faults.hh revision 3890
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 PAWatchpoint : public SparcFault<PAWatchpoint> {}; 197 198class VAWatchpoint : public SparcFault<VAWatchpoint> {}; 199 200class FastInstructionAccessMMUMiss : 201 public SparcFault<FastInstructionAccessMMUMiss> {}; 202 203class FastDataAccessMMUMiss : public SparcFault<FastDataAccessMMUMiss> {}; 204 205class FastDataAccessProtection : public SparcFault<FastDataAccessProtection> {}; 206 207class InstructionBreakpoint : public SparcFault<InstructionBreakpoint> {}; 208 209class CpuMondo : public SparcFault<CpuMondo> {}; 210 211class DevMondo : public SparcFault<DevMondo> {}; 212 213class ResumeableError : public SparcFault<ResumeableError> {}; 214 215class SpillNNormal : public EnumeratedFault<SpillNNormal> 216{ 217 public: 218 SpillNNormal(uint32_t n) : EnumeratedFault<SpillNNormal>(n) {;} 219 //These need to be handled specially to enable spill traps in SE 220#if !FULL_SYSTEM 221 void invoke(ThreadContext * tc); 222#endif 223}; 224 225class SpillNOther : public EnumeratedFault<SpillNOther> 226{ 227 public: 228 SpillNOther(uint32_t n) : EnumeratedFault<SpillNOther>(n) {;} 229}; 230 231class FillNNormal : public EnumeratedFault<FillNNormal> 232{ 233 public: 234 FillNNormal(uint32_t n) : EnumeratedFault<FillNNormal>(n) {;} 235 //These need to be handled specially to enable fill traps in SE 236#if !FULL_SYSTEM 237 void invoke(ThreadContext * tc); 238#endif 239}; 240 241class FillNOther : public EnumeratedFault<FillNOther> 242{ 243 public: 244 FillNOther(uint32_t n) : EnumeratedFault<FillNOther>(n) {;} 245}; 246 247class TrapInstruction : public EnumeratedFault<TrapInstruction> 248{ 249 250 public: 251 TrapInstruction(uint32_t n) : EnumeratedFault<TrapInstruction>(n) {;} 252}; 253 254#if !FULL_SYSTEM 255class PageTableFault : public SparcFault<PageTableFault> 256{ 257 private: 258 Addr vaddr; 259 public: 260 PageTableFault(Addr va) : vaddr(va) {} 261 void invoke(ThreadContext * tc); 262}; 263 264static inline Fault genPageTableFault(Addr va) 265{ 266 return new PageTableFault(va); 267} 268#endif 269 270static inline Fault genMachineCheckFault() 271{ 272 return new InternalProcessorError; 273} 274 275static inline Fault genAlignmentFault() 276{ 277 return new MemAddressNotAligned; 278} 279 280 281} // SparcISA namespace 282 283#endif // __SPARC_FAULTS_HH__ 284