faults.hh revision 4103
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 "sim/faults.hh"
36
37// The design of the "name" and "vect" functions is in sim/faults.hh
38
39namespace SparcISA
40{
41
42typedef uint32_t TrapType;
43typedef uint32_t FaultPriority;
44
45class SparcFaultBase : public FaultBase
46{
47  public:
48    enum PrivilegeLevel
49    {
50        U, User = U,
51        P, Privileged = P,
52        H, Hyperprivileged = H,
53        NumLevels,
54        SH = -1,
55        ShouldntHappen = SH
56    };
57    struct FaultVals
58    {
59        const FaultName name;
60        const TrapType trapType;
61        const FaultPriority priority;
62        const PrivilegeLevel nextPrivilegeLevel[NumLevels];
63        FaultStat count;
64    };
65#if FULL_SYSTEM
66    void invoke(ThreadContext * tc);
67#endif
68    virtual FaultName name() = 0;
69    virtual TrapType trapType() = 0;
70    virtual FaultPriority priority() = 0;
71    virtual FaultStat & countStat() = 0;
72    virtual PrivilegeLevel getNextLevel(PrivilegeLevel current) = 0;
73};
74
75template<typename T>
76class SparcFault : public SparcFaultBase
77{
78  protected:
79    static FaultVals vals;
80  public:
81    FaultName name() {return vals.name;}
82    TrapType trapType() {return vals.trapType;}
83    FaultPriority priority() {return vals.priority;}
84    FaultStat & countStat() {return vals.count;}
85    PrivilegeLevel getNextLevel(PrivilegeLevel current)
86    {
87        return vals.nextPrivilegeLevel[current];
88    }
89};
90
91class PowerOnReset : public SparcFault<PowerOnReset>
92{
93    void invoke(ThreadContext * tc);
94};
95
96class WatchDogReset : public SparcFault<WatchDogReset> {};
97
98class ExternallyInitiatedReset : public SparcFault<ExternallyInitiatedReset> {};
99
100class SoftwareInitiatedReset : public SparcFault<SoftwareInitiatedReset> {};
101
102class REDStateException : public SparcFault<REDStateException> {};
103
104class StoreError : public SparcFault<StoreError> {};
105
106class InstructionAccessException : public SparcFault<InstructionAccessException> {};
107
108//class InstructionAccessMMUMiss : public SparcFault<InstructionAccessMMUMiss> {};
109
110class InstructionAccessError : public SparcFault<InstructionAccessError> {};
111
112class IllegalInstruction : public SparcFault<IllegalInstruction> {};
113
114class PrivilegedOpcode : public SparcFault<PrivilegedOpcode> {};
115
116//class UnimplementedLDD : public SparcFault<UnimplementedLDD> {};
117
118//class UnimplementedSTD : public SparcFault<UnimplementedSTD> {};
119
120class FpDisabled : public SparcFault<FpDisabled> {};
121
122class FpExceptionIEEE754 : public SparcFault<FpExceptionIEEE754> {};
123
124class FpExceptionOther : public SparcFault<FpExceptionOther> {};
125
126class TagOverflow : public SparcFault<TagOverflow> {};
127
128class CleanWindow : public SparcFault<CleanWindow> {};
129
130class DivisionByZero : public SparcFault<DivisionByZero> {};
131
132class InternalProcessorError :
133    public SparcFault<InternalProcessorError>
134{
135  public:
136    bool isMachineCheckFault() {return true;}
137};
138
139class InstructionInvalidTSBEntry : public SparcFault<InstructionInvalidTSBEntry> {};
140
141class DataInvalidTSBEntry : public SparcFault<DataInvalidTSBEntry> {};
142
143class DataAccessException : public SparcFault<DataAccessException> {};
144
145//class DataAccessMMUMiss : public SparcFault<DataAccessMMUMiss> {};
146
147class DataAccessError : public SparcFault<DataAccessError> {};
148
149class DataAccessProtection : public SparcFault<DataAccessProtection> {};
150
151class MemAddressNotAligned :
152    public SparcFault<MemAddressNotAligned>
153{
154  public:
155    bool isAlignmentFault() {return true;}
156};
157
158class LDDFMemAddressNotAligned : public SparcFault<LDDFMemAddressNotAligned> {};
159
160class STDFMemAddressNotAligned : public SparcFault<STDFMemAddressNotAligned> {};
161
162class PrivilegedAction : public SparcFault<PrivilegedAction> {};
163
164class LDQFMemAddressNotAligned : public SparcFault<LDQFMemAddressNotAligned> {};
165
166class STQFMemAddressNotAligned : public SparcFault<STQFMemAddressNotAligned> {};
167
168class InstructionRealTranslationMiss :
169    public SparcFault<InstructionRealTranslationMiss> {};
170
171class DataRealTranslationMiss : public SparcFault<DataRealTranslationMiss> {};
172
173//class AsyncDataError : public SparcFault<AsyncDataError> {};
174
175template <class T>
176class EnumeratedFault : public SparcFault<T>
177{
178  protected:
179    uint32_t _n;
180  public:
181    EnumeratedFault(uint32_t n) : SparcFault<T>(), _n(n) {}
182    TrapType trapType() {return SparcFault<T>::trapType() + _n;}
183};
184
185class InterruptLevelN : public EnumeratedFault<InterruptLevelN>
186{
187  public:
188    InterruptLevelN(uint32_t n) : EnumeratedFault<InterruptLevelN>(n) {;}
189    FaultPriority priority() {return 3200 - _n*100;}
190};
191
192class HstickMatch : public SparcFault<HstickMatch> {};
193
194class TrapLevelZero : public SparcFault<TrapLevelZero> {};
195
196class InterruptVector : public SparcFault<InterruptVector> {};
197
198class PAWatchpoint : public SparcFault<PAWatchpoint> {};
199
200class VAWatchpoint : public SparcFault<VAWatchpoint> {};
201
202class FastInstructionAccessMMUMiss :
203    public SparcFault<FastInstructionAccessMMUMiss> {};
204
205class FastDataAccessMMUMiss : public SparcFault<FastDataAccessMMUMiss> {};
206
207class FastDataAccessProtection : public SparcFault<FastDataAccessProtection> {};
208
209class InstructionBreakpoint : public SparcFault<InstructionBreakpoint> {};
210
211class CpuMondo : public SparcFault<CpuMondo> {};
212
213class DevMondo : public SparcFault<DevMondo> {};
214
215class ResumableError : public SparcFault<ResumableError> {};
216
217class SpillNNormal : public EnumeratedFault<SpillNNormal>
218{
219  public:
220    SpillNNormal(uint32_t n) : EnumeratedFault<SpillNNormal>(n) {;}
221    //These need to be handled specially to enable spill traps in SE
222#if !FULL_SYSTEM
223    void invoke(ThreadContext * tc);
224#endif
225};
226
227class SpillNOther : public EnumeratedFault<SpillNOther>
228{
229  public:
230    SpillNOther(uint32_t n) : EnumeratedFault<SpillNOther>(n) {;}
231};
232
233class FillNNormal : public EnumeratedFault<FillNNormal>
234{
235  public:
236    FillNNormal(uint32_t n) : EnumeratedFault<FillNNormal>(n) {;}
237    //These need to be handled specially to enable fill traps in SE
238#if !FULL_SYSTEM
239    void invoke(ThreadContext * tc);
240#endif
241};
242
243class FillNOther : public EnumeratedFault<FillNOther>
244{
245  public:
246    FillNOther(uint32_t n) : EnumeratedFault<FillNOther>(n) {;}
247};
248
249class TrapInstruction : public EnumeratedFault<TrapInstruction>
250{
251
252  public:
253    TrapInstruction(uint32_t n) : EnumeratedFault<TrapInstruction>(n) {;}
254};
255
256#if !FULL_SYSTEM
257class PageTableFault : public SparcFault<PageTableFault>
258{
259  private:
260    Addr vaddr;
261  public:
262    PageTableFault(Addr va) : vaddr(va) {}
263    void invoke(ThreadContext * tc);
264};
265
266static inline Fault genPageTableFault(Addr va)
267{
268    return new PageTableFault(va);
269}
270#endif
271
272static inline Fault genMachineCheckFault()
273{
274    return new InternalProcessorError;
275}
276
277static inline Fault genAlignmentFault()
278{
279    return new MemAddressNotAligned;
280}
281
282
283} // SparcISA namespace
284
285#endif // __SPARC_FAULTS_HH__
286