faults.hh revision 8578
12131SN/A/* 25268Sksewell@umich.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan 35224Sksewell@umich.edu * Copyright (c) 2007 MIPS Technologies, Inc. 45224Sksewell@umich.edu * All rights reserved. 52131SN/A * 65224Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without 75224Sksewell@umich.edu * modification, are permitted provided that the following conditions are 85224Sksewell@umich.edu * met: redistributions of source code must retain the above copyright 95224Sksewell@umich.edu * notice, this list of conditions and the following disclaimer; 105224Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright 115224Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the 125224Sksewell@umich.edu * documentation and/or other materials provided with the distribution; 135224Sksewell@umich.edu * neither the name of the copyright holders nor the names of its 145224Sksewell@umich.edu * contributors may be used to endorse or promote products derived from 155224Sksewell@umich.edu * this software without specific prior written permission. 162131SN/A * 175224Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 185224Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 195224Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 205224Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 215224Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 225224Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 235224Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 245224Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 255224Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 265224Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 275224Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu * 295224Sksewell@umich.edu * Authors: Gabe Black 305224Sksewell@umich.edu * Korey Sewell 315222Sksewell@umich.edu * Jaidev Patwardhan 322131SN/A */ 332131SN/A 342239SN/A#ifndef __MIPS_FAULTS_HH__ 352239SN/A#define __MIPS_FAULTS_HH__ 362131SN/A 378575Sgblack@eecs.umich.edu#include "arch/mips/pra_constants.hh" 388575Sgblack@eecs.umich.edu#include "cpu/thread_context.hh" 398575Sgblack@eecs.umich.edu#include "debug/MipsPRA.hh" 402131SN/A#include "sim/faults.hh" 412447SN/A 422447SN/Anamespace MipsISA 432447SN/A{ 446378Sgblack@eecs.umich.edu 452447SN/Atypedef const Addr FaultVect; 462131SN/A 478578Sgblack@eecs.umich.eduenum ExcCode { 488578Sgblack@eecs.umich.edu // A dummy value to use when the code isn't defined or doesn't matter. 498578Sgblack@eecs.umich.edu ExcCodeDummy = 0, 508578Sgblack@eecs.umich.edu 518578Sgblack@eecs.umich.edu ExcCodeInt = 0, 528578Sgblack@eecs.umich.edu ExcCodeMod = 1, 538578Sgblack@eecs.umich.edu ExcCodeTlbL = 2, 548578Sgblack@eecs.umich.edu ExcCodeTlbS = 3, 558578Sgblack@eecs.umich.edu ExcCodeAdEL = 4, 568578Sgblack@eecs.umich.edu ExcCodeAdES = 5, 578578Sgblack@eecs.umich.edu ExcCodeIBE = 6, 588578Sgblack@eecs.umich.edu ExcCodeDBE = 7, 598578Sgblack@eecs.umich.edu ExcCodeSys = 8, 608578Sgblack@eecs.umich.edu ExcCodeBp = 9, 618578Sgblack@eecs.umich.edu ExcCodeRI = 10, 628578Sgblack@eecs.umich.edu ExcCodeCpU = 11, 638578Sgblack@eecs.umich.edu ExcCodeOv = 12, 648578Sgblack@eecs.umich.edu ExcCodeTr = 13, 658578Sgblack@eecs.umich.edu ExcCodeC2E = 18, 668578Sgblack@eecs.umich.edu ExcCodeMDMX = 22, 678578Sgblack@eecs.umich.edu ExcCodeWatch = 23, 688578Sgblack@eecs.umich.edu ExcCodeMCheck = 24, 698578Sgblack@eecs.umich.edu ExcCodeThread = 25, 708578Sgblack@eecs.umich.edu ExcCodeCacheErr = 30 718578Sgblack@eecs.umich.edu}; 728578Sgblack@eecs.umich.edu 738566Sgblack@eecs.umich.educlass MipsFaultBase : public FaultBase 742131SN/A{ 752131SN/A public: 768566Sgblack@eecs.umich.edu struct FaultVals 778566Sgblack@eecs.umich.edu { 788566Sgblack@eecs.umich.edu const FaultName name; 798578Sgblack@eecs.umich.edu const FaultVect offset; 808578Sgblack@eecs.umich.edu const ExcCode code; 818566Sgblack@eecs.umich.edu }; 828566Sgblack@eecs.umich.edu 838578Sgblack@eecs.umich.edu void setExceptionState(ThreadContext *, uint8_t); 848578Sgblack@eecs.umich.edu 858578Sgblack@eecs.umich.edu virtual FaultVect offset(ThreadContext *tc) const = 0; 868578Sgblack@eecs.umich.edu virtual ExcCode code() const = 0; 878578Sgblack@eecs.umich.edu virtual FaultVect base(ThreadContext *tc) const 888578Sgblack@eecs.umich.edu { 898578Sgblack@eecs.umich.edu StatusReg status = tc->readMiscReg(MISCREG_STATUS); 908578Sgblack@eecs.umich.edu if (status.bev) 918578Sgblack@eecs.umich.edu return tc->readMiscReg(MISCREG_EBASE); 928578Sgblack@eecs.umich.edu else 938578Sgblack@eecs.umich.edu return 0xbfc00200; 948578Sgblack@eecs.umich.edu } 958578Sgblack@eecs.umich.edu 968578Sgblack@eecs.umich.edu FaultVect 978578Sgblack@eecs.umich.edu vect(ThreadContext *tc) const 988578Sgblack@eecs.umich.edu { 998578Sgblack@eecs.umich.edu return base(tc) + offset(tc); 1008578Sgblack@eecs.umich.edu } 1018578Sgblack@eecs.umich.edu 1027678Sgblack@eecs.umich.edu void invoke(ThreadContext * tc, 1038578Sgblack@eecs.umich.edu StaticInstPtr inst = StaticInst::nullStaticInstPtr); 1042131SN/A}; 1052131SN/A 1068566Sgblack@eecs.umich.edutemplate <typename T> 1078566Sgblack@eecs.umich.educlass MipsFault : public MipsFaultBase 1082131SN/A{ 1098566Sgblack@eecs.umich.edu protected: 1108566Sgblack@eecs.umich.edu static FaultVals vals; 1112131SN/A public: 1128566Sgblack@eecs.umich.edu FaultName name() const { return vals.name; } 1138578Sgblack@eecs.umich.edu FaultVect offset(ThreadContext *tc) const { return vals.offset; } 1148578Sgblack@eecs.umich.edu ExcCode code() const { return vals.code; } 1158578Sgblack@eecs.umich.edu}; 1168578Sgblack@eecs.umich.edu 1178578Sgblack@eecs.umich.educlass SystemCallFault : public MipsFault<SystemCallFault> {}; 1188578Sgblack@eecs.umich.educlass ReservedInstructionFault : public MipsFault<ReservedInstructionFault> {}; 1198578Sgblack@eecs.umich.educlass ThreadFault : public MipsFault<ThreadFault> {}; 1208578Sgblack@eecs.umich.educlass IntegerOverflowFault : public MipsFault<IntegerOverflowFault> {}; 1218578Sgblack@eecs.umich.educlass TrapFault : public MipsFault<TrapFault> {}; 1228578Sgblack@eecs.umich.educlass BreakpointFault : public MipsFault<BreakpointFault> {}; 1238578Sgblack@eecs.umich.educlass DspStateDisabledFault : public MipsFault<DspStateDisabledFault> {}; 1248578Sgblack@eecs.umich.edu 1258578Sgblack@eecs.umich.educlass MachineCheckFault : public MipsFault<MachineCheckFault> 1268578Sgblack@eecs.umich.edu{ 1278578Sgblack@eecs.umich.edu public: 1288578Sgblack@eecs.umich.edu bool isMachineCheckFault() { return true; } 1298578Sgblack@eecs.umich.edu}; 1308578Sgblack@eecs.umich.edu 1318578Sgblack@eecs.umich.edustatic inline Fault genMachineCheckFault() 1328578Sgblack@eecs.umich.edu{ 1338578Sgblack@eecs.umich.edu return new MachineCheckFault; 1348578Sgblack@eecs.umich.edu} 1358578Sgblack@eecs.umich.edu 1368578Sgblack@eecs.umich.educlass ResetFault : public MipsFault<ResetFault> 1378578Sgblack@eecs.umich.edu{ 1388578Sgblack@eecs.umich.edu public: 1398578Sgblack@eecs.umich.edu void invoke(ThreadContext * tc, 1408578Sgblack@eecs.umich.edu StaticInstPtr inst = StaticInst::nullStaticInstPtr); 1418578Sgblack@eecs.umich.edu 1428578Sgblack@eecs.umich.edu}; 1438578Sgblack@eecs.umich.edu 1448578Sgblack@eecs.umich.educlass SoftResetFault : public MipsFault<SoftResetFault> 1458578Sgblack@eecs.umich.edu{ 1468578Sgblack@eecs.umich.edu public: 1478578Sgblack@eecs.umich.edu void invoke(ThreadContext * tc, 1488578Sgblack@eecs.umich.edu StaticInstPtr inst = StaticInst::nullStaticInstPtr); 1498578Sgblack@eecs.umich.edu}; 1508578Sgblack@eecs.umich.edu 1518578Sgblack@eecs.umich.educlass NonMaskableInterrupt : public MipsFault<NonMaskableInterrupt> 1528578Sgblack@eecs.umich.edu{ 1538578Sgblack@eecs.umich.edu public: 1548578Sgblack@eecs.umich.edu void invoke(ThreadContext * tc, 1558578Sgblack@eecs.umich.edu StaticInstPtr inst = StaticInst::nullStaticInstPtr); 1568578Sgblack@eecs.umich.edu}; 1578578Sgblack@eecs.umich.edu 1588578Sgblack@eecs.umich.educlass CoprocessorUnusableFault : public MipsFault<CoprocessorUnusableFault> 1598578Sgblack@eecs.umich.edu{ 1608578Sgblack@eecs.umich.edu protected: 1618578Sgblack@eecs.umich.edu int coProcID; 1628578Sgblack@eecs.umich.edu public: 1638578Sgblack@eecs.umich.edu CoprocessorUnusableFault(int _procid) : coProcID(_procid) 1648578Sgblack@eecs.umich.edu {} 1658578Sgblack@eecs.umich.edu 1668578Sgblack@eecs.umich.edu void 1678578Sgblack@eecs.umich.edu invoke(ThreadContext * tc, 1688578Sgblack@eecs.umich.edu StaticInstPtr inst = StaticInst::nullStaticInstPtr) 1698578Sgblack@eecs.umich.edu { 1708578Sgblack@eecs.umich.edu MipsFault<CoprocessorUnusableFault>::invoke(tc, inst); 1718578Sgblack@eecs.umich.edu if (FULL_SYSTEM) { 1728578Sgblack@eecs.umich.edu CauseReg cause = tc->readMiscReg(MISCREG_CAUSE); 1738578Sgblack@eecs.umich.edu cause.ce = coProcID; 1748578Sgblack@eecs.umich.edu tc->setMiscReg(MISCREG_CAUSE, cause); 1758578Sgblack@eecs.umich.edu } 1768578Sgblack@eecs.umich.edu } 1778578Sgblack@eecs.umich.edu}; 1788578Sgblack@eecs.umich.edu 1798578Sgblack@eecs.umich.educlass InterruptFault : public MipsFault<InterruptFault> 1808578Sgblack@eecs.umich.edu{ 1818578Sgblack@eecs.umich.edu public: 1828578Sgblack@eecs.umich.edu FaultVect 1838578Sgblack@eecs.umich.edu offset(ThreadContext *tc) const 1848578Sgblack@eecs.umich.edu { 1858578Sgblack@eecs.umich.edu CauseReg cause = tc->readMiscRegNoEffect(MISCREG_CAUSE); 1868578Sgblack@eecs.umich.edu return cause.iv ? 0x200 : 0x000; 1878578Sgblack@eecs.umich.edu } 1888566Sgblack@eecs.umich.edu}; 1898566Sgblack@eecs.umich.edu 1908575Sgblack@eecs.umich.edutemplate <typename T> 1918575Sgblack@eecs.umich.educlass AddressFault : public MipsFault<T> 1928575Sgblack@eecs.umich.edu{ 1938575Sgblack@eecs.umich.edu protected: 1948575Sgblack@eecs.umich.edu Addr vaddr; 1958575Sgblack@eecs.umich.edu bool store; 1968575Sgblack@eecs.umich.edu 1978575Sgblack@eecs.umich.edu AddressFault(Addr _vaddr, bool _store) : vaddr(_vaddr), store(_store) 1988575Sgblack@eecs.umich.edu {} 1998578Sgblack@eecs.umich.edu 2008578Sgblack@eecs.umich.edu void 2018578Sgblack@eecs.umich.edu invoke(ThreadContext * tc, 2028578Sgblack@eecs.umich.edu StaticInstPtr inst = StaticInst::nullStaticInstPtr) 2038578Sgblack@eecs.umich.edu { 2048578Sgblack@eecs.umich.edu MipsFault<T>::invoke(tc, inst); 2058578Sgblack@eecs.umich.edu if (FULL_SYSTEM) 2068578Sgblack@eecs.umich.edu tc->setMiscRegNoEffect(MISCREG_BADVADDR, vaddr); 2078578Sgblack@eecs.umich.edu } 2088578Sgblack@eecs.umich.edu}; 2098578Sgblack@eecs.umich.edu 2108578Sgblack@eecs.umich.educlass AddressErrorFault : public AddressFault<AddressErrorFault> 2118578Sgblack@eecs.umich.edu{ 2128578Sgblack@eecs.umich.edu public: 2138578Sgblack@eecs.umich.edu AddressErrorFault(Addr _vaddr, bool _store) : 2148578Sgblack@eecs.umich.edu AddressFault<AddressErrorFault>(_vaddr, _store) 2158578Sgblack@eecs.umich.edu {} 2168578Sgblack@eecs.umich.edu 2178578Sgblack@eecs.umich.edu ExcCode 2188578Sgblack@eecs.umich.edu code() const 2198578Sgblack@eecs.umich.edu { 2208578Sgblack@eecs.umich.edu return store ? ExcCodeAdES : ExcCodeAdEL; 2218578Sgblack@eecs.umich.edu } 2228578Sgblack@eecs.umich.edu 2238575Sgblack@eecs.umich.edu}; 2248575Sgblack@eecs.umich.edu 2258575Sgblack@eecs.umich.edutemplate <typename T> 2268575Sgblack@eecs.umich.educlass TlbFault : public AddressFault<T> 2278575Sgblack@eecs.umich.edu{ 2288575Sgblack@eecs.umich.edu protected: 2298575Sgblack@eecs.umich.edu Addr asid; 2308575Sgblack@eecs.umich.edu Addr vpn; 2318575Sgblack@eecs.umich.edu 2328575Sgblack@eecs.umich.edu TlbFault(Addr _asid, Addr _vaddr, Addr _vpn, bool _store) : 2338575Sgblack@eecs.umich.edu AddressFault<T>(_vaddr, _store), asid(_asid), vpn(_vpn) 2348575Sgblack@eecs.umich.edu {} 2358575Sgblack@eecs.umich.edu 2368575Sgblack@eecs.umich.edu void 2378575Sgblack@eecs.umich.edu setTlbExceptionState(ThreadContext *tc, uint8_t excCode) 2388575Sgblack@eecs.umich.edu { 2398575Sgblack@eecs.umich.edu this->setExceptionState(tc, excCode); 2408575Sgblack@eecs.umich.edu 2418575Sgblack@eecs.umich.edu tc->setMiscRegNoEffect(MISCREG_BADVADDR, this->vaddr); 2428575Sgblack@eecs.umich.edu EntryHiReg entryHi = tc->readMiscReg(MISCREG_ENTRYHI); 2438575Sgblack@eecs.umich.edu entryHi.asid = this->asid; 2448575Sgblack@eecs.umich.edu entryHi.vpn2 = this->vpn >> 2; 2458575Sgblack@eecs.umich.edu entryHi.vpn2x = this->vpn & 0x3; 2468575Sgblack@eecs.umich.edu tc->setMiscRegNoEffect(MISCREG_ENTRYHI, entryHi); 2478575Sgblack@eecs.umich.edu 2488575Sgblack@eecs.umich.edu ContextReg context = tc->readMiscReg(MISCREG_CONTEXT); 2498575Sgblack@eecs.umich.edu context.badVPN2 = this->vpn >> 2; 2508575Sgblack@eecs.umich.edu tc->setMiscRegNoEffect(MISCREG_CONTEXT, context); 2518575Sgblack@eecs.umich.edu } 2528575Sgblack@eecs.umich.edu 2538578Sgblack@eecs.umich.edu void 2548578Sgblack@eecs.umich.edu invoke(ThreadContext * tc, 2558578Sgblack@eecs.umich.edu StaticInstPtr inst = StaticInst::nullStaticInstPtr) 2568578Sgblack@eecs.umich.edu { 2578578Sgblack@eecs.umich.edu if (FULL_SYSTEM) { 2588578Sgblack@eecs.umich.edu DPRINTF(MipsPRA, "Fault %s encountered.\n", name()); 2598578Sgblack@eecs.umich.edu tc->pcState(this->vect(tc)); 2608578Sgblack@eecs.umich.edu setTlbExceptionState(tc, this->code()); 2618578Sgblack@eecs.umich.edu } else { 2628578Sgblack@eecs.umich.edu AddressFault<T>::invoke(tc, inst); 2638578Sgblack@eecs.umich.edu } 2648578Sgblack@eecs.umich.edu } 2655222Sksewell@umich.edu 2668578Sgblack@eecs.umich.edu ExcCode 2678578Sgblack@eecs.umich.edu code() const 2688578Sgblack@eecs.umich.edu { 2698578Sgblack@eecs.umich.edu return this->store ? ExcCodeTlbS : ExcCodeTlbL; 2708578Sgblack@eecs.umich.edu } 2715222Sksewell@umich.edu}; 2725222Sksewell@umich.edu 2738575Sgblack@eecs.umich.educlass TlbRefillFault : public TlbFault<TlbRefillFault> 2745222Sksewell@umich.edu{ 2755222Sksewell@umich.edu public: 2768575Sgblack@eecs.umich.edu TlbRefillFault(Addr asid, Addr vaddr, Addr vpn, bool store) : 2778575Sgblack@eecs.umich.edu TlbFault<TlbRefillFault>(asid, vaddr, vpn, store) 2788575Sgblack@eecs.umich.edu {} 2798578Sgblack@eecs.umich.edu 2808578Sgblack@eecs.umich.edu FaultVect 2818578Sgblack@eecs.umich.edu offset(ThreadContext *tc) const 2828578Sgblack@eecs.umich.edu { 2838578Sgblack@eecs.umich.edu StatusReg status = tc->readMiscReg(MISCREG_STATUS); 2848578Sgblack@eecs.umich.edu return status.exl ? 0x180 : 0x000; 2858578Sgblack@eecs.umich.edu } 2865222Sksewell@umich.edu}; 2876378Sgblack@eecs.umich.edu 2888575Sgblack@eecs.umich.educlass TlbInvalidFault : public TlbFault<TlbInvalidFault> 2895222Sksewell@umich.edu{ 2905222Sksewell@umich.edu public: 2918575Sgblack@eecs.umich.edu TlbInvalidFault(Addr asid, Addr vaddr, Addr vpn, bool store) : 2928575Sgblack@eecs.umich.edu TlbFault<TlbInvalidFault>(asid, vaddr, vpn, store) 2938575Sgblack@eecs.umich.edu {} 2946378Sgblack@eecs.umich.edu}; 2955222Sksewell@umich.edu 2968575Sgblack@eecs.umich.educlass TlbModifiedFault : public TlbFault<TlbModifiedFault> 2975222Sksewell@umich.edu{ 2985222Sksewell@umich.edu public: 2998575Sgblack@eecs.umich.edu TlbModifiedFault(Addr asid, Addr vaddr, Addr vpn) : 3008575Sgblack@eecs.umich.edu TlbFault<TlbModifiedFault>(asid, vaddr, vpn, false) 3018575Sgblack@eecs.umich.edu {} 3025222Sksewell@umich.edu 3038578Sgblack@eecs.umich.edu ExcCode code() const { return vals.code; } 3044661Sksewell@umich.edu}; 3054661Sksewell@umich.edu 3067811Ssteve.reinhardt@amd.com} // namespace MipsISA 3072131SN/A 3085222Sksewell@umich.edu#endif // __MIPS_FAULTS_HH__ 309