|
1 /* |
|
2 * Copyright (c) 2004-2008 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 CrashDebuggerLib.Structures.KernelObjects; |
|
22 using CrashDebuggerLib.Structures.Register; |
|
23 using CrashDebuggerLib.Structures.Common; |
|
24 using SymbianStructuresLib.Arm.Registers; |
|
25 |
|
26 namespace CrashDebuggerLib.Structures.Register |
|
27 { |
|
28 public class RegisterSet : CrashDebuggerAware |
|
29 { |
|
30 #region Constructors |
|
31 internal RegisterSet( CrashDebuggerInfo aCrashDebugger ) |
|
32 : base( aCrashDebugger ) |
|
33 { |
|
34 Clear(); |
|
35 } |
|
36 #endregion |
|
37 |
|
38 #region API |
|
39 public void Clear() |
|
40 { |
|
41 iBanks.Clear(); |
|
42 |
|
43 // General regs don't share a bank - they're just a dumping |
|
44 // ground for CPU specific entries. |
|
45 AddBank( RegisterCollection.TType.ETypeGeneral ); |
|
46 |
|
47 // The rest use banking. CPSR goes in the common bank. |
|
48 RegisterCollection common = new RegisterCollection( CrashDebugger, RegisterCollection.TType.ETypeCommonBank ); |
|
49 iBanks.Add( RegisterCollection.TType.ETypeCommonBank, common ); |
|
50 common.AddMany( TArmRegisterType.EArmReg_CPSR, |
|
51 TArmRegisterType.EArmReg_00, |
|
52 TArmRegisterType.EArmReg_01, |
|
53 TArmRegisterType.EArmReg_02, |
|
54 TArmRegisterType.EArmReg_03, |
|
55 TArmRegisterType.EArmReg_04, |
|
56 TArmRegisterType.EArmReg_05, |
|
57 TArmRegisterType.EArmReg_06, |
|
58 TArmRegisterType.EArmReg_07 ); |
|
59 |
|
60 // These are all fairly normal. They have their own SP, LR and SPSR |
|
61 // The others are common. |
|
62 AddBank( RegisterCollection.TType.ETypeUser, common ); |
|
63 AddBank( RegisterCollection.TType.ETypeAbort, common ); |
|
64 AddBank( RegisterCollection.TType.ETypeInterrupt, common ); |
|
65 AddBank( RegisterCollection.TType.ETypeSupervisor, common ); |
|
66 AddBank( RegisterCollection.TType.ETypeSystem, common ); |
|
67 AddBank( RegisterCollection.TType.ETypeUndefined, common ); |
|
68 |
|
69 // FIQ is special - it has shadows of R8->12 |
|
70 AddBank( RegisterCollection.TType.ETypeFastInterrupt, common, |
|
71 TArmRegisterType.EArmReg_08, |
|
72 TArmRegisterType.EArmReg_09, |
|
73 TArmRegisterType.EArmReg_10, |
|
74 TArmRegisterType.EArmReg_11, |
|
75 TArmRegisterType.EArmReg_12 |
|
76 ); |
|
77 } |
|
78 |
|
79 public bool Available( RegisterCollection.TType aType ) |
|
80 { |
|
81 bool ret = iBanks.ContainsKey( aType ); |
|
82 return ret; |
|
83 } |
|
84 #endregion |
|
85 |
|
86 #region Properties |
|
87 public RegisterEntryCPSR CPSR |
|
88 { |
|
89 get |
|
90 { |
|
91 RegisterEntryCPSR cpsr = (RegisterEntryCPSR) this[ RegisterCollection.TType.ETypeCommonBank, TArmRegisterType.EArmReg_CPSR ]; |
|
92 return cpsr; |
|
93 } |
|
94 } |
|
95 |
|
96 public RegisterCollection.TType CPSRBankType |
|
97 { |
|
98 get { return CPSR.CurrentBank; } |
|
99 } |
|
100 |
|
101 public RegisterEntry CurrentSP |
|
102 { |
|
103 get |
|
104 { |
|
105 RegisterCollection.TType bank = CPSRBankType; |
|
106 RegisterEntry ret = this[ bank, TArmRegisterType.EArmReg_SP ]; |
|
107 return ret; |
|
108 } |
|
109 } |
|
110 |
|
111 public RegisterEntry CurrentLR |
|
112 { |
|
113 get |
|
114 { |
|
115 RegisterCollection.TType bank = CPSRBankType; |
|
116 RegisterEntry ret = this[ bank, TArmRegisterType.EArmReg_LR ]; |
|
117 return ret; |
|
118 } |
|
119 } |
|
120 |
|
121 public RegisterCollection this[ RegisterCollection.TType aBank ] |
|
122 { |
|
123 get |
|
124 { |
|
125 RegisterCollection ret = iBanks[ aBank ]; |
|
126 return ret; |
|
127 } |
|
128 } |
|
129 |
|
130 public RegisterEntry this[ RegisterCollection.TType aBank, string aName ] |
|
131 { |
|
132 get |
|
133 { |
|
134 RegisterCollection bank = this[ aBank ]; |
|
135 return bank[ aName ]; |
|
136 } |
|
137 } |
|
138 |
|
139 public RegisterEntry this[ RegisterCollection.TType aBank, TArmRegisterType aType ] |
|
140 { |
|
141 get |
|
142 { |
|
143 RegisterCollection bank = this[ aBank ]; |
|
144 return bank[ aType ]; |
|
145 } |
|
146 } |
|
147 #endregion |
|
148 |
|
149 #region Internal methods |
|
150 private RegisterCollection AddBank( RegisterCollection.TType aType ) |
|
151 { |
|
152 return AddBank( aType, null ); |
|
153 } |
|
154 |
|
155 private RegisterCollection AddBank( RegisterCollection.TType aType, RegisterCollection aLinkedWith ) |
|
156 { |
|
157 TArmRegisterType[] empty = new TArmRegisterType[] { }; |
|
158 return AddBank( aType, aLinkedWith, empty ); |
|
159 } |
|
160 |
|
161 private RegisterCollection AddBank( RegisterCollection.TType aType, RegisterCollection aLinkedWith, params TArmRegisterType[] aExtraRegs ) |
|
162 { |
|
163 RegisterCollection bank = new RegisterCollection( CrashDebugger, aType, null, aLinkedWith ); |
|
164 iBanks.Add( aType, bank ); |
|
165 |
|
166 // Create bank specific registers |
|
167 string bankName = RegisterCollection.BankName( aType ); |
|
168 if ( bankName != string.Empty ) |
|
169 { |
|
170 bankName = "_" + bankName; |
|
171 } |
|
172 |
|
173 bank.Add( "R13" + bankName, 0 ); |
|
174 bank.Add( "R14" + bankName, 0 ); |
|
175 bank.Add( "SPSR" + bankName, 0 ); |
|
176 |
|
177 // Create custom registers |
|
178 foreach( TArmRegisterType custom in aExtraRegs ) |
|
179 { |
|
180 string name = ArmRegister.GetTypeName( custom ) + bankName; |
|
181 bank.Add( name, 0 ); |
|
182 } |
|
183 |
|
184 return bank; |
|
185 } |
|
186 #endregion |
|
187 |
|
188 #region Internal constants |
|
189 #endregion |
|
190 |
|
191 #region From System.Object |
|
192 public override string ToString() |
|
193 { |
|
194 return base.ToString(); |
|
195 } |
|
196 #endregion |
|
197 |
|
198 #region Data members |
|
199 private Dictionary<RegisterCollection.TType, RegisterCollection> iBanks = new Dictionary<RegisterCollection.TType, RegisterCollection>(); |
|
200 #endregion |
|
201 } |
|
202 } |