faults.cc revision 8570
12131SN/A/*
25268Sksewell@umich.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan
35254Sksewell@umich.edu * Copyright (c) 2007 MIPS Technologies, Inc.
45254Sksewell@umich.edu * All rights reserved.
52131SN/A *
65254Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without
75254Sksewell@umich.edu * modification, are permitted provided that the following conditions are
85254Sksewell@umich.edu * met: redistributions of source code must retain the above copyright
95254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer;
105254Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright
115254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the
125254Sksewell@umich.edu * documentation and/or other materials provided with the distribution;
135254Sksewell@umich.edu * neither the name of the copyright holders nor the names of its
145254Sksewell@umich.edu * contributors may be used to endorse or promote products derived from
155254Sksewell@umich.edu * this software without specific prior written permission.
162131SN/A *
175254Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
185254Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
195254Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
205254Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
215254Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
225254Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
235254Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
245254Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
255254Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
265254Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
275254Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu *
295254Sksewell@umich.edu * Authors: Gabe Black
305254Sksewell@umich.edu *          Korey Sewell
315222Sksewell@umich.edu *          Jaidev Patwardhan
322131SN/A */
332131SN/A
342239SN/A#include "arch/mips/faults.hh"
357676Snate@binkert.org#include "arch/mips/pra_constants.hh"
367676Snate@binkert.org#include "base/trace.hh"
377676Snate@binkert.org#include "cpu/base.hh"
382680Sktlim@umich.edu#include "cpu/thread_context.hh"
398232Snate@binkert.org#include "debug/MipsPRA.hh"
407676Snate@binkert.org
412800Ssaidi@eecs.umich.edu#if !FULL_SYSTEM
427676Snate@binkert.org#include "mem/page_table.hh"
432800Ssaidi@eecs.umich.edu#include "sim/process.hh"
442800Ssaidi@eecs.umich.edu#endif
452131SN/A
462447SN/Anamespace MipsISA
472447SN/A{
482131SN/A
498566Sgblack@eecs.umich.edutypedef MipsFaultBase::FaultVals FaultVals;
502131SN/A
518566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<MachineCheckFault>::vals =
528566Sgblack@eecs.umich.edu    { "Machine Check", 0x0401 };
532447SN/A
548566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<ResetFault>::vals =
555222Sksewell@umich.edu#if  FULL_SYSTEM
568566Sgblack@eecs.umich.edu    { "Reset Fault", 0xBFC00000};
575222Sksewell@umich.edu#else
588566Sgblack@eecs.umich.edu    { "Reset Fault", 0x001};
595222Sksewell@umich.edu#endif
602447SN/A
618566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<AddressErrorFault>::vals =
628566Sgblack@eecs.umich.edu    { "Address Error", 0x0180 };
635222Sksewell@umich.edu
648566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<SystemCallFault>::vals =
658566Sgblack@eecs.umich.edu    { "Syscall", 0x0180 };
665222Sksewell@umich.edu
678566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<CoprocessorUnusableFault>::vals =
688566Sgblack@eecs.umich.edu    { "Coprocessor Unusable Fault", 0x180 };
695222Sksewell@umich.edu
708566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<ReservedInstructionFault>::vals =
718566Sgblack@eecs.umich.edu    { "Reserved Instruction Fault", 0x0180 };
724661Sksewell@umich.edu
738566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<ThreadFault>::vals =
748566Sgblack@eecs.umich.edu    { "Thread Fault", 0x00F1 };
754661Sksewell@umich.edu
768568Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<IntegerOverflowFault>::vals =
778568Sgblack@eecs.umich.edu    { "Integer Overflow Exception", 0x180 };
782447SN/A
798566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<InterruptFault>::vals =
808566Sgblack@eecs.umich.edu    { "interrupt", 0x0180 };
814661Sksewell@umich.edu
828566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<TrapFault>::vals =
838566Sgblack@eecs.umich.edu    { "Trap", 0x0180 };
842447SN/A
858566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<BreakpointFault>::vals =
868566Sgblack@eecs.umich.edu    { "Breakpoint", 0x0180 };
875222Sksewell@umich.edu
888566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<ItbInvalidFault>::vals =
898566Sgblack@eecs.umich.edu    { "Invalid TLB Entry Exception (I-Fetch/LW)", 0x0180 };
905222Sksewell@umich.edu
918566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<ItbRefillFault>::vals =
928566Sgblack@eecs.umich.edu    { "TLB Refill Exception (I-Fetch/LW)", 0x0180 };
935222Sksewell@umich.edu
948566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<DtbInvalidFault>::vals =
958566Sgblack@eecs.umich.edu    { "Invalid TLB Entry Exception (Store)", 0x0180 };
962447SN/A
978566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<DtbRefillFault>::vals =
988566Sgblack@eecs.umich.edu    { "TLB Refill Exception (Store)", 0x0180 };
992447SN/A
1008566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<TLBModifiedFault>::vals =
1018566Sgblack@eecs.umich.edu    { "TLB Modified Exception", 0x0180 };
1022447SN/A
1038566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<DspStateDisabledFault>::vals =
1048566Sgblack@eecs.umich.edu    { "DSP Disabled Fault", 0x001a };
1054661Sksewell@umich.edu
1065222Sksewell@umich.edu#if FULL_SYSTEM
1076378Sgblack@eecs.umich.eduvoid
1088566Sgblack@eecs.umich.eduMipsFaultBase::setHandlerPC(Addr HandlerBase, ThreadContext *tc)
1095222Sksewell@umich.edu{
1106378Sgblack@eecs.umich.edu    tc->setPC(HandlerBase);
1116378Sgblack@eecs.umich.edu    tc->setNextPC(HandlerBase + sizeof(MachInst));
1126378Sgblack@eecs.umich.edu    tc->setNextNPC(HandlerBase + 2 * sizeof(MachInst));
1135222Sksewell@umich.edu}
1145222Sksewell@umich.edu
1156378Sgblack@eecs.umich.eduvoid
1168566Sgblack@eecs.umich.eduMipsFaultBase::setExceptionState(ThreadContext *tc, uint8_t excCode)
1175222Sksewell@umich.edu{
1186378Sgblack@eecs.umich.edu    // modify SRS Ctl - Save CSS, put ESS into CSS
1196383Sgblack@eecs.umich.edu    StatusReg status = tc->readMiscReg(MISCREG_STATUS);
1206379Sgblack@eecs.umich.edu    if (status.exl != 1 && status.bev != 1) {
1216378Sgblack@eecs.umich.edu        // SRS Ctl is modified only if Status_EXL and Status_BEV are not set
1226383Sgblack@eecs.umich.edu        SRSCtlReg srsCtl = tc->readMiscReg(MISCREG_SRSCTL);
1236379Sgblack@eecs.umich.edu        srsCtl.pss = srsCtl.css;
1246379Sgblack@eecs.umich.edu        srsCtl.css = srsCtl.ess;
1256383Sgblack@eecs.umich.edu        tc->setMiscRegNoEffect(MISCREG_SRSCTL, srsCtl);
1265222Sksewell@umich.edu    }
1275222Sksewell@umich.edu
1286378Sgblack@eecs.umich.edu    // set EXL bit (don't care if it is already set!)
1296379Sgblack@eecs.umich.edu    status.exl = 1;
1306383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_STATUS, status);
1315222Sksewell@umich.edu
1326378Sgblack@eecs.umich.edu    // write EPC
1336378Sgblack@eecs.umich.edu    // CHECK ME  or FIXME or FIX ME or POSSIBLE HACK
1346378Sgblack@eecs.umich.edu    // Check to see if the exception occurred in the branch delay slot
1356378Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "PC: %x, NextPC: %x, NNPC: %x\n",
1366378Sgblack@eecs.umich.edu            tc->readPC(), tc->readNextPC(), tc->readNextNPC());
1376379Sgblack@eecs.umich.edu    int bd = 0;
1386378Sgblack@eecs.umich.edu    if (tc->readPC() + sizeof(MachInst) != tc->readNextPC()) {
1396383Sgblack@eecs.umich.edu        tc->setMiscRegNoEffect(MISCREG_EPC, tc->readPC() - sizeof(MachInst));
1406378Sgblack@eecs.umich.edu        // In the branch delay slot? set CAUSE_31
1416379Sgblack@eecs.umich.edu        bd = 1;
1426378Sgblack@eecs.umich.edu    } else {
1436383Sgblack@eecs.umich.edu        tc->setMiscRegNoEffect(MISCREG_EPC, tc->readPC());
1446378Sgblack@eecs.umich.edu        // In the branch delay slot? reset CAUSE_31
1456379Sgblack@eecs.umich.edu        bd = 0;
1466378Sgblack@eecs.umich.edu    }
1475222Sksewell@umich.edu
1486378Sgblack@eecs.umich.edu    // Set Cause_EXCCODE field
1496383Sgblack@eecs.umich.edu    CauseReg cause = tc->readMiscReg(MISCREG_CAUSE);
1506379Sgblack@eecs.umich.edu    cause.excCode = excCode;
1516379Sgblack@eecs.umich.edu    cause.bd = bd;
1526379Sgblack@eecs.umich.edu    cause.ce = 0;
1536383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_CAUSE, cause);
1546378Sgblack@eecs.umich.edu}
1556378Sgblack@eecs.umich.edu
1566378Sgblack@eecs.umich.eduvoid
1578568Sgblack@eecs.umich.eduIntegerOverflowFault::invoke(ThreadContext *tc, StaticInstPtr inst)
1586378Sgblack@eecs.umich.edu{
1596378Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "%s encountered.\n", name());
1606378Sgblack@eecs.umich.edu    setExceptionState(tc, 0xC);
1616378Sgblack@eecs.umich.edu
1626378Sgblack@eecs.umich.edu    // Set new PC
1636378Sgblack@eecs.umich.edu    Addr HandlerBase;
1646383Sgblack@eecs.umich.edu    StatusReg status = tc->readMiscReg(MISCREG_STATUS);
1656378Sgblack@eecs.umich.edu    // Here, the handler is dependent on BEV, which is not modified by
1666378Sgblack@eecs.umich.edu    // setExceptionState()
1676379Sgblack@eecs.umich.edu    if (!status.bev) {
1686378Sgblack@eecs.umich.edu        // See MIPS ARM Vol 3, Revision 2, Page 38
1696383Sgblack@eecs.umich.edu        HandlerBase = vect() + tc->readMiscReg(MISCREG_EBASE);
1706378Sgblack@eecs.umich.edu    } else {
1716378Sgblack@eecs.umich.edu        HandlerBase = 0xBFC00200;
1726378Sgblack@eecs.umich.edu    }
1736378Sgblack@eecs.umich.edu    setHandlerPC(HandlerBase, tc);
1746378Sgblack@eecs.umich.edu}
1756378Sgblack@eecs.umich.edu
1766378Sgblack@eecs.umich.eduvoid
1777678Sgblack@eecs.umich.eduTrapFault::invoke(ThreadContext *tc, StaticInstPtr inst)
1786378Sgblack@eecs.umich.edu{
1796378Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "%s encountered.\n", name());
1806378Sgblack@eecs.umich.edu    setExceptionState(tc, 0xD);
1816378Sgblack@eecs.umich.edu
1826378Sgblack@eecs.umich.edu    // Set new PC
1836378Sgblack@eecs.umich.edu    Addr HandlerBase;
1846378Sgblack@eecs.umich.edu    // Offset 0x180 - General Exception Vector
1856383Sgblack@eecs.umich.edu    HandlerBase = vect() + tc->readMiscReg(MISCREG_EBASE);
1866378Sgblack@eecs.umich.edu    setHandlerPC(HandlerBase, tc);
1876378Sgblack@eecs.umich.edu}
1886378Sgblack@eecs.umich.edu
1896378Sgblack@eecs.umich.eduvoid
1907678Sgblack@eecs.umich.eduBreakpointFault::invoke(ThreadContext *tc, StaticInstPtr inst)
1916378Sgblack@eecs.umich.edu{
1926378Sgblack@eecs.umich.edu    setExceptionState(tc, 0x9);
1936378Sgblack@eecs.umich.edu
1946378Sgblack@eecs.umich.edu    // Set new PC
1956378Sgblack@eecs.umich.edu    Addr HandlerBase;
1966378Sgblack@eecs.umich.edu    // Offset 0x180 - General Exception Vector
1976383Sgblack@eecs.umich.edu    HandlerBase = vect() + tc->readMiscReg(MISCREG_EBASE);
1986378Sgblack@eecs.umich.edu    setHandlerPC(HandlerBase, tc);
1996378Sgblack@eecs.umich.edu}
2006378Sgblack@eecs.umich.edu
2016378Sgblack@eecs.umich.eduvoid
2027678Sgblack@eecs.umich.eduDtbInvalidFault::invoke(ThreadContext *tc, StaticInstPtr inst)
2036378Sgblack@eecs.umich.edu{
2046378Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "%s encountered.\n", name());
2056378Sgblack@eecs.umich.edu
2066383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_BADVADDR, badVAddr);
2076383Sgblack@eecs.umich.edu    EntryHiReg entryHi = tc->readMiscReg(MISCREG_ENTRYHI);
2086379Sgblack@eecs.umich.edu    entryHi.asid = entryHiAsid;
2096379Sgblack@eecs.umich.edu    entryHi.vpn2 = entryHiVPN2;
2106379Sgblack@eecs.umich.edu    entryHi.vpn2x = entryHiVPN2X;
2116383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_ENTRYHI, entryHi);
2126379Sgblack@eecs.umich.edu
2136383Sgblack@eecs.umich.edu    ContextReg context = tc->readMiscReg(MISCREG_CONTEXT);
2146379Sgblack@eecs.umich.edu    context.badVPN2 = contextBadVPN2;
2156383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_CONTEXT, context);
2166378Sgblack@eecs.umich.edu    setExceptionState(tc, 0x3);
2176378Sgblack@eecs.umich.edu
2186378Sgblack@eecs.umich.edu
2196378Sgblack@eecs.umich.edu    // Set new PC
2206378Sgblack@eecs.umich.edu    Addr HandlerBase;
2216378Sgblack@eecs.umich.edu    // Offset 0x180 - General Exception Vector
2226383Sgblack@eecs.umich.edu    HandlerBase = vect() + tc->readMiscReg(MISCREG_EBASE);
2236379Sgblack@eecs.umich.edu    setHandlerPC(HandlerBase, tc);
2246378Sgblack@eecs.umich.edu}
2256378Sgblack@eecs.umich.edu
2266378Sgblack@eecs.umich.eduvoid
2277678Sgblack@eecs.umich.eduAddressErrorFault::invoke(ThreadContext *tc, StaticInstPtr inst)
2286378Sgblack@eecs.umich.edu{
2296378Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "%s encountered.\n", name());
2308570Sgblack@eecs.umich.edu    setExceptionState(tc, store ? 0x5 : 0x4);
2318570Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_BADVADDR, vaddr);
2326378Sgblack@eecs.umich.edu
2336378Sgblack@eecs.umich.edu    // Set new PC
2346378Sgblack@eecs.umich.edu    Addr HandlerBase;
2356378Sgblack@eecs.umich.edu    // Offset 0x180 - General Exception Vector
2366383Sgblack@eecs.umich.edu    HandlerBase = vect() + tc->readMiscReg(MISCREG_EBASE);
2376378Sgblack@eecs.umich.edu    setHandlerPC(HandlerBase, tc);
2386378Sgblack@eecs.umich.edu}
2396378Sgblack@eecs.umich.edu
2406378Sgblack@eecs.umich.eduvoid
2417678Sgblack@eecs.umich.eduItbInvalidFault::invoke(ThreadContext *tc, StaticInstPtr inst)
2426378Sgblack@eecs.umich.edu{
2436378Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "%s encountered.\n", name());
2446378Sgblack@eecs.umich.edu    setExceptionState(tc, 0x2);
2456383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_BADVADDR, badVAddr);
2466383Sgblack@eecs.umich.edu    EntryHiReg entryHi = tc->readMiscReg(MISCREG_ENTRYHI);
2476379Sgblack@eecs.umich.edu    entryHi.asid = entryHiAsid;
2486379Sgblack@eecs.umich.edu    entryHi.vpn2 = entryHiVPN2;
2496379Sgblack@eecs.umich.edu    entryHi.vpn2x = entryHiVPN2X;
2506383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_ENTRYHI, entryHi);
2516379Sgblack@eecs.umich.edu
2526383Sgblack@eecs.umich.edu    ContextReg context = tc->readMiscReg(MISCREG_CONTEXT);
2536379Sgblack@eecs.umich.edu    context.badVPN2 = contextBadVPN2;
2546383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_CONTEXT, context);
2556378Sgblack@eecs.umich.edu
2566378Sgblack@eecs.umich.edu
2576378Sgblack@eecs.umich.edu    // Set new PC
2586378Sgblack@eecs.umich.edu    Addr HandlerBase;
2596378Sgblack@eecs.umich.edu    // Offset 0x180 - General Exception Vector
2606383Sgblack@eecs.umich.edu    HandlerBase = vect() + tc->readMiscReg(MISCREG_EBASE);
2616378Sgblack@eecs.umich.edu    setHandlerPC(HandlerBase,tc);
2626379Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "Exception Handler At: %x , EPC set to %x\n",
2636383Sgblack@eecs.umich.edu            HandlerBase, tc->readMiscReg(MISCREG_EPC));
2646378Sgblack@eecs.umich.edu}
2656378Sgblack@eecs.umich.edu
2666378Sgblack@eecs.umich.eduvoid
2677678Sgblack@eecs.umich.eduItbRefillFault::invoke(ThreadContext *tc, StaticInstPtr inst)
2686378Sgblack@eecs.umich.edu{
2696383Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "%s encountered (%x).\n", name(), MISCREG_BADVADDR);
2706378Sgblack@eecs.umich.edu    Addr HandlerBase;
2716383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_BADVADDR, badVAddr);
2726383Sgblack@eecs.umich.edu    EntryHiReg entryHi = tc->readMiscReg(MISCREG_ENTRYHI);
2736379Sgblack@eecs.umich.edu    entryHi.asid = entryHiAsid;
2746379Sgblack@eecs.umich.edu    entryHi.vpn2 = entryHiVPN2;
2756379Sgblack@eecs.umich.edu    entryHi.vpn2x = entryHiVPN2X;
2766383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_ENTRYHI, entryHi);
2776383Sgblack@eecs.umich.edu    ContextReg context = tc->readMiscReg(MISCREG_CONTEXT);
2786379Sgblack@eecs.umich.edu    context.badVPN2 = contextBadVPN2;
2796383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_CONTEXT, context);
2806378Sgblack@eecs.umich.edu
2816383Sgblack@eecs.umich.edu    StatusReg status = tc->readMiscReg(MISCREG_STATUS);
2826378Sgblack@eecs.umich.edu    // Since handler depends on EXL bit, must check EXL bit before setting it!!
2836378Sgblack@eecs.umich.edu    // See MIPS ARM Vol 3, Revision 2, Page 38
2846379Sgblack@eecs.umich.edu    if (status.exl == 1) {
2856378Sgblack@eecs.umich.edu        // Offset 0x180 - General Exception Vector
2866383Sgblack@eecs.umich.edu        HandlerBase = vect() + tc->readMiscReg(MISCREG_EBASE);
2876378Sgblack@eecs.umich.edu    } else {
2886378Sgblack@eecs.umich.edu        // Offset 0x000
2896383Sgblack@eecs.umich.edu        HandlerBase = tc->readMiscReg(MISCREG_EBASE);
2906378Sgblack@eecs.umich.edu    }
2916378Sgblack@eecs.umich.edu
2926378Sgblack@eecs.umich.edu    setExceptionState(tc, 0x2);
2936378Sgblack@eecs.umich.edu    setHandlerPC(HandlerBase, tc);
2946378Sgblack@eecs.umich.edu}
2956378Sgblack@eecs.umich.edu
2966378Sgblack@eecs.umich.eduvoid
2977678Sgblack@eecs.umich.eduDtbRefillFault::invoke(ThreadContext *tc, StaticInstPtr inst)
2986378Sgblack@eecs.umich.edu{
2996378Sgblack@eecs.umich.edu    // Set new PC
3006378Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "%s encountered.\n", name());
3016378Sgblack@eecs.umich.edu    Addr HandlerBase;
3026383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_BADVADDR, badVAddr);
3036383Sgblack@eecs.umich.edu    EntryHiReg entryHi = tc->readMiscReg(MISCREG_ENTRYHI);
3046379Sgblack@eecs.umich.edu    entryHi.asid = entryHiAsid;
3056379Sgblack@eecs.umich.edu    entryHi.vpn2 = entryHiVPN2;
3066379Sgblack@eecs.umich.edu    entryHi.vpn2x = entryHiVPN2X;
3076383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_ENTRYHI, entryHi);
3086378Sgblack@eecs.umich.edu
3096383Sgblack@eecs.umich.edu    ContextReg context = tc->readMiscReg(MISCREG_CONTEXT);
3106379Sgblack@eecs.umich.edu    context.badVPN2 = contextBadVPN2;
3116383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_CONTEXT, context);
3126379Sgblack@eecs.umich.edu
3136383Sgblack@eecs.umich.edu    StatusReg status = tc->readMiscReg(MISCREG_STATUS);
3146378Sgblack@eecs.umich.edu    // Since handler depends on EXL bit, must check EXL bit before setting it!!
3156378Sgblack@eecs.umich.edu    // See MIPS ARM Vol 3, Revision 2, Page 38
3166379Sgblack@eecs.umich.edu    if (status.exl) {
3176378Sgblack@eecs.umich.edu        // Offset 0x180 - General Exception Vector
3186383Sgblack@eecs.umich.edu        HandlerBase = vect() + tc->readMiscReg(MISCREG_EBASE);
3196378Sgblack@eecs.umich.edu    } else {
3206378Sgblack@eecs.umich.edu        // Offset 0x000
3216383Sgblack@eecs.umich.edu        HandlerBase = tc->readMiscReg(MISCREG_EBASE);
3226378Sgblack@eecs.umich.edu    }
3236378Sgblack@eecs.umich.edu
3246378Sgblack@eecs.umich.edu    setExceptionState(tc, 0x3);
3256378Sgblack@eecs.umich.edu
3266378Sgblack@eecs.umich.edu    setHandlerPC(HandlerBase, tc);
3276378Sgblack@eecs.umich.edu}
3286378Sgblack@eecs.umich.edu
3296378Sgblack@eecs.umich.eduvoid
3307678Sgblack@eecs.umich.eduTLBModifiedFault::invoke(ThreadContext *tc, StaticInstPtr inst)
3316378Sgblack@eecs.umich.edu{
3326378Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "%s encountered.\n", name());
3336383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_BADVADDR, badVAddr);
3346383Sgblack@eecs.umich.edu    EntryHiReg entryHi = tc->readMiscReg(MISCREG_ENTRYHI);
3356379Sgblack@eecs.umich.edu    entryHi.asid = entryHiAsid;
3366379Sgblack@eecs.umich.edu    entryHi.vpn2 = entryHiVPN2;
3376379Sgblack@eecs.umich.edu    entryHi.vpn2x = entryHiVPN2X;
3386383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_ENTRYHI, entryHi);
3396379Sgblack@eecs.umich.edu
3406383Sgblack@eecs.umich.edu    ContextReg context = tc->readMiscReg(MISCREG_CONTEXT);
3416379Sgblack@eecs.umich.edu    context.badVPN2 = contextBadVPN2;
3426383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_CONTEXT, context);
3436378Sgblack@eecs.umich.edu
3446378Sgblack@eecs.umich.edu    // Set new PC
3456378Sgblack@eecs.umich.edu    Addr HandlerBase;
3466378Sgblack@eecs.umich.edu    // Offset 0x180 - General Exception Vector
3476383Sgblack@eecs.umich.edu    HandlerBase = vect() + tc->readMiscReg(MISCREG_EBASE);
3486378Sgblack@eecs.umich.edu    setExceptionState(tc, 0x1);
3496378Sgblack@eecs.umich.edu    setHandlerPC(HandlerBase, tc);
3505222Sksewell@umich.edu
3515222Sksewell@umich.edu}
3525222Sksewell@umich.edu
3536378Sgblack@eecs.umich.eduvoid
3547678Sgblack@eecs.umich.eduSystemCallFault::invoke(ThreadContext *tc, StaticInstPtr inst)
3555222Sksewell@umich.edu{
3566378Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "%s encountered.\n", name());
3576378Sgblack@eecs.umich.edu    setExceptionState(tc, 0x8);
3585222Sksewell@umich.edu
3596378Sgblack@eecs.umich.edu    // Set new PC
3606378Sgblack@eecs.umich.edu    Addr HandlerBase;
3616378Sgblack@eecs.umich.edu    // Offset 0x180 - General Exception Vector
3626383Sgblack@eecs.umich.edu    HandlerBase = vect() + tc->readMiscReg(MISCREG_EBASE);
3636378Sgblack@eecs.umich.edu    setHandlerPC(HandlerBase, tc);
3645222Sksewell@umich.edu}
3655222Sksewell@umich.edu
3666378Sgblack@eecs.umich.eduvoid
3677678Sgblack@eecs.umich.eduInterruptFault::invoke(ThreadContext *tc, StaticInstPtr inst)
3685222Sksewell@umich.edu{
3695222Sksewell@umich.edu#if  FULL_SYSTEM
3706378Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "%s encountered.\n", name());
3716378Sgblack@eecs.umich.edu    setExceptionState(tc, 0x0A);
3726378Sgblack@eecs.umich.edu    Addr HandlerBase;
3735222Sksewell@umich.edu
3746383Sgblack@eecs.umich.edu    CauseReg cause = tc->readMiscRegNoEffect(MISCREG_CAUSE);
3756379Sgblack@eecs.umich.edu    if (cause.iv) {
3766378Sgblack@eecs.umich.edu        // Offset 200 for release 2
3776383Sgblack@eecs.umich.edu        HandlerBase = 0x20 + vect() + tc->readMiscRegNoEffect(MISCREG_EBASE);
3786378Sgblack@eecs.umich.edu    } else {
3796378Sgblack@eecs.umich.edu        //Ofset at 180 for release 1
3806383Sgblack@eecs.umich.edu        HandlerBase = vect() + tc->readMiscRegNoEffect(MISCREG_EBASE);
3816378Sgblack@eecs.umich.edu    }
3825222Sksewell@umich.edu
3836378Sgblack@eecs.umich.edu    setHandlerPC(HandlerBase, tc);
3845222Sksewell@umich.edu#endif
3855222Sksewell@umich.edu}
3865222Sksewell@umich.edu
3875222Sksewell@umich.edu#endif // FULL_SYSTEM
3885222Sksewell@umich.edu
3896378Sgblack@eecs.umich.eduvoid
3907678Sgblack@eecs.umich.eduResetFault::invoke(ThreadContext *tc, StaticInstPtr inst)
3914661Sksewell@umich.edu{
3925224Sksewell@umich.edu#if FULL_SYSTEM
3936378Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "%s encountered.\n", name());
3946378Sgblack@eecs.umich.edu    /* All reset activity must be invoked from here */
3956378Sgblack@eecs.umich.edu    tc->setPC(vect());
3966378Sgblack@eecs.umich.edu    tc->setNextPC(vect() + sizeof(MachInst));
3976378Sgblack@eecs.umich.edu    tc->setNextNPC(vect() + sizeof(MachInst) + sizeof(MachInst));
3986379Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "ResetFault::invoke : PC set to %x", tc->readPC());
3995224Sksewell@umich.edu#endif
4005224Sksewell@umich.edu
4016378Sgblack@eecs.umich.edu    // Set Coprocessor 1 (Floating Point) To Usable
4026383Sgblack@eecs.umich.edu    StatusReg status = tc->readMiscRegNoEffect(MISCREG_STATUS);
4036379Sgblack@eecs.umich.edu    status.cu.cu1 = 1;
4046383Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_STATUS, status);
4055222Sksewell@umich.edu}
4065222Sksewell@umich.edu
4076378Sgblack@eecs.umich.eduvoid
4087678Sgblack@eecs.umich.eduReservedInstructionFault::invoke(ThreadContext *tc, StaticInstPtr inst)
4095222Sksewell@umich.edu{
4105222Sksewell@umich.edu#if  FULL_SYSTEM
4116378Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "%s encountered.\n", name());
4126378Sgblack@eecs.umich.edu    setExceptionState(tc, 0x0A);
4136378Sgblack@eecs.umich.edu    Addr HandlerBase;
4146378Sgblack@eecs.umich.edu    // Offset 0x180 - General Exception Vector
4156383Sgblack@eecs.umich.edu    HandlerBase = vect() + tc->readMiscRegNoEffect(MISCREG_EBASE);
4166378Sgblack@eecs.umich.edu    setHandlerPC(HandlerBase, tc);
4175222Sksewell@umich.edu#else
4185222Sksewell@umich.edu    panic("%s encountered.\n", name());
4195222Sksewell@umich.edu#endif
4205222Sksewell@umich.edu}
4215222Sksewell@umich.edu
4226378Sgblack@eecs.umich.eduvoid
4237678Sgblack@eecs.umich.eduThreadFault::invoke(ThreadContext *tc, StaticInstPtr inst)
4245222Sksewell@umich.edu{
4256378Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "%s encountered.\n", name());
4266378Sgblack@eecs.umich.edu    panic("%s encountered.\n", name());
4275222Sksewell@umich.edu}
4285222Sksewell@umich.edu
4296378Sgblack@eecs.umich.eduvoid
4307678Sgblack@eecs.umich.eduDspStateDisabledFault::invoke(ThreadContext *tc, StaticInstPtr inst)
4315222Sksewell@umich.edu{
4326378Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "%s encountered.\n", name());
4336378Sgblack@eecs.umich.edu    panic("%s encountered.\n", name());
4344661Sksewell@umich.edu}
4354661Sksewell@umich.edu
4366378Sgblack@eecs.umich.eduvoid
4377678Sgblack@eecs.umich.eduCoprocessorUnusableFault::invoke(ThreadContext *tc, StaticInstPtr inst)
4384661Sksewell@umich.edu{
4395222Sksewell@umich.edu#if FULL_SYSTEM
4406378Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "%s encountered.\n", name());
4416378Sgblack@eecs.umich.edu    setExceptionState(tc, 0xb);
4426378Sgblack@eecs.umich.edu    // The ID of the coprocessor causing the exception is stored in
4436378Sgblack@eecs.umich.edu    // CoprocessorUnusableFault::coProcID
4446383Sgblack@eecs.umich.edu    CauseReg cause = tc->readMiscReg(MISCREG_CAUSE);
4456379Sgblack@eecs.umich.edu    cause.ce = coProcID;
4466383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_CAUSE, cause);
4474661Sksewell@umich.edu
4486378Sgblack@eecs.umich.edu    Addr HandlerBase;
4496378Sgblack@eecs.umich.edu    // Offset 0x180 - General Exception Vector
4506383Sgblack@eecs.umich.edu    HandlerBase = vect() + tc->readMiscReg(MISCREG_EBASE);
4516378Sgblack@eecs.umich.edu    setHandlerPC(HandlerBase, tc);
4524661Sksewell@umich.edu
4535222Sksewell@umich.edu#else
4545224Sksewell@umich.edu    warn("%s (CP%d) encountered.\n", name(), coProcID);
4555222Sksewell@umich.edu#endif
4564661Sksewell@umich.edu}
4574661Sksewell@umich.edu
4582447SN/A} // namespace MipsISA
4592447SN/A
460