Major clean up of the fault code.
[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 __ALPHA_FAULTS_HH__
33 #define __ALPHA_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 struct FaultVals
49 {
50 const FaultName name;
51 const TrapType trapType;
52 const FaultPriority priority;
53 FaultStat count;
54 };
55 #if FULL_SYSTEM
56 void invoke(ThreadContext * tc);
57 #endif
58 virtual FaultName name() = 0;
59 virtual TrapType trapType() = 0;
60 virtual FaultPriority priority() = 0;
61 virtual FaultStat & countStat() = 0;
62 };
63
64 template<typename T>
65 class SparcFault : public SparcFaultBase
66 {
67 protected:
68 static FaultVals vals;
69 public:
70 FaultName name() {return vals.name;}
71 TrapType trapType() {return vals.trapType;}
72 FaultPriority priority() {return vals.priority;}
73 FaultStat & countStat() {return vals.count;}
74 };
75
76 class InternalProcessorError :
77 public SparcFault<InternalProcessorError>
78 {
79 public:
80 bool isMachineCheckFault() {return true;}
81 };
82
83 class MemAddressNotAligned :
84 public SparcFault<MemAddressNotAligned>
85 {
86 public:
87 bool isAlignmentFault() {return true;}
88 };
89
90 #if !FULL_SYSTEM
91 class PageTableFault : public SparcFault<PageTableFault>
92 {
93 private:
94 Addr vaddr;
95 public:
96 PageTableFault(Addr va) : vaddr(va) {}
97 void invoke(ThreadContext * tc);
98 };
99
100 static inline Fault genPageTableFault(Addr va)
101 {
102 return new PageTableFault(va);
103 }
104 #endif
105
106 static inline Fault genMachineCheckFault()
107 {
108 return new InternalProcessorError;
109 }
110
111 static inline Fault genAlignmentFault()
112 {
113 return new MemAddressNotAligned;
114 }
115
116 class PowerOnReset : public SparcFault<PowerOnReset> {};
117
118 class WatchDogReset : public SparcFault<WatchDogReset> {};
119
120 class ExternallyInitiatedReset : public SparcFault<ExternallyInitiatedReset> {};
121
122 class SoftwareInitiatedReset : public SparcFault<SoftwareInitiatedReset> {};
123
124 class REDStateException : public SparcFault<REDStateException> {};
125
126 class InstructionAccessException : public SparcFault<InstructionAccessException> {};
127
128 class InstructionAccessMMUMiss : public SparcFault<InstructionAccessMMUMiss> {};
129
130 class InstructionAccessError : public SparcFault<InstructionAccessError> {};
131
132 class IllegalInstruction : public SparcFault<IllegalInstruction> {};
133
134 class PrivilegedOpcode : public SparcFault<PrivilegedOpcode> {};
135
136 class UnimplementedLDD : public SparcFault<UnimplementedLDD> {};
137
138 class UnimplementedSTD : public SparcFault<UnimplementedSTD> {};
139
140 class FpDisabled : public SparcFault<FpDisabled> {};
141
142 class FpExceptionIEEE754 : public SparcFault<FpExceptionIEEE754> {};
143
144 class FpExceptionOther : public SparcFault<FpExceptionOther> {};
145
146 class TagOverflow : public SparcFault<TagOverflow> {};
147
148 class DivisionByZero : public SparcFault<DivisionByZero> {};
149
150 class DataAccessException : public SparcFault<DataAccessException> {};
151
152 class DataAccessMMUMiss : public SparcFault<DataAccessMMUMiss> {};
153
154 class DataAccessError : public SparcFault<DataAccessError> {};
155
156 class DataAccessProtection : public SparcFault<DataAccessProtection> {};
157
158 class LDDFMemAddressNotAligned : public SparcFault<LDDFMemAddressNotAligned> {};
159
160 class STDFMemAddressNotAligned : public SparcFault<STDFMemAddressNotAligned> {};
161
162 class PrivilegedAction : public SparcFault<PrivilegedAction> {};
163
164 class LDQFMemAddressNotAligned : public SparcFault<LDQFMemAddressNotAligned> {};
165
166 class STQFMemAddressNotAligned : public SparcFault<STQFMemAddressNotAligned> {};
167
168 class AsyncDataError : public SparcFault<AsyncDataError> {};
169
170 class CleanWindow : public SparcFault<CleanWindow> {};
171
172 template <class T>
173 class EnumeratedFault : public SparcFault<T>
174 {
175 protected:
176 uint32_t _n;
177 public:
178 EnumeratedFault(uint32_t n) : SparcFault<T>(), _n(n) {}
179 TrapType trapType() {return SparcFault<T>::trapType() + _n;}
180 };
181
182 class InterruptLevelN : public EnumeratedFault<InterruptLevelN>
183 {
184 public:
185 InterruptLevelN(uint32_t n) :
186 EnumeratedFault<InterruptLevelN>(n) {;}
187 FaultPriority priority() {return 32 - _n;}
188 };
189
190 class SpillNNormal : public EnumeratedFault<SpillNNormal>
191 {
192 public:
193 SpillNNormal(uint32_t n) :
194 EnumeratedFault<SpillNNormal>(n) {;}
195 void invoke(ThreadContext * tc);
196 };
197
198 class SpillNOther : public EnumeratedFault<SpillNOther>
199 {
200 public:
201 SpillNOther(uint32_t n) :
202 EnumeratedFault<SpillNOther>(n) {;}
203 };
204
205 class FillNNormal : public EnumeratedFault<FillNNormal>
206 {
207 public:
208 FillNNormal(uint32_t n) :
209 EnumeratedFault<FillNNormal>(n) {;}
210 void invoke(ThreadContext * tc);
211 };
212
213 class FillNOther : public EnumeratedFault<FillNOther>
214 {
215 public:
216 FillNOther(uint32_t n) :
217 EnumeratedFault<FillNOther>(n) {;}
218 };
219
220 class TrapInstruction : public EnumeratedFault<TrapInstruction>
221 {
222 private:
223 uint64_t syscall_num;
224 public:
225 TrapInstruction(uint32_t n, uint64_t syscall) :
226 EnumeratedFault<TrapInstruction>(n), syscall_num(syscall) {;}
227 #if !FULL_SYSTEM
228 void invoke(ThreadContext * tc);
229 #endif
230 };
231
232
233 } // SparcISA namespace
234
235 #endif // __FAULTS_HH__