|
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 SymbianStructuresLib.Arm.Exceptions; |
|
23 using SymbianStructuresLib.Arm.Registers; |
|
24 using SymbianStructuresLib.Arm.Registers.EmbeddedTrace; |
|
25 using SymbianETMLib.Common.Types; |
|
26 using SymbianETMLib.Common.Utilities; |
|
27 using SymbianETMLib.Common.Exception; |
|
28 using SymbianETMLib.Common.Config; |
|
29 using SymbianETMLib.ETB.Buffer; |
|
30 |
|
31 namespace SymbianETMLib.ETB.Config |
|
32 { |
|
33 public class ETBConfig : ETConfigBase |
|
34 { |
|
35 #region Constructors |
|
36 public ETBConfig( ETBBuffer aBuffer ) |
|
37 : base( aBuffer ) |
|
38 { |
|
39 } |
|
40 |
|
41 public ETBConfig( ETBBuffer aBuffer, string aETBXmlFile ) |
|
42 : this( aBuffer ) |
|
43 { |
|
44 bool loaded = ExtractFromXml( aETBXmlFile ); |
|
45 if ( !loaded ) |
|
46 { |
|
47 throw new ETMException( "ERROR: XML input data is corrupt or invalid" ); |
|
48 } |
|
49 } |
|
50 #endregion |
|
51 |
|
52 #region API |
|
53 #endregion |
|
54 |
|
55 #region Properties |
|
56 public uint RegisterETBRamWritePointer |
|
57 { |
|
58 get { return iRegistersETB[ TArmRegisterType.EArmReg_ETB_RamWritePointer ].Value; } |
|
59 set { iRegistersETB[ TArmRegisterType.EArmReg_ETB_RamWritePointer ].Value = value; } |
|
60 } |
|
61 #endregion |
|
62 |
|
63 #region Internal methods |
|
64 protected new ETBBuffer Buffer |
|
65 { |
|
66 get { return base.Buffer as ETBBuffer; } |
|
67 } |
|
68 |
|
69 private bool ExtractFromXml( string aFileName ) |
|
70 { |
|
71 bool success = false; |
|
72 // |
|
73 try |
|
74 { |
|
75 XmlReaderSettings settings = new XmlReaderSettings(); |
|
76 settings.ConformanceLevel = ConformanceLevel.Auto; |
|
77 settings.IgnoreComments = true; |
|
78 settings.CheckCharacters = true; |
|
79 settings.IgnoreWhitespace = true; |
|
80 // |
|
81 using ( XmlReader reader = XmlReader.Create( aFileName, settings ) ) |
|
82 { |
|
83 XmlDocument document = new XmlDocument(); |
|
84 document.Load( reader ); |
|
85 XmlElement root = document.DocumentElement; |
|
86 if ( root == null || root.Name != "etb" ) |
|
87 { |
|
88 throw new ETMException( "ERROR - document root expected to be \'etb\'" ); |
|
89 } |
|
90 else |
|
91 { |
|
92 foreach ( XmlNode node in root ) |
|
93 { |
|
94 string nodeName = node.Name.Trim().ToUpper(); |
|
95 if ( nodeName == "REGISTERS" ) |
|
96 { |
|
97 ExtractXmlRegisters( node ); |
|
98 } |
|
99 else if ( nodeName == "EXCEPTION_VECTORS" ) |
|
100 { |
|
101 ExtractXmlExceptionVectors( node ); |
|
102 } |
|
103 else if ( nodeName == "RAW_DATA" ) |
|
104 { |
|
105 ExtractXmlRawData( node ); |
|
106 } |
|
107 else if ( nodeName == "THREAD_TABLE" ) |
|
108 { |
|
109 ExtractXmlThreadTable( node ); |
|
110 } |
|
111 } |
|
112 } |
|
113 } |
|
114 |
|
115 // Primed okay? |
|
116 success = true; |
|
117 |
|
118 // Re-order data based upon write pointer value |
|
119 if ( RegisterETBRamWritePointer != 0 ) |
|
120 { |
|
121 Buffer.Reorder( RegisterETBRamWritePointer ); |
|
122 } |
|
123 } |
|
124 catch ( System.Exception ) |
|
125 { |
|
126 } |
|
127 // |
|
128 return success; |
|
129 } |
|
130 |
|
131 private void ExtractXmlRegisters( XmlNode aNode ) |
|
132 { |
|
133 foreach ( XmlNode node in aNode.ChildNodes ) |
|
134 { |
|
135 string nodeName = node.Name.Trim().ToUpper(); |
|
136 if ( nodeName == "REGISTER" && node.Attributes.Count == 2 ) |
|
137 { |
|
138 XmlAttributeCollection attributes = node.Attributes; |
|
139 // |
|
140 XmlAttribute attribName = attributes[ "name" ]; |
|
141 XmlAttribute attribValue = attributes[ "value" ]; |
|
142 // |
|
143 if ( attribName != null && !string.IsNullOrEmpty( attribName.Value.Trim() ) && |
|
144 attribValue != null && !string.IsNullOrEmpty( attribValue.Value.Trim() ) |
|
145 ) |
|
146 { |
|
147 string name = attribName.Value.Trim().ToUpper(); |
|
148 uint value = uint.Parse( attribValue.Value, System.Globalization.NumberStyles.HexNumber ); |
|
149 // |
|
150 TArmRegisterType regType = ETMTextToEnumConverter.ToRegisterType( name ); |
|
151 switch ( regType ) |
|
152 { |
|
153 default: |
|
154 break; |
|
155 case TArmRegisterType.EArmReg_ETM_Id: |
|
156 base.RegisterETMId = value; |
|
157 break; |
|
158 case TArmRegisterType.EArmReg_ETM_Control: |
|
159 base.RegisterETMControl = value; |
|
160 break; |
|
161 case TArmRegisterType.EArmReg_ETB_RamWritePointer: |
|
162 RegisterETBRamWritePointer = value; |
|
163 break; |
|
164 } |
|
165 } |
|
166 } |
|
167 } |
|
168 } |
|
169 |
|
170 private void ExtractXmlExceptionVectors( XmlNode aNode ) |
|
171 { |
|
172 foreach ( XmlNode node in aNode.ChildNodes ) |
|
173 { |
|
174 string nodeName = node.Name.Trim().ToUpper(); |
|
175 if ( nodeName == "REGISTER" && node.Attributes.Count == 2 ) |
|
176 { |
|
177 XmlAttributeCollection attributes = node.Attributes; |
|
178 // |
|
179 XmlAttribute attribName = attributes[ "name" ]; |
|
180 XmlAttribute attribValue = attributes[ "value" ]; |
|
181 // |
|
182 if ( attribName != null && !string.IsNullOrEmpty( attribName.Value.Trim() ) && |
|
183 attribValue != null && !string.IsNullOrEmpty( attribValue.Value.Trim() ) |
|
184 ) |
|
185 { |
|
186 string name = attribName.Value.Trim().ToUpper(); |
|
187 uint value = uint.Parse( attribValue.Value, System.Globalization.NumberStyles.HexNumber ); |
|
188 // |
|
189 TArmExceptionVector exceptionVectorType = ETMTextToEnumConverter.ToExceptionVector( name ); |
|
190 SetExceptionVector( exceptionVectorType, value ); |
|
191 } |
|
192 } |
|
193 } |
|
194 } |
|
195 |
|
196 private void ExtractXmlThreadTable( XmlNode aNode ) |
|
197 { |
|
198 foreach ( XmlNode node in aNode.ChildNodes ) |
|
199 { |
|
200 string nodeName = node.Name.Trim().ToUpper(); |
|
201 if ( nodeName == "THREAD" && node.Attributes.Count == 3 ) |
|
202 { |
|
203 XmlAttributeCollection attributes = node.Attributes; |
|
204 // |
|
205 XmlAttribute attribName = attributes[ "name" ]; |
|
206 XmlAttribute attribAddress = attributes[ "address" ]; |
|
207 XmlAttribute attribId = attributes[ "id" ]; |
|
208 // |
|
209 if ( attribName != null && !string.IsNullOrEmpty( attribName.Value.Trim() ) && |
|
210 attribAddress != null && !string.IsNullOrEmpty( attribAddress.Value.Trim() ) |
|
211 ) |
|
212 { |
|
213 string name = attribName.Value.Trim(); |
|
214 uint value = uint.Parse( attribAddress.Value, System.Globalization.NumberStyles.HexNumber ); |
|
215 |
|
216 // Add the missing colon back in. |
|
217 if ( name.Contains( ":" ) ) |
|
218 { |
|
219 name = name.Replace( ":", "::" ); |
|
220 } |
|
221 AddContextIdMapping( value, name ); |
|
222 } |
|
223 } |
|
224 } |
|
225 } |
|
226 |
|
227 private void ExtractXmlRawData( XmlNode aNode ) |
|
228 { |
|
229 List<string> lines = new List<string>(); |
|
230 // |
|
231 foreach ( XmlNode node in aNode.ChildNodes ) |
|
232 { |
|
233 string nodeName = node.Name.Trim().ToUpper(); |
|
234 if ( nodeName == "DATA" ) |
|
235 { |
|
236 string line = node.InnerText; |
|
237 lines.Add( line ); |
|
238 } |
|
239 else |
|
240 { |
|
241 break; |
|
242 } |
|
243 } |
|
244 |
|
245 // Convert strings to bytes |
|
246 List<byte> data = new List<byte>(); |
|
247 foreach ( string line in lines ) |
|
248 { |
|
249 int len = line.Length; |
|
250 if ( len % 2 != 0 ) |
|
251 { |
|
252 throw new ETMException( "ERROR: Raw data is corrupt - invalid line length" ); |
|
253 } |
|
254 |
|
255 for ( int i = 0; i < len; i += 2 ) |
|
256 { |
|
257 string byteString = line.Substring( i, 2 ); |
|
258 byte b = System.Convert.ToByte( byteString, 16 ); |
|
259 data.Add( b ); |
|
260 } |
|
261 } |
|
262 |
|
263 // Save entire data |
|
264 base.Buffer.AddRange( data.ToArray() ); |
|
265 } |
|
266 #endregion |
|
267 |
|
268 #region From System.Object |
|
269 #endregion |
|
270 |
|
271 #region Data members |
|
272 private ArmETBRegisterCollection iRegistersETB = new ArmETBRegisterCollection(); |
|
273 #endregion |
|
274 } |
|
275 } |