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