faults.cc revision 5250
12131SN/A/*
25222Sksewell@umich.edu * Copyright N) 2007 MIPS Technologies, Inc.  All Rights Reserved
32131SN/A *
45222Sksewell@umich.edu * This software is part of the M5 simulator.
52131SN/A *
65222Sksewell@umich.edu * THIS IS A LEGAL AGREEMENT.  BY DOWNLOADING, USING, COPYING, CREATING
75222Sksewell@umich.edu * DERIVATIVE WORKS, AND/OR DISTRIBUTING THIS SOFTWARE YOU ARE AGREEING
85222Sksewell@umich.edu * TO THESE TERMS AND CONDITIONS.
92665Ssaidi@eecs.umich.edu *
105222Sksewell@umich.edu * Permission is granted to use, copy, create derivative works and
115222Sksewell@umich.edu * distribute this software and such derivative works for any purpose,
125222Sksewell@umich.edu * so long as (1) the copyright notice above, this grant of permission,
135222Sksewell@umich.edu * and the disclaimer below appear in all copies and derivative works
145222Sksewell@umich.edu * made, (2) the copyright notice above is augmented as appropriate to
155222Sksewell@umich.edu * reflect the addition of any new copyrightable work in a derivative
165222Sksewell@umich.edu * work (e.g., Copyright N) <Publication Year> Copyright Owner), and (3)
175222Sksewell@umich.edu * the name of MIPS Technologies, Inc. ($(B!H(BMIPS$(B!I(B) is not used in any
185222Sksewell@umich.edu * advertising or publicity pertaining to the use or distribution of
195222Sksewell@umich.edu * this software without specific, written prior authorization.
205222Sksewell@umich.edu *
215222Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED $(B!H(BAS IS.$(B!I(B  MIPS MAKES NO WARRANTIES AND
225222Sksewell@umich.edu * DISCLAIMS ALL WARRANTIES, WHETHER EXPRESS, STATUTORY, IMPLIED OR
235222Sksewell@umich.edu * OTHERWISE, INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
245222Sksewell@umich.edu * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
255222Sksewell@umich.edu * NON-INFRINGEMENT OF THIRD PARTY RIGHTS, REGARDING THIS SOFTWARE.
265222Sksewell@umich.edu * IN NO EVENT SHALL MIPS BE LIABLE FOR ANY DAMAGES, INCLUDING DIRECT,
275222Sksewell@umich.edu * INDIRECT, INCIDENTAL, CONSEQUENTIAL, SPECIAL, OR PUNITIVE DAMAGES OF
285222Sksewell@umich.edu * ANY KIND OR NATURE, ARISING OUT OF OR IN CONNECTION WITH THIS AGREEMENT,
295222Sksewell@umich.edu * THIS SOFTWARE AND/OR THE USE OF THIS SOFTWARE, WHETHER SUCH LIABILITY
305222Sksewell@umich.edu * IS ASSERTED ON THE BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE OR
315222Sksewell@umich.edu * STRICT LIABILITY), OR OTHERWISE, EVEN IF MIPS HAS BEEN WARNED OF THE
325222Sksewell@umich.edu * POSSIBILITY OF ANY SUCH LOSS OR DAMAGE IN ADVANCE.
335222Sksewell@umich.edu *
345222Sksewell@umich.edu * Authors: Gabe M. Black
355222Sksewell@umich.edu *          Korey L. Sewell
365222Sksewell@umich.edu *          Jaidev Patwardhan
372131SN/A */
382131SN/A
392239SN/A#include "arch/mips/faults.hh"
402680Sktlim@umich.edu#include "cpu/thread_context.hh"
412447SN/A#include "cpu/base.hh"
422447SN/A#include "base/trace.hh"
435222Sksewell@umich.edu#include "arch/mips/pra_constants.hh"
442800Ssaidi@eecs.umich.edu#if !FULL_SYSTEM
452800Ssaidi@eecs.umich.edu#include "sim/process.hh"
462800Ssaidi@eecs.umich.edu#include "mem/page_table.hh"
472800Ssaidi@eecs.umich.edu#endif
482131SN/A
492447SN/Anamespace MipsISA
502447SN/A{
512131SN/A
522479SN/AFaultName MachineCheckFault::_name = "Machine Check";
532447SN/AFaultVect MachineCheckFault::_vect = 0x0401;
542447SN/AFaultStat MachineCheckFault::_count;
552131SN/A
562479SN/AFaultName AlignmentFault::_name = "Alignment";
572447SN/AFaultVect AlignmentFault::_vect = 0x0301;
582447SN/AFaultStat AlignmentFault::_count;
592447SN/A
605224Sksewell@umich.eduFaultName ResetFault::_name = "Reset Fault";
615222Sksewell@umich.edu#if  FULL_SYSTEM
625222Sksewell@umich.eduFaultVect ResetFault::_vect = 0xBFC00000;
635222Sksewell@umich.edu#else
645222Sksewell@umich.eduFaultVect ResetFault::_vect = 0x001;
655222Sksewell@umich.edu#endif
662447SN/AFaultStat ResetFault::_count;
672447SN/A
685222Sksewell@umich.eduFaultName AddressErrorFault::_name = "Address Error";
695222Sksewell@umich.eduFaultVect AddressErrorFault::_vect = 0x0180;
705222Sksewell@umich.eduFaultStat AddressErrorFault::_count;
715222Sksewell@umich.edu
725222Sksewell@umich.eduFaultName StoreAddressErrorFault::_name = "Store Address Error";
735222Sksewell@umich.eduFaultVect StoreAddressErrorFault::_vect = 0x0180;
745222Sksewell@umich.eduFaultStat StoreAddressErrorFault::_count;
755222Sksewell@umich.edu
765222Sksewell@umich.edu
775222Sksewell@umich.eduFaultName SystemCallFault::_name = "Syscall";
785222Sksewell@umich.eduFaultVect SystemCallFault::_vect = 0x0180;
795222Sksewell@umich.eduFaultStat SystemCallFault::_count;
805222Sksewell@umich.edu
815224Sksewell@umich.eduFaultName CoprocessorUnusableFault::_name = "Coprocessor Unusable Fault";
825222Sksewell@umich.eduFaultVect CoprocessorUnusableFault::_vect = 0x180;
834661Sksewell@umich.eduFaultStat CoprocessorUnusableFault::_count;
844661Sksewell@umich.edu
855224Sksewell@umich.eduFaultName ReservedInstructionFault::_name = "Reserved Instruction Fault";
865222Sksewell@umich.eduFaultVect ReservedInstructionFault::_vect = 0x0180;
874661Sksewell@umich.eduFaultStat ReservedInstructionFault::_count;
884661Sksewell@umich.edu
895224Sksewell@umich.eduFaultName ThreadFault::_name = "Thread Fault";
904661Sksewell@umich.eduFaultVect ThreadFault::_vect = 0x00F1;
914661Sksewell@umich.eduFaultStat ThreadFault::_count;
924661Sksewell@umich.edu
934661Sksewell@umich.edu
945222Sksewell@umich.eduFaultName ArithmeticFault::_name = "Arithmetic Overflow Exception";
955222Sksewell@umich.eduFaultVect ArithmeticFault::_vect = 0x180;
962447SN/AFaultStat ArithmeticFault::_count;
972447SN/A
984661Sksewell@umich.eduFaultName UnimplementedOpcodeFault::_name = "opdec";
994661Sksewell@umich.eduFaultVect UnimplementedOpcodeFault::_vect = 0x0481;
1004661Sksewell@umich.eduFaultStat UnimplementedOpcodeFault::_count;
1014661Sksewell@umich.edu
1022447SN/AFaultName InterruptFault::_name = "interrupt";
1035222Sksewell@umich.eduFaultVect InterruptFault::_vect = 0x0180;
1042447SN/AFaultStat InterruptFault::_count;
1052447SN/A
1065222Sksewell@umich.eduFaultName TrapFault::_name = "Trap";
1075222Sksewell@umich.eduFaultVect TrapFault::_vect = 0x0180;
1085222Sksewell@umich.eduFaultStat TrapFault::_count;
1095222Sksewell@umich.edu
1105222Sksewell@umich.eduFaultName BreakpointFault::_name = "Breakpoint";
1115222Sksewell@umich.eduFaultVect BreakpointFault::_vect = 0x0180;
1125222Sksewell@umich.eduFaultStat BreakpointFault::_count;
1135222Sksewell@umich.edu
1145222Sksewell@umich.edu
1155222Sksewell@umich.eduFaultName ItbInvalidFault::_name = "Invalid TLB Entry Exception (I-Fetch/LW)";
1165222Sksewell@umich.eduFaultVect ItbInvalidFault::_vect = 0x0180;
1175222Sksewell@umich.eduFaultStat ItbInvalidFault::_count;
1185222Sksewell@umich.edu
1195222Sksewell@umich.eduFaultName ItbPageFault::_name = "itbmiss";
1205222Sksewell@umich.eduFaultVect ItbPageFault::_vect = 0x0181;
1215222Sksewell@umich.eduFaultStat ItbPageFault::_count;
1225222Sksewell@umich.edu
1235222Sksewell@umich.eduFaultName ItbMissFault::_name = "itbmiss";
1245222Sksewell@umich.eduFaultVect ItbMissFault::_vect = 0x0181;
1255222Sksewell@umich.eduFaultStat ItbMissFault::_count;
1265222Sksewell@umich.edu
1275222Sksewell@umich.eduFaultName ItbAcvFault::_name = "iaccvio";
1285222Sksewell@umich.eduFaultVect ItbAcvFault::_vect = 0x0081;
1295222Sksewell@umich.eduFaultStat ItbAcvFault::_count;
1305222Sksewell@umich.edu
1315222Sksewell@umich.eduFaultName ItbRefillFault::_name = "TLB Refill Exception (I-Fetch/LW)";
1325222Sksewell@umich.eduFaultVect ItbRefillFault::_vect = 0x0180;
1335222Sksewell@umich.eduFaultStat ItbRefillFault::_count;
1345222Sksewell@umich.edu
1352447SN/AFaultName NDtbMissFault::_name = "dtb_miss_single";
1362447SN/AFaultVect NDtbMissFault::_vect = 0x0201;
1372447SN/AFaultStat NDtbMissFault::_count;
1382447SN/A
1392447SN/AFaultName PDtbMissFault::_name = "dtb_miss_double";
1402447SN/AFaultVect PDtbMissFault::_vect = 0x0281;
1412447SN/AFaultStat PDtbMissFault::_count;
1422447SN/A
1432447SN/AFaultName DtbPageFault::_name = "dfault";
1442447SN/AFaultVect DtbPageFault::_vect = 0x0381;
1452447SN/AFaultStat DtbPageFault::_count;
1462447SN/A
1472447SN/AFaultName DtbAcvFault::_name = "dfault";
1482447SN/AFaultVect DtbAcvFault::_vect = 0x0381;
1492447SN/AFaultStat DtbAcvFault::_count;
1502447SN/A
1515222Sksewell@umich.eduFaultName DtbInvalidFault::_name = "Invalid TLB Entry Exception (Store)";
1525222Sksewell@umich.eduFaultVect DtbInvalidFault::_vect = 0x0180;
1535222Sksewell@umich.eduFaultStat DtbInvalidFault::_count;
1542447SN/A
1555222Sksewell@umich.eduFaultName DtbRefillFault::_name = "TLB Refill Exception (Store)";
1565222Sksewell@umich.eduFaultVect DtbRefillFault::_vect = 0x0180;
1575222Sksewell@umich.eduFaultStat DtbRefillFault::_count;
1582447SN/A
1595222Sksewell@umich.eduFaultName TLBModifiedFault::_name = "TLB Modified Exception";
1605222Sksewell@umich.eduFaultVect TLBModifiedFault::_vect = 0x0180;
1615222Sksewell@umich.eduFaultStat TLBModifiedFault::_count;
1622447SN/A
1635222Sksewell@umich.eduFaultName FloatEnableFault::_name = "float_enable_fault";
1642447SN/AFaultVect FloatEnableFault::_vect = 0x0581;
1652447SN/AFaultStat FloatEnableFault::_count;
1662447SN/A
1675222Sksewell@umich.eduFaultName IntegerOverflowFault::_name = "Integer Overflow Fault";
1682447SN/AFaultVect IntegerOverflowFault::_vect = 0x0501;
1692447SN/AFaultStat IntegerOverflowFault::_count;
1702447SN/A
1715222Sksewell@umich.eduFaultName DspStateDisabledFault::_name = "DSP Disabled Fault";
1724661Sksewell@umich.eduFaultVect DspStateDisabledFault::_vect = 0x001a;
1734661Sksewell@umich.eduFaultStat DspStateDisabledFault::_count;
1744661Sksewell@umich.edu
1755222Sksewell@umich.edu#if FULL_SYSTEM
1765222Sksewell@umich.eduvoid MipsFault::setHandlerPC(Addr HandlerBase, ThreadContext *tc)
1775222Sksewell@umich.edu{
1785222Sksewell@umich.edu  tc->setPC(HandlerBase);
1795222Sksewell@umich.edu  tc->setNextPC(HandlerBase+sizeof(MachInst));
1805222Sksewell@umich.edu  tc->setNextNPC(HandlerBase+2*sizeof(MachInst));
1815222Sksewell@umich.edu}
1825222Sksewell@umich.edu
1835222Sksewell@umich.eduvoid MipsFault::setExceptionState(ThreadContext *tc,uint8_t ExcCode)
1845222Sksewell@umich.edu{
1855222Sksewell@umich.edu  // modify SRS Ctl - Save CSS, put ESS into CSS
1865222Sksewell@umich.edu  MiscReg stat = tc->readMiscReg(MipsISA::Status);
1875222Sksewell@umich.edu  if(bits(stat,Status_EXL) != 1 && bits(stat,Status_BEV) != 1)
1885222Sksewell@umich.edu    {
1895222Sksewell@umich.edu      // SRS Ctl is modified only if Status_EXL and Status_BEV are not set
1905222Sksewell@umich.edu      MiscReg srs = tc->readMiscReg(MipsISA::SRSCtl);
1915222Sksewell@umich.edu      uint8_t CSS,ESS;
1925222Sksewell@umich.edu      CSS = bits(srs,SRSCtl_CSS_HI,SRSCtl_CSS_LO);
1935222Sksewell@umich.edu      ESS = bits(srs,SRSCtl_ESS_HI,SRSCtl_ESS_LO);
1945222Sksewell@umich.edu      // Move CSS to PSS
1955222Sksewell@umich.edu      replaceBits(srs,SRSCtl_PSS_HI,SRSCtl_PSS_LO,CSS);
1965222Sksewell@umich.edu      // Move ESS to CSS
1975222Sksewell@umich.edu      replaceBits(srs,SRSCtl_CSS_HI,SRSCtl_CSS_LO,ESS);
1985222Sksewell@umich.edu      tc->setMiscRegNoEffect(MipsISA::SRSCtl,srs);
1995250Sksewell@umich.edu      //tc->setShadowSet(ESS);
2005222Sksewell@umich.edu    }
2015222Sksewell@umich.edu
2025222Sksewell@umich.edu  // set EXL bit (don't care if it is already set!)
2035222Sksewell@umich.edu  replaceBits(stat,Status_EXL_HI,Status_EXL_LO,1);
2045222Sksewell@umich.edu  tc->setMiscRegNoEffect(MipsISA::Status,stat);
2055222Sksewell@umich.edu
2065222Sksewell@umich.edu  // write EPC
2075222Sksewell@umich.edu  //  warn("Set EPC to %x\n",tc->readPC());
2085222Sksewell@umich.edu  // CHECK ME  or FIXME or FIX ME or POSSIBLE HACK
2095222Sksewell@umich.edu  // Check to see if the exception occurred in the branch delay slot
2105222Sksewell@umich.edu  DPRINTF(MipsPRA,"PC: %x, NextPC: %x, NNPC: %x\n",tc->readPC(),tc->readNextPC(),tc->readNextNPC());
2115222Sksewell@umich.edu  int C_BD=0;
2125222Sksewell@umich.edu  if(tc->readPC() + sizeof(MachInst) != tc->readNextPC()){
2135222Sksewell@umich.edu    tc->setMiscRegNoEffect(MipsISA::EPC,tc->readPC()-sizeof(MachInst));
2145222Sksewell@umich.edu    // In the branch delay slot? set CAUSE_31
2155222Sksewell@umich.edu    C_BD = 1;
2165222Sksewell@umich.edu  } else {
2175222Sksewell@umich.edu    tc->setMiscRegNoEffect(MipsISA::EPC,tc->readPC());
2185222Sksewell@umich.edu    // In the branch delay slot? reset CAUSE_31
2195222Sksewell@umich.edu    C_BD = 0;
2205222Sksewell@umich.edu  }
2215222Sksewell@umich.edu
2225222Sksewell@umich.edu  // Set Cause_EXCCODE field
2235222Sksewell@umich.edu  MiscReg cause = tc->readMiscReg(MipsISA::Cause);
2245222Sksewell@umich.edu  replaceBits(cause,Cause_EXCCODE_HI,Cause_EXCCODE_LO,ExcCode);
2255222Sksewell@umich.edu  replaceBits(cause,Cause_BD_HI,Cause_BD_LO,C_BD);
2265222Sksewell@umich.edu  replaceBits(cause,Cause_CE_HI,Cause_CE_LO,0);
2275222Sksewell@umich.edu  tc->setMiscRegNoEffect(MipsISA::Cause,cause);
2285222Sksewell@umich.edu
2295222Sksewell@umich.edu}
2305222Sksewell@umich.edu
2315222Sksewell@umich.eduvoid ArithmeticFault::invoke(ThreadContext *tc)
2325222Sksewell@umich.edu{
2335222Sksewell@umich.edu  DPRINTF(MipsPRA,"%s encountered.\n", name());
2345222Sksewell@umich.edu  setExceptionState(tc,0xC);
2355222Sksewell@umich.edu
2365222Sksewell@umich.edu  // Set new PC
2375222Sksewell@umich.edu  Addr HandlerBase;
2385222Sksewell@umich.edu  MiscReg stat = tc->readMiscReg(MipsISA::Status);
2395222Sksewell@umich.edu  // Here, the handler is dependent on BEV, which is not modified by setExceptionState()
2405222Sksewell@umich.edu  if(bits(stat,Status_BEV)==0){ // See MIPS ARM Vol 3, Revision 2, Page 38
2415222Sksewell@umich.edu    HandlerBase= vect() + tc->readMiscReg(MipsISA::EBase);
2425222Sksewell@umich.edu  }else{
2435222Sksewell@umich.edu    HandlerBase = 0xBFC00200;
2445222Sksewell@umich.edu  }
2455222Sksewell@umich.edu  setHandlerPC(HandlerBase,tc);
2465222Sksewell@umich.edu  //      warn("Exception Handler At: %x \n",HandlerBase);
2475222Sksewell@umich.edu}
2485222Sksewell@umich.edu
2495222Sksewell@umich.eduvoid StoreAddressErrorFault::invoke(ThreadContext *tc)
2505222Sksewell@umich.edu{
2515222Sksewell@umich.edu  DPRINTF(MipsPRA,"%s encountered.\n", name());
2525222Sksewell@umich.edu  setExceptionState(tc,0x5);
2535222Sksewell@umich.edu  tc->setMiscRegNoEffect(MipsISA::BadVAddr,BadVAddr);
2545222Sksewell@umich.edu
2555222Sksewell@umich.edu  // Set new PC
2565222Sksewell@umich.edu  Addr HandlerBase;
2575222Sksewell@umich.edu  HandlerBase= vect() + tc->readMiscReg(MipsISA::EBase); // Offset 0x180 - General Exception Vector
2585222Sksewell@umich.edu  setHandlerPC(HandlerBase,tc);
2595222Sksewell@umich.edu  //      warn("Exception Handler At: %x \n",HandlerBase);
2605222Sksewell@umich.edu  //      warn("Exception Handler At: %x , EPC set to %x\n",HandlerBase,tc->readMiscReg(MipsISA::EPC));
2615222Sksewell@umich.edu
2625222Sksewell@umich.edu}
2635222Sksewell@umich.edu
2645222Sksewell@umich.eduvoid TrapFault::invoke(ThreadContext *tc)
2655222Sksewell@umich.edu{
2665222Sksewell@umich.edu  DPRINTF(MipsPRA,"%s encountered.\n", name());
2675222Sksewell@umich.edu  //  warn("%s encountered.\n", name());
2685222Sksewell@umich.edu  setExceptionState(tc,0xD);
2695222Sksewell@umich.edu
2705222Sksewell@umich.edu  // Set new PC
2715222Sksewell@umich.edu  Addr HandlerBase;
2725222Sksewell@umich.edu  HandlerBase= vect() + tc->readMiscReg(MipsISA::EBase); // Offset 0x180 - General Exception Vector
2735222Sksewell@umich.edu  setHandlerPC(HandlerBase,tc);
2745222Sksewell@umich.edu  //      warn("Exception Handler At: %x \n",HandlerBase);
2755222Sksewell@umich.edu  //      warn("Exception Handler At: %x , EPC set to %x\n",HandlerBase,tc->readMiscReg(MipsISA::EPC));
2765222Sksewell@umich.edu}
2775222Sksewell@umich.edu
2785222Sksewell@umich.eduvoid BreakpointFault::invoke(ThreadContext *tc)
2795222Sksewell@umich.edu{
2805222Sksewell@umich.edu      setExceptionState(tc,0x9);
2815222Sksewell@umich.edu
2825222Sksewell@umich.edu      // Set new PC
2835222Sksewell@umich.edu      Addr HandlerBase;
2845222Sksewell@umich.edu      HandlerBase= vect() + tc->readMiscReg(MipsISA::EBase); // Offset 0x180 - General Exception Vector
2855222Sksewell@umich.edu      setHandlerPC(HandlerBase,tc);
2865222Sksewell@umich.edu      //      warn("Exception Handler At: %x \n",HandlerBase);
2875222Sksewell@umich.edu      //      warn("Exception Handler At: %x , EPC set to %x\n",HandlerBase,tc->readMiscReg(MipsISA::EPC));
2885222Sksewell@umich.edu
2895222Sksewell@umich.edu}
2905222Sksewell@umich.edu
2915222Sksewell@umich.eduvoid DtbInvalidFault::invoke(ThreadContext *tc)
2925222Sksewell@umich.edu{
2935222Sksewell@umich.edu  DPRINTF(MipsPRA,"%s encountered.\n", name());
2945222Sksewell@umich.edu  //    warn("%s encountered.\n", name());
2955222Sksewell@umich.edu  tc->setMiscRegNoEffect(MipsISA::BadVAddr,BadVAddr);
2965222Sksewell@umich.edu  MiscReg eh = tc->readMiscReg(MipsISA::EntryHi);
2975222Sksewell@umich.edu  replaceBits(eh,EntryHi_ASID_HI,EntryHi_ASID_LO,EntryHi_Asid);
2985222Sksewell@umich.edu  replaceBits(eh,EntryHi_VPN2_HI,EntryHi_VPN2_LO,EntryHi_VPN2);
2995222Sksewell@umich.edu  replaceBits(eh,EntryHi_VPN2X_HI,EntryHi_VPN2X_LO,EntryHi_VPN2X);
3005222Sksewell@umich.edu  tc->setMiscRegNoEffect(MipsISA::EntryHi,eh);
3015222Sksewell@umich.edu  MiscReg ctxt = tc->readMiscReg(MipsISA::Context);
3025222Sksewell@umich.edu  replaceBits(ctxt,Context_BadVPN2_HI,Context_BadVPN2_LO,Context_BadVPN2);
3035222Sksewell@umich.edu  tc->setMiscRegNoEffect(MipsISA::Context,ctxt);
3045222Sksewell@umich.edu  setExceptionState(tc,0x3);
3055222Sksewell@umich.edu
3065222Sksewell@umich.edu
3075222Sksewell@umich.edu  // Set new PC
3085222Sksewell@umich.edu  Addr HandlerBase;
3095222Sksewell@umich.edu  HandlerBase= vect() + tc->readMiscReg(MipsISA::EBase); // Offset 0x180 - General Exception Vector
3105222Sksewell@umich.edu  setHandlerPC(HandlerBase,tc);
3115222Sksewell@umich.edu  //      warn("Exception Handler At: %x , EPC set to %x\n",HandlerBase,tc->readMiscReg(MipsISA::EPC));
3125222Sksewell@umich.edu}
3135222Sksewell@umich.edu
3145222Sksewell@umich.eduvoid AddressErrorFault::invoke(ThreadContext *tc)
3155222Sksewell@umich.edu{
3165222Sksewell@umich.edu  DPRINTF(MipsPRA,"%s encountered.\n", name());
3175222Sksewell@umich.edu      setExceptionState(tc,0x4);
3185222Sksewell@umich.edu      tc->setMiscRegNoEffect(MipsISA::BadVAddr,BadVAddr);
3195222Sksewell@umich.edu
3205222Sksewell@umich.edu      // Set new PC
3215222Sksewell@umich.edu      Addr HandlerBase;
3225222Sksewell@umich.edu      HandlerBase= vect() + tc->readMiscReg(MipsISA::EBase); // Offset 0x180 - General Exception Vector
3235222Sksewell@umich.edu      setHandlerPC(HandlerBase,tc);
3245222Sksewell@umich.edu}
3255222Sksewell@umich.edu
3265222Sksewell@umich.eduvoid ItbInvalidFault::invoke(ThreadContext *tc)
3275222Sksewell@umich.edu{
3285222Sksewell@umich.edu  DPRINTF(MipsPRA,"%s encountered.\n", name());
3295222Sksewell@umich.edu      setExceptionState(tc,0x2);
3305222Sksewell@umich.edu      tc->setMiscRegNoEffect(MipsISA::BadVAddr,BadVAddr);
3315222Sksewell@umich.edu      MiscReg eh = tc->readMiscReg(MipsISA::EntryHi);
3325222Sksewell@umich.edu      replaceBits(eh,EntryHi_ASID_HI,EntryHi_ASID_LO,EntryHi_Asid);
3335222Sksewell@umich.edu      replaceBits(eh,EntryHi_VPN2_HI,EntryHi_VPN2_LO,EntryHi_VPN2);
3345222Sksewell@umich.edu      replaceBits(eh,EntryHi_VPN2X_HI,EntryHi_VPN2X_LO,EntryHi_VPN2X);
3355222Sksewell@umich.edu      tc->setMiscRegNoEffect(MipsISA::EntryHi,eh);
3365222Sksewell@umich.edu      MiscReg ctxt = tc->readMiscReg(MipsISA::Context);
3375222Sksewell@umich.edu      replaceBits(ctxt,Context_BadVPN2_HI,Context_BadVPN2_LO,Context_BadVPN2);
3385222Sksewell@umich.edu      tc->setMiscRegNoEffect(MipsISA::Context,ctxt);
3395222Sksewell@umich.edu
3405222Sksewell@umich.edu
3415222Sksewell@umich.edu      // Set new PC
3425222Sksewell@umich.edu      Addr HandlerBase;
3435222Sksewell@umich.edu      HandlerBase= vect() + tc->readMiscReg(MipsISA::EBase); // Offset 0x180 - General Exception Vector
3445222Sksewell@umich.edu      setHandlerPC(HandlerBase,tc);
3455222Sksewell@umich.edu      DPRINTF(MipsPRA,"Exception Handler At: %x , EPC set to %x\n",HandlerBase,tc->readMiscReg(MipsISA::EPC));
3465222Sksewell@umich.edu}
3475222Sksewell@umich.edu
3485222Sksewell@umich.eduvoid ItbRefillFault::invoke(ThreadContext *tc)
3495222Sksewell@umich.edu{
3505222Sksewell@umich.edu  DPRINTF(MipsPRA,"%s encountered (%x).\n", name(),BadVAddr);
3515222Sksewell@umich.edu  Addr HandlerBase;
3525222Sksewell@umich.edu  tc->setMiscRegNoEffect(MipsISA::BadVAddr,BadVAddr);
3535222Sksewell@umich.edu  MiscReg eh = tc->readMiscReg(MipsISA::EntryHi);
3545222Sksewell@umich.edu  replaceBits(eh,EntryHi_ASID_HI,EntryHi_ASID_LO,EntryHi_Asid);
3555222Sksewell@umich.edu  replaceBits(eh,EntryHi_VPN2_HI,EntryHi_VPN2_LO,EntryHi_VPN2);
3565222Sksewell@umich.edu  replaceBits(eh,EntryHi_VPN2X_HI,EntryHi_VPN2X_LO,EntryHi_VPN2X);
3575222Sksewell@umich.edu  tc->setMiscRegNoEffect(MipsISA::EntryHi,eh);
3585222Sksewell@umich.edu  MiscReg ctxt = tc->readMiscReg(MipsISA::Context);
3595222Sksewell@umich.edu  replaceBits(ctxt,Context_BadVPN2_HI,Context_BadVPN2_LO,Context_BadVPN2);
3605222Sksewell@umich.edu  tc->setMiscRegNoEffect(MipsISA::Context,ctxt);
3615222Sksewell@umich.edu
3625222Sksewell@umich.edu  MiscReg stat = tc->readMiscReg(MipsISA::Status);
3635222Sksewell@umich.edu  // Since handler depends on EXL bit, must check EXL bit before setting it!!
3645222Sksewell@umich.edu  if(bits(stat,Status_EXL)==1){ // See MIPS ARM Vol 3, Revision 2, Page 38
3655222Sksewell@umich.edu    HandlerBase= vect() + tc->readMiscReg(MipsISA::EBase); // Offset 0x180 - General Exception Vector
3665222Sksewell@umich.edu  }else{
3675222Sksewell@umich.edu    HandlerBase = tc->readMiscReg(MipsISA::EBase); // Offset 0x000
3685222Sksewell@umich.edu  }
3695222Sksewell@umich.edu
3705222Sksewell@umich.edu  setExceptionState(tc,0x2);
3715222Sksewell@umich.edu  setHandlerPC(HandlerBase,tc);
3725222Sksewell@umich.edu}
3735222Sksewell@umich.edu
3745222Sksewell@umich.eduvoid DtbRefillFault::invoke(ThreadContext *tc)
3755222Sksewell@umich.edu{
3765222Sksewell@umich.edu  // Set new PC
3775222Sksewell@umich.edu  DPRINTF(MipsPRA,"%s encountered.\n", name());
3785222Sksewell@umich.edu  Addr HandlerBase;
3795222Sksewell@umich.edu  tc->setMiscRegNoEffect(MipsISA::BadVAddr,BadVAddr);
3805222Sksewell@umich.edu  MiscReg eh = tc->readMiscReg(MipsISA::EntryHi);
3815222Sksewell@umich.edu  replaceBits(eh,EntryHi_ASID_HI,EntryHi_ASID_LO,EntryHi_Asid);
3825222Sksewell@umich.edu  replaceBits(eh,EntryHi_VPN2_HI,EntryHi_VPN2_LO,EntryHi_VPN2);
3835222Sksewell@umich.edu  replaceBits(eh,EntryHi_VPN2X_HI,EntryHi_VPN2X_LO,EntryHi_VPN2X);
3845222Sksewell@umich.edu  tc->setMiscRegNoEffect(MipsISA::EntryHi,eh);
3855222Sksewell@umich.edu  MiscReg ctxt = tc->readMiscReg(MipsISA::Context);
3865222Sksewell@umich.edu  replaceBits(ctxt,Context_BadVPN2_HI,Context_BadVPN2_LO,Context_BadVPN2);
3875222Sksewell@umich.edu  tc->setMiscRegNoEffect(MipsISA::Context,ctxt);
3885222Sksewell@umich.edu
3895222Sksewell@umich.edu  MiscReg stat = tc->readMiscReg(MipsISA::Status);
3905222Sksewell@umich.edu  // Since handler depends on EXL bit, must check EXL bit before setting it!!
3915222Sksewell@umich.edu  if(bits(stat,Status_EXL)==1){ // See MIPS ARM Vol 3, Revision 2, Page 38
3925222Sksewell@umich.edu    HandlerBase= vect() + tc->readMiscReg(MipsISA::EBase); // Offset 0x180 - General Exception Vector
3935222Sksewell@umich.edu  }else{
3945222Sksewell@umich.edu    HandlerBase = tc->readMiscReg(MipsISA::EBase); // Offset 0x000
3955222Sksewell@umich.edu  }
3965222Sksewell@umich.edu
3975222Sksewell@umich.edu
3985222Sksewell@umich.edu  setExceptionState(tc,0x3);
3995222Sksewell@umich.edu
4005222Sksewell@umich.edu  setHandlerPC(HandlerBase,tc);
4015222Sksewell@umich.edu}
4025222Sksewell@umich.edu
4035222Sksewell@umich.eduvoid TLBModifiedFault::invoke(ThreadContext *tc)
4045222Sksewell@umich.edu{
4055222Sksewell@umich.edu  DPRINTF(MipsPRA,"%s encountered.\n", name());
4065222Sksewell@umich.edu  tc->setMiscRegNoEffect(MipsISA::BadVAddr,BadVAddr);
4075222Sksewell@umich.edu  MiscReg eh = tc->readMiscReg(MipsISA::EntryHi);
4085222Sksewell@umich.edu  replaceBits(eh,EntryHi_ASID_HI,EntryHi_ASID_LO,EntryHi_Asid);
4095222Sksewell@umich.edu  replaceBits(eh,EntryHi_VPN2_HI,EntryHi_VPN2_LO,EntryHi_VPN2);
4105222Sksewell@umich.edu  replaceBits(eh,EntryHi_VPN2X_HI,EntryHi_VPN2X_LO,EntryHi_VPN2X);
4115222Sksewell@umich.edu  tc->setMiscRegNoEffect(MipsISA::EntryHi,eh);
4125222Sksewell@umich.edu  MiscReg ctxt = tc->readMiscReg(MipsISA::Context);
4135222Sksewell@umich.edu  replaceBits(ctxt,Context_BadVPN2_HI,Context_BadVPN2_LO,Context_BadVPN2);
4145222Sksewell@umich.edu  tc->setMiscRegNoEffect(MipsISA::Context,ctxt);
4155222Sksewell@umich.edu
4165222Sksewell@umich.edu    // Set new PC
4175222Sksewell@umich.edu      Addr HandlerBase;
4185222Sksewell@umich.edu      HandlerBase= vect() + tc->readMiscReg(MipsISA::EBase); // Offset 0x180 - General Exception Vector
4195222Sksewell@umich.edu      setExceptionState(tc,0x1);
4205222Sksewell@umich.edu      setHandlerPC(HandlerBase,tc);
4215222Sksewell@umich.edu      //      warn("Exception Handler At: %x , EPC set to %x\n",HandlerBase,tc->readMiscReg(MipsISA::EPC));
4225222Sksewell@umich.edu
4235222Sksewell@umich.edu}
4245222Sksewell@umich.edu
4255222Sksewell@umich.eduvoid SystemCallFault::invoke(ThreadContext *tc)
4265222Sksewell@umich.edu{
4275222Sksewell@umich.edu  DPRINTF(MipsPRA,"%s encountered.\n", name());
4285222Sksewell@umich.edu      setExceptionState(tc,0x8);
4295222Sksewell@umich.edu
4305222Sksewell@umich.edu      // Set new PC
4315222Sksewell@umich.edu      Addr HandlerBase;
4325222Sksewell@umich.edu      HandlerBase= vect() + tc->readMiscReg(MipsISA::EBase); // Offset 0x180 - General Exception Vector
4335222Sksewell@umich.edu      setHandlerPC(HandlerBase,tc);
4345222Sksewell@umich.edu      //      warn("Exception Handler At: %x \n",HandlerBase);
4355222Sksewell@umich.edu      //      warn("Exception Handler At: %x , EPC set to %x\n",HandlerBase,tc->readMiscReg(MipsISA::EPC));
4365222Sksewell@umich.edu
4375222Sksewell@umich.edu}
4385222Sksewell@umich.edu
4395222Sksewell@umich.eduvoid InterruptFault::invoke(ThreadContext *tc)
4405222Sksewell@umich.edu{
4415222Sksewell@umich.edu#if  FULL_SYSTEM
4425222Sksewell@umich.edu  DPRINTF(MipsPRA,"%s encountered.\n", name());
4435222Sksewell@umich.edu  //RegFile *Reg = tc->getRegFilePtr(); // Get pointer to the register fil
4445222Sksewell@umich.edu  setExceptionState(tc,0x0A);
4455222Sksewell@umich.edu  Addr HandlerBase;
4465222Sksewell@umich.edu
4475222Sksewell@umich.edu
4485222Sksewell@umich.edu  uint8_t IV = bits(tc->readMiscRegNoEffect(MipsISA::Cause),Cause_IV);
4495222Sksewell@umich.edu  if (IV)// Offset 200 for release 2
4505222Sksewell@umich.edu      HandlerBase= 0x20 + vect() + tc->readMiscRegNoEffect(MipsISA::EBase);
4515222Sksewell@umich.edu  else//Ofset at 180 for release 1
4525222Sksewell@umich.edu      HandlerBase= vect() + tc->readMiscRegNoEffect(MipsISA::EBase);
4535222Sksewell@umich.edu
4545222Sksewell@umich.edu  setHandlerPC(HandlerBase,tc);
4555222Sksewell@umich.edu#endif
4565222Sksewell@umich.edu}
4575222Sksewell@umich.edu
4585222Sksewell@umich.edu#endif // FULL_SYSTEM
4595222Sksewell@umich.edu
4604661Sksewell@umich.eduvoid ResetFault::invoke(ThreadContext *tc)
4614661Sksewell@umich.edu{
4625224Sksewell@umich.edu#if FULL_SYSTEM
4635222Sksewell@umich.edu  DPRINTF(MipsPRA,"%s encountered.\n", name());
4645222Sksewell@umich.edu  /* All reset activity must be invoked from here */
4655222Sksewell@umich.edu  tc->setPC(vect());
4665222Sksewell@umich.edu  tc->setNextPC(vect()+sizeof(MachInst));
4675222Sksewell@umich.edu  tc->setNextNPC(vect()+sizeof(MachInst)+sizeof(MachInst));
4685222Sksewell@umich.edu  DPRINTF(MipsPRA,"(%x)  -  ResetFault::invoke : PC set to %x",(unsigned)tc,(unsigned)tc->readPC());
4695224Sksewell@umich.edu#endif
4705224Sksewell@umich.edu
4715224Sksewell@umich.edu  // Set Coprocessor 1 (Floating Point) To Usable
4725224Sksewell@umich.edu  tc->setMiscReg(MipsISA::Status, MipsISA::Status | 0x20000000);
4735222Sksewell@umich.edu}
4745222Sksewell@umich.edu
4755222Sksewell@umich.eduvoid ReservedInstructionFault::invoke(ThreadContext *tc)
4765222Sksewell@umich.edu{
4775222Sksewell@umich.edu#if  FULL_SYSTEM
4785222Sksewell@umich.edu  DPRINTF(MipsPRA,"%s encountered.\n", name());
4795222Sksewell@umich.edu  //RegFile *Reg = tc->getRegFilePtr(); // Get pointer to the register fil
4805222Sksewell@umich.edu  setExceptionState(tc,0x0A);
4815222Sksewell@umich.edu  Addr HandlerBase;
4825222Sksewell@umich.edu  HandlerBase= vect() + tc->readMiscRegNoEffect(MipsISA::EBase); // Offset 0x180 - General Exception Vector
4835222Sksewell@umich.edu  setHandlerPC(HandlerBase,tc);
4845222Sksewell@umich.edu#else
4855222Sksewell@umich.edu    panic("%s encountered.\n", name());
4865222Sksewell@umich.edu#endif
4875222Sksewell@umich.edu}
4885222Sksewell@umich.edu
4895222Sksewell@umich.eduvoid ThreadFault::invoke(ThreadContext *tc)
4905222Sksewell@umich.edu{
4915222Sksewell@umich.edu  DPRINTF(MipsPRA,"%s encountered.\n", name());
4925222Sksewell@umich.edu  panic("%s encountered.\n", name());
4935222Sksewell@umich.edu}
4945222Sksewell@umich.edu
4955222Sksewell@umich.eduvoid DspStateDisabledFault::invoke(ThreadContext *tc)
4965222Sksewell@umich.edu{
4975222Sksewell@umich.edu  DPRINTF(MipsPRA,"%s encountered.\n", name());
4985222Sksewell@umich.edu  panic("%s encountered.\n", name());
4994661Sksewell@umich.edu}
5004661Sksewell@umich.edu
5014661Sksewell@umich.eduvoid CoprocessorUnusableFault::invoke(ThreadContext *tc)
5024661Sksewell@umich.edu{
5035222Sksewell@umich.edu#if FULL_SYSTEM
5045222Sksewell@umich.edu  DPRINTF(MipsPRA,"%s encountered.\n", name());
5055222Sksewell@umich.edu  setExceptionState(tc,0xb);
5065222Sksewell@umich.edu  /* The ID of the coprocessor causing the exception is stored in CoprocessorUnusableFault::coProcID */
5075222Sksewell@umich.edu  MiscReg cause = tc->readMiscReg(MipsISA::Cause);
5085222Sksewell@umich.edu  replaceBits(cause,Cause_CE_HI,Cause_CE_LO,coProcID);
5095222Sksewell@umich.edu  tc->setMiscRegNoEffect(MipsISA::Cause,cause);
5104661Sksewell@umich.edu
5115222Sksewell@umich.edu  Addr HandlerBase;
5125222Sksewell@umich.edu  HandlerBase= vect() + tc->readMiscReg(MipsISA::EBase); // Offset 0x180 - General Exception Vector
5135222Sksewell@umich.edu  setHandlerPC(HandlerBase,tc);
5144661Sksewell@umich.edu
5155222Sksewell@umich.edu  //      warn("Status: %x, Cause: %x\n",tc->readMiscReg(MipsISA::Status),tc->readMiscReg(MipsISA::Cause));
5165222Sksewell@umich.edu#else
5175224Sksewell@umich.edu    warn("%s (CP%d) encountered.\n", name(), coProcID);
5185222Sksewell@umich.edu#endif
5194661Sksewell@umich.edu}
5204661Sksewell@umich.edu
5212447SN/A} // namespace MipsISA
5222447SN/A
523