2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
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.
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.
32 #ifndef __SPARC_FAULTS_HH__
33 #define __SPARC_FAULTS_HH__
35 #include "cpu/static_inst.hh"
36 #include "sim/faults.hh"
38 // The design of the "name" and "vect" functions is in sim/faults.hh
43 typedef uint32_t TrapType;
44 typedef uint32_t FaultPriority;
48 class SparcFaultBase : public FaultBase
55 H, Hyperprivileged = H,
60 using PrivilegeLevelSpec = std::array<PrivilegeLevel, NumLevels>;
64 const TrapType trapType;
65 const FaultPriority priority;
66 const PrivilegeLevelSpec nextPrivilegeLevel;
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)
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;
83 class SparcFault : public SparcFaultBase
86 static FaultVals vals;
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; }
94 getNextLevel(PrivilegeLevel current)
96 return vals.nextPrivilegeLevel[current];
100 class PowerOnReset : public SparcFault<PowerOnReset>
102 void invoke(ThreadContext * tc, const StaticInstPtr &inst =
103 StaticInst::nullStaticInstPtr);
106 class WatchDogReset : public SparcFault<WatchDogReset> {};
108 class ExternallyInitiatedReset : public SparcFault<ExternallyInitiatedReset> {};
110 class SoftwareInitiatedReset : public SparcFault<SoftwareInitiatedReset> {};
112 class REDStateException : public SparcFault<REDStateException> {};
114 class StoreError : public SparcFault<StoreError> {};
116 class InstructionAccessException : public SparcFault<InstructionAccessException> {};
118 // class InstructionAccessMMUMiss : public SparcFault<InstructionAccessMMUMiss> {};
120 class InstructionAccessError : public SparcFault<InstructionAccessError> {};
122 class IllegalInstruction : public SparcFault<IllegalInstruction> {};
124 class PrivilegedOpcode : public SparcFault<PrivilegedOpcode> {};
126 // class UnimplementedLDD : public SparcFault<UnimplementedLDD> {};
128 // class UnimplementedSTD : public SparcFault<UnimplementedSTD> {};
130 class FpDisabled : public SparcFault<FpDisabled> {};
131 class VecDisabled : public SparcFault<VecDisabled> {};
133 class FpExceptionIEEE754 : public SparcFault<FpExceptionIEEE754> {};
135 class FpExceptionOther : public SparcFault<FpExceptionOther> {};
137 class TagOverflow : public SparcFault<TagOverflow> {};
139 class CleanWindow : public SparcFault<CleanWindow> {};
141 class DivisionByZero : public SparcFault<DivisionByZero> {};
143 class InternalProcessorError :
144 public SparcFault<InternalProcessorError> {};
146 class InstructionInvalidTSBEntry :
147 public SparcFault<InstructionInvalidTSBEntry> {};
149 class DataInvalidTSBEntry : public SparcFault<DataInvalidTSBEntry> {};
151 class DataAccessException : public SparcFault<DataAccessException> {};
153 // class DataAccessMMUMiss : public SparcFault<DataAccessMMUMiss> {};
155 class DataAccessError : public SparcFault<DataAccessError> {};
157 class DataAccessProtection : public SparcFault<DataAccessProtection> {};
159 class MemAddressNotAligned :
160 public SparcFault<MemAddressNotAligned> {};
162 class LDDFMemAddressNotAligned : public SparcFault<LDDFMemAddressNotAligned> {};
164 class STDFMemAddressNotAligned : public SparcFault<STDFMemAddressNotAligned> {};
166 class PrivilegedAction : public SparcFault<PrivilegedAction> {};
168 class LDQFMemAddressNotAligned : public SparcFault<LDQFMemAddressNotAligned> {};
170 class STQFMemAddressNotAligned : public SparcFault<STQFMemAddressNotAligned> {};
172 class InstructionRealTranslationMiss :
173 public SparcFault<InstructionRealTranslationMiss> {};
175 class DataRealTranslationMiss : public SparcFault<DataRealTranslationMiss> {};
177 // class AsyncDataError : public SparcFault<AsyncDataError> {};
180 class EnumeratedFault : public SparcFault<T>
185 EnumeratedFault(uint32_t n) : SparcFault<T>(), _n(n) {}
186 TrapType trapType() { return SparcFault<T>::trapType() + _n; }
189 class InterruptLevelN : public EnumeratedFault<InterruptLevelN>
192 InterruptLevelN(uint32_t n) : EnumeratedFault<InterruptLevelN>(n) {;}
193 FaultPriority priority() { return 3200 - _n*100; }
196 class HstickMatch : public SparcFault<HstickMatch> {};
198 class TrapLevelZero : public SparcFault<TrapLevelZero> {};
200 class InterruptVector : public SparcFault<InterruptVector> {};
202 class PAWatchpoint : public SparcFault<PAWatchpoint> {};
204 class VAWatchpoint : public SparcFault<VAWatchpoint> {};
206 class FastInstructionAccessMMUMiss :
207 public SparcFault<FastInstructionAccessMMUMiss>
212 FastInstructionAccessMMUMiss(Addr addr) : vaddr(addr)
214 FastInstructionAccessMMUMiss() : vaddr(0)
216 void invoke(ThreadContext * tc, const StaticInstPtr &inst =
217 StaticInst::nullStaticInstPtr);
220 class FastDataAccessMMUMiss : public SparcFault<FastDataAccessMMUMiss>
225 FastDataAccessMMUMiss(Addr addr) : vaddr(addr)
227 FastDataAccessMMUMiss() : vaddr(0)
229 void invoke(ThreadContext * tc, const StaticInstPtr &inst =
230 StaticInst::nullStaticInstPtr);
233 class FastDataAccessProtection : public SparcFault<FastDataAccessProtection> {};
235 class InstructionBreakpoint : public SparcFault<InstructionBreakpoint> {};
237 class CpuMondo : public SparcFault<CpuMondo> {};
239 class DevMondo : public SparcFault<DevMondo> {};
241 class ResumableError : public SparcFault<ResumableError> {};
243 class SpillNNormal : public EnumeratedFault<SpillNNormal>
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);
252 class SpillNOther : public EnumeratedFault<SpillNOther>
255 SpillNOther(uint32_t n) : EnumeratedFault<SpillNOther>(n)
259 class FillNNormal : public EnumeratedFault<FillNNormal>
262 FillNNormal(uint32_t n) : EnumeratedFault<FillNNormal>(n)
264 // These need to be handled specially to enable fill traps in SE
265 void invoke(ThreadContext * tc, const StaticInstPtr &inst =
266 StaticInst::nullStaticInstPtr);
269 class FillNOther : public EnumeratedFault<FillNOther>
272 FillNOther(uint32_t n) : EnumeratedFault<FillNOther>(n)
276 class TrapInstruction : public EnumeratedFault<TrapInstruction>
279 TrapInstruction(uint32_t n) : EnumeratedFault<TrapInstruction>(n)
281 // In SE, trap instructions are requesting services from the OS.
282 void invoke(ThreadContext * tc, const StaticInstPtr &inst =
283 StaticInst::nullStaticInstPtr);
287 * Explicitly declare template static member variables to avoid warnings
288 * in some clang versions
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;
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;
351 void enterREDState(ThreadContext *tc);
353 void doREDFault(ThreadContext *tc, TrapType tt);
355 void doNormalFault(ThreadContext *tc, TrapType tt, bool gotoHpriv);
357 void getREDVector(MiscReg TT, Addr &PC, Addr &NPC);
359 void getHyperVector(ThreadContext * tc, Addr &PC, Addr &NPC, MiscReg TT);
361 void getPrivVector(ThreadContext *tc, Addr &PC, Addr &NPC, MiscReg TT,
364 } // namespace SparcISA
366 #endif // __SPARC_FAULTS_HH__