|
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 SymbianStructuresLib.Arm; |
|
23 using SymbianStructuresLib.Arm.Exceptions; |
|
24 using SymbianETMLib.Common.Types; |
|
25 using SymbianETMLib.Common.Config; |
|
26 using SymbianETMLib.Common.State; |
|
27 |
|
28 namespace SymbianETMLib.Common.BranchDecoder |
|
29 { |
|
30 internal class ETMBranchDecoderAlternative : ETMBranchDecoderOriginal |
|
31 { |
|
32 #region Constructors |
|
33 public ETMBranchDecoderAlternative( ETMStateData aManager ) |
|
34 : base( aManager ) |
|
35 { |
|
36 } |
|
37 #endregion |
|
38 |
|
39 #region From ETBBranchDecoder |
|
40 protected override void DecodePartial() |
|
41 { |
|
42 int count = base.Count; |
|
43 System.Diagnostics.Debug.Assert( count > 0 && count < 5 ); |
|
44 |
|
45 // According to Table 7-13, "Missing components of exception Branch address packets" |
|
46 // then after a partial branch, we're always in "no exception" state |
|
47 base.ExceptionType = TArmExceptionType.ENone; |
|
48 |
|
49 if ( count == 1 ) |
|
50 { |
|
51 // The single-byte packet is exactly the same as in the original encoding |
|
52 base.DecodePartial(); |
|
53 } |
|
54 else |
|
55 { |
|
56 // We have full 5 bytes of address info. |
|
57 SymMask maskFirst = new SymMask( 0x7E, SymMask.TShiftDirection.ERight, 1 ); |
|
58 SymMask maskMiddle = new SymMask( 0x7F ); |
|
59 SymMask maskLast = new SymMask( 0x3F ); |
|
60 |
|
61 SymByte b; |
|
62 SymAddressWithKnownBits address = new SymAddressWithKnownBits(); |
|
63 uint masked = 0; |
|
64 |
|
65 // First byte |
|
66 b = base[ 0 ]; |
|
67 address.KnownBits += 6; |
|
68 address.Address |= maskFirst.Apply( b ); |
|
69 |
|
70 // Middle bytes, but not the last |
|
71 for ( int i = 1; i < count-1; i++ ) |
|
72 { |
|
73 b = base[ i ]; |
|
74 b = (byte) maskMiddle.Apply( b ); |
|
75 masked = (uint) ( b << address.KnownBits ); |
|
76 address.KnownBits += 7; |
|
77 address.Address |= masked; |
|
78 } |
|
79 |
|
80 // Last byte |
|
81 b = base.LastByte; |
|
82 address.KnownBits += 6; |
|
83 address.Address |= maskLast.Apply( b ); |
|
84 |
|
85 // Shift entire address by shift count based upon current instruction set. |
|
86 int isShift = ETMBranchDecoder.CompressionLeftShiftCount( base.InstructionSet ); |
|
87 address.KnownBits += isShift; |
|
88 address.Address <<= isShift; |
|
89 |
|
90 // Save address |
|
91 base.BranchAddress = address; |
|
92 } |
|
93 } |
|
94 |
|
95 public override bool IsPacketComplete |
|
96 { |
|
97 get |
|
98 { |
|
99 bool ret = false; |
|
100 // |
|
101 SymByte lastByte = base.LastByte; |
|
102 bool bit7 = lastByte[ 7 ]; |
|
103 // |
|
104 if ( bit7 ) |
|
105 { |
|
106 // If the 7th bit is set, then the interpretation is the same as in the original |
|
107 // compression scheme, in which case we can use the base class call. |
|
108 ret = base.IsPacketComplete; |
|
109 } |
|
110 else |
|
111 { |
|
112 if ( base.Count == 1 ) |
|
113 { |
|
114 // If the 7th bit is clear and this is the first byte, then this is also |
|
115 // the only byte - no exception continuation byte follows. |
|
116 ret = true; |
|
117 } |
|
118 else |
|
119 { |
|
120 // If the 7th bit is clear and the 6th bit is also clear, then this is |
|
121 // the last byte. |
|
122 bool bit6 = lastByte[ 6 ]; |
|
123 ret = ( bit6 == false ); |
|
124 } |
|
125 } |
|
126 // |
|
127 return ret; |
|
128 } |
|
129 } |
|
130 |
|
131 public override bool IsBranchAddressAvailable |
|
132 { |
|
133 get |
|
134 { |
|
135 bool ret = base.IsBranchAddressAvailable; |
|
136 return ret; |
|
137 } |
|
138 } |
|
139 #endregion |
|
140 |
|
141 #region From ETBBranchDecoderOriginal |
|
142 /* |
|
143 protected override bool ContainsInlineException |
|
144 { |
|
145 get |
|
146 { |
|
147 // Not supported in alternative encoding |
|
148 return false; |
|
149 } |
|
150 }*/ |
|
151 #endregion |
|
152 |
|
153 #region Properties |
|
154 #endregion |
|
155 |
|
156 #region Internal constants |
|
157 #endregion |
|
158 |
|
159 #region Internal methods |
|
160 #endregion |
|
161 |
|
162 #region Data members |
|
163 #endregion |
|
164 } |
|
165 } |