sim: Make Stats truly non-copy-constructible
[gem5.git] / src / arch / sparc / faults.hh
1 /*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Gabe Black
29 * Kevin Lim
30 */
31
32 #ifndef __SPARC_FAULTS_HH__
33 #define __SPARC_FAULTS_HH__
34
35 #include "cpu/static_inst.hh"
36 #include "sim/faults.hh"
37
38 // The design of the "name" and "vect" functions is in sim/faults.hh
39
40 namespace SparcISA
41 {
42
43 typedef uint32_t TrapType;
44 typedef uint32_t FaultPriority;
45
46 class ITB;
47
48 class SparcFaultBase : public FaultBase
49 {
50 public:
51 enum PrivilegeLevel
52 {
53 U, User = U,
54 P, Privileged = P,
55 H, Hyperprivileged = H,
56 NumLevels,
57 SH = -1,
58 ShouldntHappen = SH
59 };
60 using PrivilegeLevelSpec = std::array<PrivilegeLevel, NumLevels>;
61 struct FaultVals
62 {
63 const FaultName name;
64 const TrapType trapType;
65 const FaultPriority priority;
66 const PrivilegeLevelSpec nextPrivilegeLevel;
67 FaultStat count;
68 FaultVals(const FaultName& name_, const TrapType& trapType_,
69 const FaultPriority& priority_, const PrivilegeLevelSpec& il)
70 : name(name_), trapType(trapType_), priority(priority_),
71 nextPrivilegeLevel(il)
72 {}
73 };
74 void invoke(ThreadContext * tc, const StaticInstPtr &inst =
75 StaticInst::nullStaticInstPtr);
76 virtual TrapType trapType() = 0;
77 virtual FaultPriority priority() = 0;
78 virtual FaultStat & countStat() = 0;
79 virtual PrivilegeLevel getNextLevel(PrivilegeLevel current) = 0;
80 };
81
82 template<typename T>
83 class SparcFault : public SparcFaultBase
84 {
85 protected:
86 static FaultVals vals;
87 public:
88 FaultName name() const { return vals.name; }
89 TrapType trapType() { return vals.trapType; }
90 FaultPriority priority() { return vals.priority; }
91 FaultStat & countStat() { return vals.count; }
92
93 PrivilegeLevel
94 getNextLevel(PrivilegeLevel current)
95 {
96 return vals.nextPrivilegeLevel[current];
97 }
98 };
99
100 class PowerOnReset : public SparcFault<PowerOnReset>
101 {
102 void invoke(ThreadContext * tc, const StaticInstPtr &inst =
103 StaticInst::nullStaticInstPtr);
104 };
105
106 class WatchDogReset : public SparcFault<WatchDogReset> {};
107
108 class ExternallyInitiatedReset : public SparcFault<ExternallyInitiatedReset> {};
109
110 class SoftwareInitiatedReset : public SparcFault<SoftwareInitiatedReset> {};
111
112 class REDStateException : public SparcFault<REDStateException> {};
113
114 class StoreError : public SparcFault<StoreError> {};
115
116 class InstructionAccessException : public SparcFault<InstructionAccessException> {};
117
118 // class InstructionAccessMMUMiss : public SparcFault<InstructionAccessMMUMiss> {};
119
120 class InstructionAccessError : public SparcFault<InstructionAccessError> {};
121
122 class IllegalInstruction : public SparcFault<IllegalInstruction> {};
123
124 class PrivilegedOpcode : public SparcFault<PrivilegedOpcode> {};
125
126 // class UnimplementedLDD : public SparcFault<UnimplementedLDD> {};
127
128 // class UnimplementedSTD : public SparcFault<UnimplementedSTD> {};
129
130 class FpDisabled : public SparcFault<FpDisabled> {};
131 class VecDisabled : public SparcFault<VecDisabled> {};
132
133 class FpExceptionIEEE754 : public SparcFault<FpExceptionIEEE754> {};
134
135 class FpExceptionOther : public SparcFault<FpExceptionOther> {};
136
137 class TagOverflow : public SparcFault<TagOverflow> {};
138
139 class CleanWindow : public SparcFault<CleanWindow> {};
140
141 class DivisionByZero : public SparcFault<DivisionByZero> {};
142
143 class InternalProcessorError :
144 public SparcFault<InternalProcessorError> {};
145
146 class InstructionInvalidTSBEntry :
147 public SparcFault<InstructionInvalidTSBEntry> {};
148
149 class DataInvalidTSBEntry : public SparcFault<DataInvalidTSBEntry> {};
150
151 class DataAccessException : public SparcFault<DataAccessException> {};
152
153 // class DataAccessMMUMiss : public SparcFault<DataAccessMMUMiss> {};
154
155 class DataAccessError : public SparcFault<DataAccessError> {};
156
157 class DataAccessProtection : public SparcFault<DataAccessProtection> {};
158
159 class MemAddressNotAligned :
160 public SparcFault<MemAddressNotAligned> {};
161
162 class LDDFMemAddressNotAligned : public SparcFault<LDDFMemAddressNotAligned> {};
163
164 class STDFMemAddressNotAligned : public SparcFault<STDFMemAddressNotAligned> {};
165
166 class PrivilegedAction : public SparcFault<PrivilegedAction> {};
167
168 class LDQFMemAddressNotAligned : public SparcFault<LDQFMemAddressNotAligned> {};
169
170 class STQFMemAddressNotAligned : public SparcFault<STQFMemAddressNotAligned> {};
171
172 class InstructionRealTranslationMiss :
173 public SparcFault<InstructionRealTranslationMiss> {};
174
175 class DataRealTranslationMiss : public SparcFault<DataRealTranslationMiss> {};
176
177 // class AsyncDataError : public SparcFault<AsyncDataError> {};
178
179 template <class T>
180 class EnumeratedFault : public SparcFault<T>
181 {
182 protected:
183 uint32_t _n;
184 public:
185 EnumeratedFault(uint32_t n) : SparcFault<T>(), _n(n) {}
186 TrapType trapType() { return SparcFault<T>::trapType() + _n; }
187 };
188
189 class InterruptLevelN : public EnumeratedFault<InterruptLevelN>
190 {
191 public:
192 InterruptLevelN(uint32_t n) : EnumeratedFault<InterruptLevelN>(n) {;}
193 FaultPriority priority() { return 3200 - _n*100; }
194 };
195
196 class HstickMatch : public SparcFault<HstickMatch> {};
197
198 class TrapLevelZero : public SparcFault<TrapLevelZero> {};
199
200 class InterruptVector : public SparcFault<InterruptVector> {};
201
202 class PAWatchpoint : public SparcFault<PAWatchpoint> {};
203
204 class VAWatchpoint : public SparcFault<VAWatchpoint> {};
205
206 class FastInstructionAccessMMUMiss :
207 public SparcFault<FastInstructionAccessMMUMiss>
208 {
209 protected:
210 Addr vaddr;
211 public:
212 FastInstructionAccessMMUMiss(Addr addr) : vaddr(addr)
213 {}
214 FastInstructionAccessMMUMiss() : vaddr(0)
215 {}
216 void invoke(ThreadContext * tc, const StaticInstPtr &inst =
217 StaticInst::nullStaticInstPtr);
218 };
219
220 class FastDataAccessMMUMiss : public SparcFault<FastDataAccessMMUMiss>
221 {
222 protected:
223 Addr vaddr;
224 public:
225 FastDataAccessMMUMiss(Addr addr) : vaddr(addr)
226 {}
227 FastDataAccessMMUMiss() : vaddr(0)
228 {}
229 void invoke(ThreadContext * tc, const StaticInstPtr &inst =
230 StaticInst::nullStaticInstPtr);
231 };
232
233 class FastDataAccessProtection : public SparcFault<FastDataAccessProtection> {};
234
235 class InstructionBreakpoint : public SparcFault<InstructionBreakpoint> {};
236
237 class CpuMondo : public SparcFault<CpuMondo> {};
238
239 class DevMondo : public SparcFault<DevMondo> {};
240
241 class ResumableError : public SparcFault<ResumableError> {};
242
243 class SpillNNormal : public EnumeratedFault<SpillNNormal>
244 {
245 public:
246 SpillNNormal(uint32_t n) : EnumeratedFault<SpillNNormal>(n) {;}
247 // These need to be handled specially to enable spill traps in SE
248 void invoke(ThreadContext * tc, const StaticInstPtr &inst =
249 StaticInst::nullStaticInstPtr);
250 };
251
252 class SpillNOther : public EnumeratedFault<SpillNOther>
253 {
254 public:
255 SpillNOther(uint32_t n) : EnumeratedFault<SpillNOther>(n)
256 {}
257 };
258
259 class FillNNormal : public EnumeratedFault<FillNNormal>
260 {
261 public:
262 FillNNormal(uint32_t n) : EnumeratedFault<FillNNormal>(n)
263 {}
264 // These need to be handled specially to enable fill traps in SE
265 void invoke(ThreadContext * tc, const StaticInstPtr &inst =
266 StaticInst::nullStaticInstPtr);
267 };
268
269 class FillNOther : public EnumeratedFault<FillNOther>
270 {
271 public:
272 FillNOther(uint32_t n) : EnumeratedFault<FillNOther>(n)
273 {}
274 };
275
276 class TrapInstruction : public EnumeratedFault<TrapInstruction>
277 {
278 public:
279 TrapInstruction(uint32_t n) : EnumeratedFault<TrapInstruction>(n)
280 {}
281 // In SE, trap instructions are requesting services from the OS.
282 void invoke(ThreadContext * tc, const StaticInstPtr &inst =
283 StaticInst::nullStaticInstPtr);
284 };
285
286 /*
287 * Explicitly declare template static member variables to avoid warnings
288 * in some clang versions
289 */
290 template<> SparcFaultBase::FaultVals SparcFault<PowerOnReset>::vals;
291 template<> SparcFaultBase::FaultVals SparcFault<WatchDogReset>::vals;
292 template<> SparcFaultBase::FaultVals
293 SparcFault<ExternallyInitiatedReset>::vals;
294 template<> SparcFaultBase::FaultVals SparcFault<SoftwareInitiatedReset>::vals;
295 template<> SparcFaultBase::FaultVals SparcFault<REDStateException>::vals;
296 template<> SparcFaultBase::FaultVals SparcFault<StoreError>::vals;
297 template<> SparcFaultBase::FaultVals
298 SparcFault<InstructionAccessException>::vals;
299 template<> SparcFaultBase::FaultVals SparcFault<InstructionAccessError>::vals;
300 template<> SparcFaultBase::FaultVals SparcFault<IllegalInstruction>::vals;
301 template<> SparcFaultBase::FaultVals SparcFault<PrivilegedOpcode>::vals;
302 template<> SparcFaultBase::FaultVals SparcFault<FpDisabled>::vals;
303 template<> SparcFaultBase::FaultVals SparcFault<VecDisabled>::vals;
304 template<> SparcFaultBase::FaultVals SparcFault<FpExceptionIEEE754>::vals;
305 template<> SparcFaultBase::FaultVals SparcFault<FpExceptionOther>::vals;
306 template<> SparcFaultBase::FaultVals SparcFault<TagOverflow>::vals;
307 template<> SparcFaultBase::FaultVals SparcFault<CleanWindow>::vals;
308 template<> SparcFaultBase::FaultVals SparcFault<DivisionByZero>::vals;
309 template<> SparcFaultBase::FaultVals SparcFault<InternalProcessorError>::vals;
310 template<> SparcFaultBase::FaultVals
311 SparcFault<InstructionInvalidTSBEntry>::vals;
312 template<> SparcFaultBase::FaultVals SparcFault<DataInvalidTSBEntry>::vals;
313 template<> SparcFaultBase::FaultVals SparcFault<DataAccessException>::vals;
314 template<> SparcFaultBase::FaultVals SparcFault<DataAccessError>::vals;
315 template<> SparcFaultBase::FaultVals SparcFault<DataAccessProtection>::vals;
316 template<> SparcFaultBase::FaultVals SparcFault<MemAddressNotAligned>::vals;
317 template<> SparcFaultBase::FaultVals
318 SparcFault<LDDFMemAddressNotAligned>::vals;
319 template<> SparcFaultBase::FaultVals
320 SparcFault<STDFMemAddressNotAligned>::vals;
321 template<> SparcFaultBase::FaultVals SparcFault<PrivilegedAction>::vals;
322 template<> SparcFaultBase::FaultVals
323 SparcFault<LDQFMemAddressNotAligned>::vals;
324 template<> SparcFaultBase::FaultVals
325 SparcFault<STQFMemAddressNotAligned>::vals;
326 template<> SparcFaultBase::FaultVals
327 SparcFault<InstructionRealTranslationMiss>::vals;
328 template<> SparcFaultBase::FaultVals SparcFault<DataRealTranslationMiss>::vals;
329 template<> SparcFaultBase::FaultVals SparcFault<InterruptLevelN>::vals;
330 template<> SparcFaultBase::FaultVals SparcFault<HstickMatch>::vals;
331 template<> SparcFaultBase::FaultVals SparcFault<TrapLevelZero>::vals;
332 template<> SparcFaultBase::FaultVals SparcFault<InterruptVector>::vals;
333 template<> SparcFaultBase::FaultVals SparcFault<PAWatchpoint>::vals;
334 template<> SparcFaultBase::FaultVals SparcFault<VAWatchpoint>::vals;
335 template<> SparcFaultBase::FaultVals
336 SparcFault<FastInstructionAccessMMUMiss>::vals;
337 template<> SparcFaultBase::FaultVals SparcFault<FastDataAccessMMUMiss>::vals;
338 template<>
339 SparcFaultBase::FaultVals SparcFault<FastDataAccessProtection>::vals;
340 template<> SparcFaultBase::FaultVals SparcFault<InstructionBreakpoint>::vals;
341 template<> SparcFaultBase::FaultVals SparcFault<CpuMondo>::vals;
342 template<> SparcFaultBase::FaultVals SparcFault<DevMondo>::vals;
343 template<> SparcFaultBase::FaultVals SparcFault<ResumableError>::vals;
344 template<> SparcFaultBase::FaultVals SparcFault<SpillNNormal>::vals;
345 template<> SparcFaultBase::FaultVals SparcFault<SpillNOther>::vals;
346 template<> SparcFaultBase::FaultVals SparcFault<FillNNormal>::vals;
347 template<> SparcFaultBase::FaultVals SparcFault<FillNOther>::vals;
348 template<> SparcFaultBase::FaultVals SparcFault<TrapInstruction>::vals;
349
350
351 void enterREDState(ThreadContext *tc);
352
353 void doREDFault(ThreadContext *tc, TrapType tt);
354
355 void doNormalFault(ThreadContext *tc, TrapType tt, bool gotoHpriv);
356
357 void getREDVector(MiscReg TT, Addr &PC, Addr &NPC);
358
359 void getHyperVector(ThreadContext * tc, Addr &PC, Addr &NPC, MiscReg TT);
360
361 void getPrivVector(ThreadContext *tc, Addr &PC, Addr &NPC, MiscReg TT,
362 MiscReg TL);
363
364 } // namespace SparcISA
365
366 #endif // __SPARC_FAULTS_HH__