|
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 System.Xml; |
|
22 using SymbianUtils.BasicTypes; |
|
23 using SymbianStructuresLib.Arm.Exceptions; |
|
24 using SymbianStructuresLib.Arm.Registers; |
|
25 using SymbianStructuresLib.Arm.Registers.EmbeddedTrace; |
|
26 using SymbianStructuresLib.Arm.Registers.CoProcessor; |
|
27 using SymbianETMLib.Common.Buffer; |
|
28 using SymbianETMLib.Common.State; |
|
29 using SymbianETMLib.Common.Types; |
|
30 using SymbianETMLib.Common.Utilities; |
|
31 using SymbianETMLib.Common.Exception; |
|
32 |
|
33 namespace SymbianETMLib.Common.Config |
|
34 { |
|
35 public abstract class ETConfigBase |
|
36 { |
|
37 #region Constructors |
|
38 protected ETConfigBase( ETBufferBase aBuffer ) |
|
39 { |
|
40 iBuffer = aBuffer; |
|
41 // |
|
42 RegisterETMControl = 0xC000; // 4 byte context id |
|
43 RegisterSysConControl = 1 << 13; // Assume HIVECS; |
|
44 // |
|
45 SetExceptionVector( TArmExceptionVector.EReset, 0 ); |
|
46 SetExceptionVector( TArmExceptionVector.EUndefinedInstruction, 0 ); |
|
47 SetExceptionVector( TArmExceptionVector.ESVC, 0 ); |
|
48 SetExceptionVector( TArmExceptionVector.EPrefetchAbort, 0 ); |
|
49 SetExceptionVector( TArmExceptionVector.EDataAbort, 0 ); |
|
50 SetExceptionVector( TArmExceptionVector.EIRQ, 0 ); |
|
51 SetExceptionVector( TArmExceptionVector.EFIQ, 0 ); |
|
52 } |
|
53 #endregion |
|
54 |
|
55 #region API |
|
56 public void AddContextIdMapping( uint aId, string aName ) |
|
57 { |
|
58 // Clean the context id so that it matches the kind of data |
|
59 // we see on the phone. |
|
60 uint id = aId & 0x0FFFFFFF; |
|
61 |
|
62 if ( !iContextIDs.ContainsKey( id ) ) |
|
63 { |
|
64 iContextIDs.Add( id, aName ); |
|
65 } |
|
66 } |
|
67 |
|
68 public void SetExceptionVector( TArmExceptionVector aVector, uint aInstruction ) |
|
69 { |
|
70 if ( !iExceptionVectors.ContainsKey( aVector ) ) |
|
71 { |
|
72 iExceptionVectors.Add( aVector, aInstruction ); |
|
73 } |
|
74 else |
|
75 { |
|
76 iExceptionVectors[ aVector ] = aInstruction; |
|
77 } |
|
78 } |
|
79 |
|
80 public string GetContextID( uint aID ) |
|
81 { |
|
82 string ret = "Unknown Thread"; |
|
83 // |
|
84 uint lastKey = 0; |
|
85 // |
|
86 foreach ( KeyValuePair<uint, string> kvp in iContextIDs ) |
|
87 { |
|
88 if ( kvp.Key > aID ) |
|
89 { |
|
90 if ( lastKey != 0 ) |
|
91 { |
|
92 ret = kvp.Value;//iContextIDs[ lastKey ]; |
|
93 } |
|
94 break; |
|
95 } |
|
96 else |
|
97 { |
|
98 lastKey = kvp.Key; |
|
99 } |
|
100 } |
|
101 // |
|
102 return ret; |
|
103 } |
|
104 #endregion |
|
105 |
|
106 #region API - internal |
|
107 internal uint GetExceptionVector( TArmExceptionVector aVector ) |
|
108 { |
|
109 uint ret = iExceptionVectors[ aVector ]; |
|
110 return ret; |
|
111 } |
|
112 |
|
113 internal bool IsExceptionVector( uint aAddress ) |
|
114 { |
|
115 bool ret = false; |
|
116 |
|
117 // Get current vector setting and also the vector address range |
|
118 TArmExceptionVectorLocation type = ExceptionVectorLocation; |
|
119 uint min = (uint) type; |
|
120 uint max = min + (uint) TArmExceptionVector.EFIQ; |
|
121 // |
|
122 ret = ( aAddress >= min && aAddress <= max ); |
|
123 // |
|
124 return ret; |
|
125 } |
|
126 |
|
127 internal TArmExceptionVector MapToExceptionVector( uint aAddress ) |
|
128 { |
|
129 System.Diagnostics.Debug.Assert( IsExceptionVector( aAddress ) ); |
|
130 // |
|
131 TArmExceptionVector ret = TArmExceptionVector.EUndefinedInstruction; |
|
132 // |
|
133 uint baseAddress = (uint) ExceptionVectorLocation; |
|
134 uint delta = aAddress - baseAddress; |
|
135 switch ( delta ) |
|
136 { |
|
137 case (uint) TArmExceptionVector.EReset: |
|
138 case (uint) TArmExceptionVector.EUndefinedInstruction: |
|
139 case (uint) TArmExceptionVector.ESVC: |
|
140 case (uint) TArmExceptionVector.EPrefetchAbort: |
|
141 case (uint) TArmExceptionVector.EDataAbort: |
|
142 case (uint) TArmExceptionVector.EIRQ: |
|
143 case (uint) TArmExceptionVector.EFIQ: |
|
144 ret = (TArmExceptionVector) delta; |
|
145 break; |
|
146 default: |
|
147 throw new ETMException( "ERROR - specified address is an unsupported vector location" ); |
|
148 } |
|
149 // |
|
150 return ret; |
|
151 } |
|
152 #endregion |
|
153 |
|
154 #region Properties |
|
155 public bool Verbose |
|
156 { |
|
157 get { return iVerbose; } |
|
158 set { iVerbose = value; } |
|
159 } |
|
160 |
|
161 public bool BBCModeEnabled |
|
162 { |
|
163 get |
|
164 { |
|
165 // 10 0 0 000 00 01 |
|
166 SymMask mask = new SymMask( "1 # ### ## ##" ); |
|
167 uint val = mask.Apply( RegisterETMControl ); |
|
168 return ( val != 0 ); |
|
169 } |
|
170 } |
|
171 |
|
172 public int ContextIDSize |
|
173 { |
|
174 get |
|
175 { |
|
176 // Bits [15:14] define the context id size. |
|
177 uint ret = RegisterETMControl & 0xC000; // b11000000 00000000 |
|
178 ret >>= 14; |
|
179 if ( ret > 0 ) |
|
180 { |
|
181 ++ret; |
|
182 } |
|
183 return (int) ret; |
|
184 } |
|
185 } |
|
186 |
|
187 public uint RegisterETMControl |
|
188 { |
|
189 get { return iRegistersETM[ TArmRegisterType.EArmReg_ETM_Control ].Value; } |
|
190 set { iRegistersETM[ TArmRegisterType.EArmReg_ETM_Control ].Value = value; } |
|
191 } |
|
192 |
|
193 public uint RegisterETMId |
|
194 { |
|
195 get { return iRegistersETM[ TArmRegisterType.EArmReg_ETM_Id ].Value; } |
|
196 set { iRegistersETM[ TArmRegisterType.EArmReg_ETM_Id ].Value = value; } |
|
197 } |
|
198 |
|
199 public uint RegisterSysConControl |
|
200 { |
|
201 get { return iRegistersCoProSystemControl[ TArmRegisterType.EArmReg_SysCon_Control ].Value; } |
|
202 set { iRegistersCoProSystemControl[ TArmRegisterType.EArmReg_SysCon_Control ].Value = value; } |
|
203 } |
|
204 |
|
205 public TArmExceptionVectorLocation ExceptionVectorLocation |
|
206 { |
|
207 get |
|
208 { |
|
209 TArmExceptionVectorLocation ret = TArmExceptionVectorLocation.ENormal; |
|
210 uint mask = (uint) ( 1 << 13 ); |
|
211 if ( ( RegisterSysConControl & mask ) == mask ) |
|
212 { |
|
213 ret = TArmExceptionVectorLocation.EHigh; |
|
214 } |
|
215 return ret; |
|
216 } |
|
217 } |
|
218 |
|
219 internal TETMBranchCompressionScheme BranchCompressionScheme |
|
220 { |
|
221 get |
|
222 { |
|
223 TETMBranchCompressionScheme ret = TETMBranchCompressionScheme.EOriginal; |
|
224 // 101011 100 1 0000 00001111 00001111 |
|
225 SymMask mask = new SymMask( "1 #### ######## ########" ); |
|
226 if ( mask.IsMatch( RegisterETMId ) ) |
|
227 { |
|
228 ret = TETMBranchCompressionScheme.EAlternative; |
|
229 } |
|
230 return ret; |
|
231 } |
|
232 } |
|
233 #endregion |
|
234 |
|
235 #region Internal methods |
|
236 protected ETBufferBase Buffer |
|
237 { |
|
238 get { return iBuffer; } |
|
239 } |
|
240 #endregion |
|
241 |
|
242 #region From System.Object |
|
243 #endregion |
|
244 |
|
245 #region Data members |
|
246 private readonly ETBufferBase iBuffer; |
|
247 private bool iVerbose = false; |
|
248 private ArmETMRegisterCollection iRegistersETM = new ArmETMRegisterCollection(); |
|
249 private ArmCoProSystemControlRegisterCollection iRegistersCoProSystemControl = new ArmCoProSystemControlRegisterCollection(); |
|
250 private Dictionary<TArmExceptionVector, uint> iExceptionVectors = new Dictionary<TArmExceptionVector, uint>(); |
|
251 private SortedDictionary<uint, string> iContextIDs = new SortedDictionary<uint, string>(); |
|
252 #endregion |
|
253 } |
|
254 } |