faults.cc revision 10417
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
328696Sguodeyuan@tsinghua.org.cn *          Zhengxing Li
338696Sguodeyuan@tsinghua.org.cn *          Deyuan Guo
342131SN/A */
352131SN/A
362239SN/A#include "arch/mips/faults.hh"
377676Snate@binkert.org#include "arch/mips/pra_constants.hh"
387676Snate@binkert.org#include "base/trace.hh"
397676Snate@binkert.org#include "cpu/base.hh"
402680Sktlim@umich.edu#include "cpu/thread_context.hh"
418232Snate@binkert.org#include "debug/MipsPRA.hh"
427676Snate@binkert.org#include "mem/page_table.hh"
432800Ssaidi@eecs.umich.edu#include "sim/process.hh"
442131SN/A
452447SN/Anamespace MipsISA
462447SN/A{
472131SN/A
488566Sgblack@eecs.umich.edutypedef MipsFaultBase::FaultVals FaultVals;
492131SN/A
508578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<SystemCallFault>::vals =
518578Sgblack@eecs.umich.edu    { "Syscall", 0x180, ExcCodeSys };
528578Sgblack@eecs.umich.edu
538578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<ReservedInstructionFault>::vals =
548578Sgblack@eecs.umich.edu    { "Reserved Instruction Fault", 0x180, ExcCodeRI };
558578Sgblack@eecs.umich.edu
568578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<ThreadFault>::vals =
578578Sgblack@eecs.umich.edu    { "Thread Fault", 0x180, ExcCodeDummy };
588578Sgblack@eecs.umich.edu
598578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<IntegerOverflowFault>::vals =
608578Sgblack@eecs.umich.edu    { "Integer Overflow Exception", 0x180, ExcCodeOv };
618578Sgblack@eecs.umich.edu
628578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<TrapFault>::vals =
638578Sgblack@eecs.umich.edu    { "Trap", 0x180, ExcCodeTr };
648578Sgblack@eecs.umich.edu
658578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<BreakpointFault>::vals =
668578Sgblack@eecs.umich.edu    { "Breakpoint", 0x180, ExcCodeBp };
678578Sgblack@eecs.umich.edu
688578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<DspStateDisabledFault>::vals =
698578Sgblack@eecs.umich.edu    { "DSP Disabled Fault", 0x180, ExcCodeDummy };
708578Sgblack@eecs.umich.edu
718566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<MachineCheckFault>::vals =
728578Sgblack@eecs.umich.edu    { "Machine Check", 0x180, ExcCodeMCheck };
732447SN/A
748566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<ResetFault>::vals =
758578Sgblack@eecs.umich.edu    { "Reset Fault", 0x000, ExcCodeDummy };
768578Sgblack@eecs.umich.edu
778578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<SoftResetFault>::vals =
788578Sgblack@eecs.umich.edu    { "Soft Reset Fault", 0x000, ExcCodeDummy };
798578Sgblack@eecs.umich.edu
808578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<NonMaskableInterrupt>::vals =
818578Sgblack@eecs.umich.edu    { "Non Maskable Interrupt", 0x000, ExcCodeDummy };
828578Sgblack@eecs.umich.edu
838578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<CoprocessorUnusableFault>::vals =
848578Sgblack@eecs.umich.edu    { "Coprocessor Unusable Fault", 0x180, ExcCodeCpU };
858578Sgblack@eecs.umich.edu
868578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<InterruptFault>::vals =
878578Sgblack@eecs.umich.edu    { "Interrupt", 0x000, ExcCodeInt };
882447SN/A
898566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<AddressErrorFault>::vals =
908578Sgblack@eecs.umich.edu    { "Address Error", 0x180, ExcCodeDummy };
915222Sksewell@umich.edu
928573Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<TlbInvalidFault>::vals =
938578Sgblack@eecs.umich.edu    { "Invalid TLB Entry Exception", 0x180, ExcCodeDummy };
945222Sksewell@umich.edu
958573Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<TlbRefillFault>::vals =
968578Sgblack@eecs.umich.edu    { "TLB Refill Exception", 0x180, ExcCodeDummy };
972447SN/A
988737Skoansin.tan@gmail.comtemplate <> MipsFaultBase::FaultVals MipsFault<TlbModifiedFault>::vals =
998578Sgblack@eecs.umich.edu    { "TLB Modified Exception", 0x180, ExcCodeMod };
1004661Sksewell@umich.edu
1016378Sgblack@eecs.umich.eduvoid
1028566Sgblack@eecs.umich.eduMipsFaultBase::setExceptionState(ThreadContext *tc, uint8_t excCode)
1035222Sksewell@umich.edu{
1046378Sgblack@eecs.umich.edu    // modify SRS Ctl - Save CSS, put ESS into CSS
1056383Sgblack@eecs.umich.edu    StatusReg status = tc->readMiscReg(MISCREG_STATUS);
1066379Sgblack@eecs.umich.edu    if (status.exl != 1 && status.bev != 1) {
1076378Sgblack@eecs.umich.edu        // SRS Ctl is modified only if Status_EXL and Status_BEV are not set
1086383Sgblack@eecs.umich.edu        SRSCtlReg srsCtl = tc->readMiscReg(MISCREG_SRSCTL);
1096379Sgblack@eecs.umich.edu        srsCtl.pss = srsCtl.css;
1106379Sgblack@eecs.umich.edu        srsCtl.css = srsCtl.ess;
1116383Sgblack@eecs.umich.edu        tc->setMiscRegNoEffect(MISCREG_SRSCTL, srsCtl);
1125222Sksewell@umich.edu    }
1135222Sksewell@umich.edu
1146378Sgblack@eecs.umich.edu    // set EXL bit (don't care if it is already set!)
1156379Sgblack@eecs.umich.edu    status.exl = 1;
1166383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_STATUS, status);
1175222Sksewell@umich.edu
1186378Sgblack@eecs.umich.edu    // write EPC
1198574Sgblack@eecs.umich.edu    PCState pc = tc->pcState();
1208574Sgblack@eecs.umich.edu    DPRINTF(MipsPRA, "PC: %s\n", pc);
1218574Sgblack@eecs.umich.edu    bool delay_slot = pc.pc() + sizeof(MachInst) != pc.npc();
1228574Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_EPC,
1238696Sguodeyuan@tsinghua.org.cn            pc.pc() - (delay_slot ? sizeof(MachInst) : 0));
1245222Sksewell@umich.edu
1256378Sgblack@eecs.umich.edu    // Set Cause_EXCCODE field
1266383Sgblack@eecs.umich.edu    CauseReg cause = tc->readMiscReg(MISCREG_CAUSE);
1276379Sgblack@eecs.umich.edu    cause.excCode = excCode;
1288574Sgblack@eecs.umich.edu    cause.bd = delay_slot ? 1 : 0;
1296379Sgblack@eecs.umich.edu    cause.ce = 0;
1306383Sgblack@eecs.umich.edu    tc->setMiscRegNoEffect(MISCREG_CAUSE, cause);
1316378Sgblack@eecs.umich.edu}
1326378Sgblack@eecs.umich.edu
1336378Sgblack@eecs.umich.eduvoid
13410417Sandreas.hansson@arm.comMipsFaultBase::invoke(ThreadContext *tc, const StaticInstPtr &inst)
1356378Sgblack@eecs.umich.edu{
1368738Sgblack@eecs.umich.edu    if (FullSystem) {
1378578Sgblack@eecs.umich.edu        DPRINTF(MipsPRA, "Fault %s encountered.\n", name());
1388578Sgblack@eecs.umich.edu        setExceptionState(tc, code());
1398578Sgblack@eecs.umich.edu        tc->pcState(vect(tc));
1406378Sgblack@eecs.umich.edu    } else {
1418578Sgblack@eecs.umich.edu        panic("Fault %s encountered.\n", name());
1426378Sgblack@eecs.umich.edu    }
1436378Sgblack@eecs.umich.edu}
1446378Sgblack@eecs.umich.edu
1456378Sgblack@eecs.umich.eduvoid
14610417Sandreas.hansson@arm.comResetFault::invoke(ThreadContext *tc, const StaticInstPtr &inst)
1474661Sksewell@umich.edu{
1488738Sgblack@eecs.umich.edu    if (FullSystem) {
1498578Sgblack@eecs.umich.edu        DPRINTF(MipsPRA, "%s encountered.\n", name());
1508578Sgblack@eecs.umich.edu        /* All reset activity must be invoked from here */
1518578Sgblack@eecs.umich.edu        Addr handler = vect(tc);
1528578Sgblack@eecs.umich.edu        tc->pcState(handler);
1538578Sgblack@eecs.umich.edu        DPRINTF(MipsPRA, "ResetFault::invoke : PC set to %x", handler);
1548578Sgblack@eecs.umich.edu    }
1555224Sksewell@umich.edu
1566378Sgblack@eecs.umich.edu    // Set Coprocessor 1 (Floating Point) To Usable
1576383Sgblack@eecs.umich.edu    StatusReg status = tc->readMiscRegNoEffect(MISCREG_STATUS);
1586379Sgblack@eecs.umich.edu    status.cu.cu1 = 1;
1596383Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_STATUS, status);
1605222Sksewell@umich.edu}
1615222Sksewell@umich.edu
1626378Sgblack@eecs.umich.eduvoid
16310417Sandreas.hansson@arm.comSoftResetFault::invoke(ThreadContext *tc, const StaticInstPtr &inst)
1645222Sksewell@umich.edu{
1658578Sgblack@eecs.umich.edu    panic("Soft reset not implemented.\n");
1665222Sksewell@umich.edu}
1675222Sksewell@umich.edu
1686378Sgblack@eecs.umich.eduvoid
16910417Sandreas.hansson@arm.comNonMaskableInterrupt::invoke(ThreadContext *tc, const StaticInstPtr &inst)
1705222Sksewell@umich.edu{
1718578Sgblack@eecs.umich.edu    panic("Non maskable interrupt not implemented.\n");
1724661Sksewell@umich.edu}
1734661Sksewell@umich.edu
1742447SN/A} // namespace MipsISA
1752447SN/A
176