|
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 ETMDecodeStateOutOfOrderData : ETMDecodeState |
|
29 { |
|
30 #region Constructors |
|
31 public ETMDecodeStateOutOfOrderData( ETMStateData aManager ) |
|
32 : base( aManager ) |
|
33 { |
|
34 } |
|
35 #endregion |
|
36 |
|
37 #region API |
|
38 public override ETMDecodeState HandleByte( SymByte aByte ) |
|
39 { |
|
40 ETMDecodeState nextState = this; |
|
41 |
|
42 if ( iSeenHeader == false ) |
|
43 { |
|
44 ETMPcktOutOfOrderData cycle = new ETMPcktOutOfOrderData( aByte ); |
|
45 cycle.Matches( aByte ); |
|
46 iDataByteCount = cycle.Size; |
|
47 iSeenHeader = true; |
|
48 } |
|
49 else |
|
50 { |
|
51 iBytes.Add( aByte ); |
|
52 // |
|
53 if ( iBytes.Count == iDataByteCount ) |
|
54 { |
|
55 // Done |
|
56 nextState = new ETMDecodeStateSynchronized( base.StateData ); |
|
57 } |
|
58 } |
|
59 |
|
60 // Done. |
|
61 return nextState; |
|
62 } |
|
63 #endregion |
|
64 |
|
65 #region Properties |
|
66 protected bool IsFullBranch |
|
67 { |
|
68 get { return iBytes.Count == 5; } |
|
69 } |
|
70 #endregion |
|
71 |
|
72 #region Internal methods |
|
73 private void Flush() |
|
74 { |
|
75 // If we have a full 5 bytes, then mask off the top bits |
|
76 // from the last byte because these are reserved. |
|
77 int count = iBytes.Count; |
|
78 if ( count == 5 ) |
|
79 { |
|
80 iBytes[ 4 ].Value = (byte) ( iBytes[ 4 ].Value & 0xF ); |
|
81 } |
|
82 |
|
83 // Build final 32 bit value |
|
84 uint counter = 0; |
|
85 for ( int shift = 0; shift < count; shift++ ) |
|
86 { |
|
87 int shiftBits = shift * 8; |
|
88 uint v = (uint) ( iBytes[ shift ] << shiftBits ); |
|
89 counter |= v; |
|
90 } |
|
91 } |
|
92 |
|
93 private void Trace( uint aCounter ) |
|
94 { |
|
95 base.DbgTrace( "OoO_DATA", string.Empty ); |
|
96 } |
|
97 #endregion |
|
98 |
|
99 #region Internal constants |
|
100 protected const string KFifthByteMask_NormalStateBranchAddressArm = "00001xxx"; |
|
101 protected const string KFifthByteMask_NormalStateBranchAddressThumb = "0001xxxx"; |
|
102 protected const string KFifthByteMask_NormalStateBranchAddressJazelle = "001xxxxx"; |
|
103 protected const string KFifthByteMask_Reserved1 = "00000xxx"; |
|
104 protected const string KFifthByteMask_StateBranchWithFollowingExceptionArm = "01001xxx"; |
|
105 protected const string KFifthByteMask_StateBranchWithFollowingExceptionThumb = "0101xxxx"; |
|
106 protected const string KFifthByteMask_StateBranchWithFollowingExceptionJazelle = "011xxxxx"; |
|
107 protected const string KFifthByteMask_Reserved2 = "01000xxx"; |
|
108 protected const string KFifthByteMask_ExceptionInArmState = "1xxxxxxx"; |
|
109 #endregion |
|
110 |
|
111 #region Data members |
|
112 private int iDataByteCount = 0; |
|
113 private bool iSeenHeader = false; |
|
114 private List<SymByte> iBytes = new List<SymByte>(); |
|
115 #endregion |
|
116 } |
|
117 } |