|
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 using System; |
|
18 using System.Text; |
|
19 using System.Text.RegularExpressions; |
|
20 using System.Collections.Generic; |
|
21 using CrashItemLib.Crash; |
|
22 using CrashItemLib.Crash.Base; |
|
23 using CrashItemLib.Crash.Container; |
|
24 using CrashItemLib.Crash.Stacks; |
|
25 using CrashItemLib.Crash.ExitInfo; |
|
26 using CrashItemLib.Crash.Processes; |
|
27 using CrashItemLib.Crash.Registers; |
|
28 using SymbianStructuresLib.Uids; |
|
29 using SymbianStructuresLib.Arm.Registers; |
|
30 |
|
31 namespace CrashItemLib.Crash.Registers |
|
32 { |
|
33 public class CIRegisterListCollection : CIElement, IEnumerable<CIRegisterList> |
|
34 { |
|
35 #region Constructors |
|
36 [CIElementAttributeMandatory()] |
|
37 public CIRegisterListCollection( CIContainer aContainer ) |
|
38 : this( aContainer, null ) |
|
39 { |
|
40 } |
|
41 |
|
42 internal CIRegisterListCollection( CIContainer aContainer, CIElement aParent ) |
|
43 : base( aContainer, aParent ) |
|
44 { |
|
45 } |
|
46 #endregion |
|
47 |
|
48 #region API |
|
49 public void Add( TArmRegisterBank aType ) |
|
50 { |
|
51 this[ aType ] = new CIRegisterList( Container, aType ); |
|
52 } |
|
53 |
|
54 public void Add( CIRegisterList aCollection ) |
|
55 { |
|
56 // Make sure the dictionary doesn't already contain this bank type! |
|
57 bool exists = Contains( aCollection.Bank ); |
|
58 if ( exists ) |
|
59 { |
|
60 throw new Exception( aCollection.BankName + " already exists within collection" ); |
|
61 } |
|
62 else |
|
63 { |
|
64 iRegisters.Add( aCollection.Bank, aCollection ); |
|
65 |
|
66 // Register as child also |
|
67 base.AddChild( aCollection ); |
|
68 } |
|
69 } |
|
70 |
|
71 public void Add( params TArmRegisterBank[] aTypes ) |
|
72 { |
|
73 foreach ( TArmRegisterBank type in aTypes ) |
|
74 { |
|
75 Add( type ); |
|
76 } |
|
77 } |
|
78 |
|
79 public bool Contains( TArmRegisterBank aType ) |
|
80 { |
|
81 return iRegisters.ContainsKey( aType ); |
|
82 } |
|
83 |
|
84 public override void Clear() |
|
85 { |
|
86 iRegisters.Clear(); |
|
87 base.Clear(); |
|
88 } |
|
89 #endregion |
|
90 |
|
91 #region Properties |
|
92 public virtual uint CPSR |
|
93 { |
|
94 get |
|
95 { |
|
96 uint ret = 0; |
|
97 // |
|
98 CIRegisterList list = CurrentProcessorModeRegisters; |
|
99 if ( list != null ) |
|
100 { |
|
101 ret = list[ TArmRegisterType.EArmReg_CPSR ].Value; |
|
102 } |
|
103 else |
|
104 { |
|
105 // CPSR is not yet defined |
|
106 } |
|
107 // |
|
108 return ret; |
|
109 } |
|
110 set |
|
111 { |
|
112 TArmRegisterBank bank = ArmRegisterBankUtils.ExtractBank( value ); |
|
113 |
|
114 // Remove CPSR from current register list |
|
115 CIRegisterList list = CurrentProcessorModeRegisters; |
|
116 if ( list != null ) |
|
117 { |
|
118 list.Remove( TArmRegisterType.EArmReg_CPSR ); |
|
119 } |
|
120 |
|
121 // Now we can add it without fear of creating a duplicate |
|
122 CIRegisterList cpsrRegList = this[ bank ]; |
|
123 if ( cpsrRegList != null ) |
|
124 { |
|
125 cpsrRegList.Add( TArmRegisterType.EArmReg_CPSR, value ); |
|
126 } |
|
127 } |
|
128 } |
|
129 |
|
130 public virtual CIRegisterList CurrentProcessorModeRegisters |
|
131 { |
|
132 get |
|
133 { |
|
134 // Try to find the bank that contains CPSR (if any) and |
|
135 // return that. |
|
136 CIRegisterList ret = null; |
|
137 // |
|
138 foreach ( CIRegisterList col in this ) |
|
139 { |
|
140 if ( col.Contains( TArmRegisterType.EArmReg_CPSR ) ) |
|
141 { |
|
142 // Get CPSR value |
|
143 ArmRegister cpsr = col[ TArmRegisterType.EArmReg_CPSR ]; |
|
144 TArmRegisterBank cpsrBank = ArmRegisterBankUtils.ExtractBank( cpsr ); |
|
145 |
|
146 // Try to get the corresponding bank (should be the same as col...) |
|
147 if ( Contains( cpsrBank ) ) |
|
148 { |
|
149 CIRegisterList list = this[ cpsrBank ]; |
|
150 System.Diagnostics.Debug.Assert( list is CIRegisterList ); |
|
151 ret = (CIRegisterList) list; |
|
152 } |
|
153 break; |
|
154 } |
|
155 } |
|
156 // |
|
157 return ret; |
|
158 } |
|
159 } |
|
160 |
|
161 public CIRegisterList this[ TArmRegisterBank aType ] |
|
162 { |
|
163 get { return iRegisters[ aType ]; } |
|
164 set |
|
165 { |
|
166 if ( iRegisters.ContainsKey( aType ) ) |
|
167 { |
|
168 iRegisters[ aType ] = value; |
|
169 } |
|
170 else |
|
171 { |
|
172 Add( value ); |
|
173 } |
|
174 } |
|
175 } |
|
176 #endregion |
|
177 |
|
178 #region Internal methods |
|
179 #endregion |
|
180 |
|
181 #region From IEnumerable<CIRegisterCollection> |
|
182 public new IEnumerator<CIRegisterList> GetEnumerator() |
|
183 { |
|
184 foreach ( KeyValuePair<TArmRegisterBank, CIRegisterList> kvp in iRegisters ) |
|
185 { |
|
186 yield return kvp.Value; |
|
187 } |
|
188 } |
|
189 |
|
190 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|
191 { |
|
192 foreach ( KeyValuePair<TArmRegisterBank, CIRegisterList> kvp in iRegisters ) |
|
193 { |
|
194 yield return kvp.Value; |
|
195 } |
|
196 } |
|
197 #endregion |
|
198 |
|
199 #region Data members |
|
200 private Dictionary<TArmRegisterBank, CIRegisterList> iRegisters = new Dictionary<TArmRegisterBank, CIRegisterList>(); |
|
201 #endregion |
|
202 } |
|
203 } |