From 27388c0fe0da3b47e112478c787dd4bc78e32562 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Mon, 19 Sep 2011 06:17:19 -0700 Subject: [PATCH] MIPS: Use the CRTP to streamline the Fault class definitions. CRTP stands for the curiously recurring template pattern. --- src/arch/mips/faults.cc | 154 +++++++--------- src/arch/mips/faults.hh | 380 ++++++---------------------------------- 2 files changed, 121 insertions(+), 413 deletions(-) diff --git a/src/arch/mips/faults.cc b/src/arch/mips/faults.cc index 652b5960c..87a69669e 100644 --- a/src/arch/mips/faults.cc +++ b/src/arch/mips/faults.cc @@ -46,130 +46,102 @@ namespace MipsISA { -FaultName MachineCheckFault::_name = "Machine Check"; -FaultVect MachineCheckFault::_vect = 0x0401; -FaultStat MachineCheckFault::_count; +typedef MipsFaultBase::FaultVals FaultVals; -FaultName AlignmentFault::_name = "Alignment"; -FaultVect AlignmentFault::_vect = 0x0301; -FaultStat AlignmentFault::_count; +template <> FaultVals MipsFault::vals = + { "Machine Check", 0x0401 }; -FaultName ResetFault::_name = "Reset Fault"; +template <> FaultVals MipsFault::vals = + { "Alignment", 0x0301 }; + +template <> FaultVals MipsFault::vals = #if FULL_SYSTEM -FaultVect ResetFault::_vect = 0xBFC00000; + { "Reset Fault", 0xBFC00000}; #else -FaultVect ResetFault::_vect = 0x001; + { "Reset Fault", 0x001}; #endif -FaultStat ResetFault::_count; - -FaultName AddressErrorFault::_name = "Address Error"; -FaultVect AddressErrorFault::_vect = 0x0180; -FaultStat AddressErrorFault::_count; -FaultName StoreAddressErrorFault::_name = "Store Address Error"; -FaultVect StoreAddressErrorFault::_vect = 0x0180; -FaultStat StoreAddressErrorFault::_count; +template <> FaultVals MipsFault::vals = + { "Address Error", 0x0180 }; +template <> FaultVals MipsFault::vals = + { "Store Address Error", 0x0180 }; -FaultName SystemCallFault::_name = "Syscall"; -FaultVect SystemCallFault::_vect = 0x0180; -FaultStat SystemCallFault::_count; +template <> FaultVals MipsFault::vals = + { "Syscall", 0x0180 }; -FaultName CoprocessorUnusableFault::_name = "Coprocessor Unusable Fault"; -FaultVect CoprocessorUnusableFault::_vect = 0x180; -FaultStat CoprocessorUnusableFault::_count; +template <> FaultVals MipsFault::vals = + { "Coprocessor Unusable Fault", 0x180 }; -FaultName ReservedInstructionFault::_name = "Reserved Instruction Fault"; -FaultVect ReservedInstructionFault::_vect = 0x0180; -FaultStat ReservedInstructionFault::_count; +template <> FaultVals MipsFault::vals = + { "Reserved Instruction Fault", 0x0180 }; -FaultName ThreadFault::_name = "Thread Fault"; -FaultVect ThreadFault::_vect = 0x00F1; -FaultStat ThreadFault::_count; +template <> FaultVals MipsFault::vals = + { "Thread Fault", 0x00F1 }; -FaultName ArithmeticFault::_name = "Arithmetic Overflow Exception"; -FaultVect ArithmeticFault::_vect = 0x180; -FaultStat ArithmeticFault::_count; +template <> FaultVals MipsFault::vals = + { "Arithmetic Overflow Exception", 0x180 }; -FaultName UnimplementedOpcodeFault::_name = "opdec"; -FaultVect UnimplementedOpcodeFault::_vect = 0x0481; -FaultStat UnimplementedOpcodeFault::_count; +template <> FaultVals MipsFault::vals = + { "opdec", 0x0481 }; -FaultName InterruptFault::_name = "interrupt"; -FaultVect InterruptFault::_vect = 0x0180; -FaultStat InterruptFault::_count; +template <> FaultVals MipsFault::vals = + { "interrupt", 0x0180 }; -FaultName TrapFault::_name = "Trap"; -FaultVect TrapFault::_vect = 0x0180; -FaultStat TrapFault::_count; +template <> FaultVals MipsFault::vals = + { "Trap", 0x0180 }; -FaultName BreakpointFault::_name = "Breakpoint"; -FaultVect BreakpointFault::_vect = 0x0180; -FaultStat BreakpointFault::_count; +template <> FaultVals MipsFault::vals = + { "Breakpoint", 0x0180 }; -FaultName ItbInvalidFault::_name = "Invalid TLB Entry Exception (I-Fetch/LW)"; -FaultVect ItbInvalidFault::_vect = 0x0180; -FaultStat ItbInvalidFault::_count; +template <> FaultVals MipsFault::vals = + { "Invalid TLB Entry Exception (I-Fetch/LW)", 0x0180 }; -FaultName ItbPageFault::_name = "itbmiss"; -FaultVect ItbPageFault::_vect = 0x0181; -FaultStat ItbPageFault::_count; +template <> FaultVals MipsFault::vals = + { "itbmiss", 0x0181 }; -FaultName ItbMissFault::_name = "itbmiss"; -FaultVect ItbMissFault::_vect = 0x0181; -FaultStat ItbMissFault::_count; +template <> FaultVals MipsFault::vals = + { "itbmiss", 0x0181 }; -FaultName ItbAcvFault::_name = "iaccvio"; -FaultVect ItbAcvFault::_vect = 0x0081; -FaultStat ItbAcvFault::_count; +template <> FaultVals MipsFault::vals = + { "iaccvio", 0x0081 }; -FaultName ItbRefillFault::_name = "TLB Refill Exception (I-Fetch/LW)"; -FaultVect ItbRefillFault::_vect = 0x0180; -FaultStat ItbRefillFault::_count; +template <> FaultVals MipsFault::vals = + { "TLB Refill Exception (I-Fetch/LW)", 0x0180 }; -FaultName NDtbMissFault::_name = "dtb_miss_single"; -FaultVect NDtbMissFault::_vect = 0x0201; -FaultStat NDtbMissFault::_count; +template <> FaultVals MipsFault::vals = + { "dtb_miss_single", 0x0201 }; -FaultName PDtbMissFault::_name = "dtb_miss_double"; -FaultVect PDtbMissFault::_vect = 0x0281; -FaultStat PDtbMissFault::_count; +template <> FaultVals MipsFault::vals = + { "dtb_miss_double", 0x0281 }; -FaultName DtbPageFault::_name = "dfault"; -FaultVect DtbPageFault::_vect = 0x0381; -FaultStat DtbPageFault::_count; +template <> FaultVals MipsFault::vals = + { "dfault", 0x0381 }; -FaultName DtbAcvFault::_name = "dfault"; -FaultVect DtbAcvFault::_vect = 0x0381; -FaultStat DtbAcvFault::_count; +template <> FaultVals MipsFault::vals = + { "dfault", 0x0381 }; -FaultName DtbInvalidFault::_name = "Invalid TLB Entry Exception (Store)"; -FaultVect DtbInvalidFault::_vect = 0x0180; -FaultStat DtbInvalidFault::_count; +template <> FaultVals MipsFault::vals = + { "Invalid TLB Entry Exception (Store)", 0x0180 }; -FaultName DtbRefillFault::_name = "TLB Refill Exception (Store)"; -FaultVect DtbRefillFault::_vect = 0x0180; -FaultStat DtbRefillFault::_count; +template <> FaultVals MipsFault::vals = + { "TLB Refill Exception (Store)", 0x0180 }; -FaultName TLBModifiedFault::_name = "TLB Modified Exception"; -FaultVect TLBModifiedFault::_vect = 0x0180; -FaultStat TLBModifiedFault::_count; +template <> FaultVals MipsFault::vals = + { "TLB Modified Exception", 0x0180 }; -FaultName FloatEnableFault::_name = "float_enable_fault"; -FaultVect FloatEnableFault::_vect = 0x0581; -FaultStat FloatEnableFault::_count; +template <> FaultVals MipsFault::vals = + { "float_enable_fault", 0x0581 }; -FaultName IntegerOverflowFault::_name = "Integer Overflow Fault"; -FaultVect IntegerOverflowFault::_vect = 0x0501; -FaultStat IntegerOverflowFault::_count; +template <> FaultVals MipsFault::vals = + { "Integer Overflow Fault", 0x0501 }; -FaultName DspStateDisabledFault::_name = "DSP Disabled Fault"; -FaultVect DspStateDisabledFault::_vect = 0x001a; -FaultStat DspStateDisabledFault::_count; +template <> FaultVals MipsFault::vals = + { "DSP Disabled Fault", 0x001a }; #if FULL_SYSTEM void -MipsFault::setHandlerPC(Addr HandlerBase, ThreadContext *tc) +MipsFaultBase::setHandlerPC(Addr HandlerBase, ThreadContext *tc) { tc->setPC(HandlerBase); tc->setNextPC(HandlerBase + sizeof(MachInst)); @@ -177,7 +149,7 @@ MipsFault::setHandlerPC(Addr HandlerBase, ThreadContext *tc) } void -MipsFault::setExceptionState(ThreadContext *tc, uint8_t excCode) +MipsFaultBase::setExceptionState(ThreadContext *tc, uint8_t excCode) { // modify SRS Ctl - Save CSS, put ESS into CSS StatusReg status = tc->readMiscReg(MISCREG_STATUS); diff --git a/src/arch/mips/faults.hh b/src/arch/mips/faults.hh index 8b7c22ec4..049140229 100644 --- a/src/arch/mips/faults.hh +++ b/src/arch/mips/faults.hh @@ -41,12 +41,19 @@ namespace MipsISA typedef const Addr FaultVect; -class MipsFault : public FaultBase +class MipsFaultBase : public FaultBase { protected: virtual bool skipFaultingInstruction() {return false;} virtual bool setRestartAddress() {return true;} public: + struct FaultVals + { + const FaultName name; + const FaultVect vect; + FaultStat count; + }; + Addr badVAddr; Addr entryHiAsid; Addr entryHiVPN2; @@ -59,59 +66,40 @@ class MipsFault : public FaultBase void setExceptionState(ThreadContext *, uint8_t); void setHandlerPC(Addr, ThreadContext *); #endif - virtual FaultVect vect() = 0; - virtual FaultStat & countStat() = 0; }; -class MachineCheckFault : public MipsFault +template +class MipsFault : public MipsFaultBase +{ + protected: + static FaultVals vals; + public: + FaultName name() const { return vals.name; } + FaultVect vect() const { return vals.vect; } + FaultStat & countStat() { return vals.count; } +}; + +class MachineCheckFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} bool isMachineCheckFault() {return true;} }; -class NonMaskableInterrupt : public MipsFault +class NonMaskableInterrupt : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} bool isNonMaskableInterrupt() {return true;} }; -class AlignmentFault : public MipsFault +class AlignmentFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} bool isAlignmentFault() {return true;} }; -class AddressErrorFault : public MipsFault +class AddressErrorFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} #if FULL_SYSTEM void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); @@ -119,113 +107,35 @@ class AddressErrorFault : public MipsFault }; -class StoreAddressErrorFault : public MipsFault +class StoreAddressErrorFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} #if FULL_SYSTEM void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); #endif }; -class UnimplementedOpcodeFault : public MipsFault -{ - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; - public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} -}; +class UnimplementedOpcodeFault : public MipsFault {}; - -class TLBRefillIFetchFault : public MipsFault +class TLBRefillIFetchFault : public MipsFault { - private: - Addr vaddr; - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); }; -class TLBInvalidIFetchFault : public MipsFault +class TLBInvalidIFetchFault : public MipsFault { - private: - Addr vaddr; - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); }; -class NDtbMissFault : public MipsFault -{ - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; - public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} -}; - -class PDtbMissFault : public MipsFault -{ - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; - public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} -}; - -class DtbPageFault : public MipsFault -{ - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; - public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} -}; - -class DtbAcvFault : public MipsFault -{ - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; - public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} -}; - +class NDtbMissFault : public MipsFault {}; +class PDtbMissFault : public MipsFault {}; +class DtbPageFault : public MipsFault {}; +class DtbAcvFault : public MipsFault {}; static inline Fault genMachineCheckFault() { @@ -237,346 +147,172 @@ static inline Fault genAlignmentFault() return new AlignmentFault; } -class ResetFault : public MipsFault +class ResetFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); }; -class SystemCallFault : public MipsFault +class SystemCallFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} #if FULL_SYSTEM void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); #endif }; -class SoftResetFault : public MipsFault +class SoftResetFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); }; -class DebugSingleStep : public MipsFault +class DebugSingleStep : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); }; -class DebugInterrupt : public MipsFault +class DebugInterrupt : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); }; -class CoprocessorUnusableFault : public MipsFault +class CoprocessorUnusableFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; + protected: int coProcID; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} + CoprocessorUnusableFault(int _procid) : coProcID(_procid) + {} + void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); - CoprocessorUnusableFault(int _procid){ coProcID = _procid;} }; -class ReservedInstructionFault : public MipsFault +class ReservedInstructionFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); }; -class ThreadFault : public MipsFault +class ThreadFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); }; -class ArithmeticFault : public MipsFault +class ArithmeticFault : public MipsFault { protected: bool skipFaultingInstruction() {return true;} - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} #if FULL_SYSTEM void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); #endif }; -class InterruptFault : public MipsFault +class InterruptFault : public MipsFault { protected: bool setRestartAddress() {return false;} - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} - #if FULL_SYSTEM void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); #endif }; -class TrapFault : public MipsFault +class TrapFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} #if FULL_SYSTEM void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); #endif }; -class BreakpointFault : public MipsFault +class BreakpointFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} #if FULL_SYSTEM void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); #endif }; -class ItbRefillFault : public MipsFault +class ItbRefillFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} #if FULL_SYSTEM void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); #endif }; -class DtbRefillFault : public MipsFault +class DtbRefillFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} #if FULL_SYSTEM void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); #endif }; -class ItbPageFault : public MipsFault +class ItbPageFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} #if FULL_SYSTEM void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); #endif }; -class ItbInvalidFault : public MipsFault +class ItbInvalidFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} #if FULL_SYSTEM void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); #endif }; -class TLBModifiedFault : public MipsFault +class TLBModifiedFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} #if FULL_SYSTEM void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); #endif }; -class DtbInvalidFault : public MipsFault +class DtbInvalidFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} #if FULL_SYSTEM void invoke(ThreadContext * tc, StaticInst::StaticInstPtr inst = nullStaticInstPtr); #endif }; -class FloatEnableFault : public MipsFault -{ - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; - public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} -}; - -class ItbMissFault : public MipsFault -{ - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; - public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} -}; - -class ItbAcvFault : public MipsFault -{ - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; - public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} -}; - -class IntegerOverflowFault : public MipsFault -{ - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; - public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} -}; +class FloatEnableFault : public MipsFault {}; +class ItbMissFault : public MipsFault {}; +class ItbAcvFault : public MipsFault {}; +class IntegerOverflowFault : public MipsFault {}; -class DspStateDisabledFault : public MipsFault +class DspStateDisabledFault : public MipsFault { - private: - static FaultName _name; - static FaultVect _vect; - static FaultStat _count; public: - FaultName name() const {return _name;} - FaultVect vect() {return _vect;} - FaultStat & countStat() {return _count;} void invoke(ThreadContext * tc, StaticInstPtr inst = StaticInst::nullStaticInstPtr); }; -- 2.30.2