faults.cc revision 8737
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 432800Ssaidi@eecs.umich.edu#if !FULL_SYSTEM 447676Snate@binkert.org#include "mem/page_table.hh" 452800Ssaidi@eecs.umich.edu#include "sim/process.hh" 462800Ssaidi@eecs.umich.edu#endif 472131SN/A 482447SN/Anamespace MipsISA 492447SN/A{ 502131SN/A 518566Sgblack@eecs.umich.edutypedef MipsFaultBase::FaultVals FaultVals; 522131SN/A 538578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<SystemCallFault>::vals = 548578Sgblack@eecs.umich.edu { "Syscall", 0x180, ExcCodeSys }; 558578Sgblack@eecs.umich.edu 568578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<ReservedInstructionFault>::vals = 578578Sgblack@eecs.umich.edu { "Reserved Instruction Fault", 0x180, ExcCodeRI }; 588578Sgblack@eecs.umich.edu 598578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<ThreadFault>::vals = 608578Sgblack@eecs.umich.edu { "Thread Fault", 0x180, ExcCodeDummy }; 618578Sgblack@eecs.umich.edu 628578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<IntegerOverflowFault>::vals = 638578Sgblack@eecs.umich.edu { "Integer Overflow Exception", 0x180, ExcCodeOv }; 648578Sgblack@eecs.umich.edu 658578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<TrapFault>::vals = 668578Sgblack@eecs.umich.edu { "Trap", 0x180, ExcCodeTr }; 678578Sgblack@eecs.umich.edu 688578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<BreakpointFault>::vals = 698578Sgblack@eecs.umich.edu { "Breakpoint", 0x180, ExcCodeBp }; 708578Sgblack@eecs.umich.edu 718578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<DspStateDisabledFault>::vals = 728578Sgblack@eecs.umich.edu { "DSP Disabled Fault", 0x180, ExcCodeDummy }; 738578Sgblack@eecs.umich.edu 748566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<MachineCheckFault>::vals = 758578Sgblack@eecs.umich.edu { "Machine Check", 0x180, ExcCodeMCheck }; 762447SN/A 778566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<ResetFault>::vals = 788578Sgblack@eecs.umich.edu { "Reset Fault", 0x000, ExcCodeDummy }; 798578Sgblack@eecs.umich.edu 808578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<SoftResetFault>::vals = 818578Sgblack@eecs.umich.edu { "Soft Reset Fault", 0x000, ExcCodeDummy }; 828578Sgblack@eecs.umich.edu 838578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<NonMaskableInterrupt>::vals = 848578Sgblack@eecs.umich.edu { "Non Maskable Interrupt", 0x000, ExcCodeDummy }; 858578Sgblack@eecs.umich.edu 868578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<CoprocessorUnusableFault>::vals = 878578Sgblack@eecs.umich.edu { "Coprocessor Unusable Fault", 0x180, ExcCodeCpU }; 888578Sgblack@eecs.umich.edu 898578Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<InterruptFault>::vals = 908578Sgblack@eecs.umich.edu { "Interrupt", 0x000, ExcCodeInt }; 912447SN/A 928566Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<AddressErrorFault>::vals = 938578Sgblack@eecs.umich.edu { "Address Error", 0x180, ExcCodeDummy }; 945222Sksewell@umich.edu 958573Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<TlbInvalidFault>::vals = 968578Sgblack@eecs.umich.edu { "Invalid TLB Entry Exception", 0x180, ExcCodeDummy }; 975222Sksewell@umich.edu 988573Sgblack@eecs.umich.edutemplate <> FaultVals MipsFault<TlbRefillFault>::vals = 998578Sgblack@eecs.umich.edu { "TLB Refill Exception", 0x180, ExcCodeDummy }; 1002447SN/A 1018737Skoansin.tan@gmail.comtemplate <> MipsFaultBase::FaultVals MipsFault<TlbModifiedFault>::vals = 1028578Sgblack@eecs.umich.edu { "TLB Modified Exception", 0x180, ExcCodeMod }; 1034661Sksewell@umich.edu 1046378Sgblack@eecs.umich.eduvoid 1058566Sgblack@eecs.umich.eduMipsFaultBase::setExceptionState(ThreadContext *tc, uint8_t excCode) 1065222Sksewell@umich.edu{ 1076378Sgblack@eecs.umich.edu // modify SRS Ctl - Save CSS, put ESS into CSS 1086383Sgblack@eecs.umich.edu StatusReg status = tc->readMiscReg(MISCREG_STATUS); 1096379Sgblack@eecs.umich.edu if (status.exl != 1 && status.bev != 1) { 1106378Sgblack@eecs.umich.edu // SRS Ctl is modified only if Status_EXL and Status_BEV are not set 1116383Sgblack@eecs.umich.edu SRSCtlReg srsCtl = tc->readMiscReg(MISCREG_SRSCTL); 1126379Sgblack@eecs.umich.edu srsCtl.pss = srsCtl.css; 1136379Sgblack@eecs.umich.edu srsCtl.css = srsCtl.ess; 1146383Sgblack@eecs.umich.edu tc->setMiscRegNoEffect(MISCREG_SRSCTL, srsCtl); 1155222Sksewell@umich.edu } 1165222Sksewell@umich.edu 1176378Sgblack@eecs.umich.edu // set EXL bit (don't care if it is already set!) 1186379Sgblack@eecs.umich.edu status.exl = 1; 1196383Sgblack@eecs.umich.edu tc->setMiscRegNoEffect(MISCREG_STATUS, status); 1205222Sksewell@umich.edu 1216378Sgblack@eecs.umich.edu // write EPC 1228574Sgblack@eecs.umich.edu PCState pc = tc->pcState(); 1238574Sgblack@eecs.umich.edu DPRINTF(MipsPRA, "PC: %s\n", pc); 1248574Sgblack@eecs.umich.edu bool delay_slot = pc.pc() + sizeof(MachInst) != pc.npc(); 1258574Sgblack@eecs.umich.edu tc->setMiscRegNoEffect(MISCREG_EPC, 1268696Sguodeyuan@tsinghua.org.cn pc.pc() - (delay_slot ? sizeof(MachInst) : 0)); 1275222Sksewell@umich.edu 1286378Sgblack@eecs.umich.edu // Set Cause_EXCCODE field 1296383Sgblack@eecs.umich.edu CauseReg cause = tc->readMiscReg(MISCREG_CAUSE); 1306379Sgblack@eecs.umich.edu cause.excCode = excCode; 1318574Sgblack@eecs.umich.edu cause.bd = delay_slot ? 1 : 0; 1326379Sgblack@eecs.umich.edu cause.ce = 0; 1336383Sgblack@eecs.umich.edu tc->setMiscRegNoEffect(MISCREG_CAUSE, cause); 1346378Sgblack@eecs.umich.edu} 1356378Sgblack@eecs.umich.edu 1366378Sgblack@eecs.umich.eduvoid 1378578Sgblack@eecs.umich.eduMipsFaultBase::invoke(ThreadContext *tc, StaticInstPtr inst) 1386378Sgblack@eecs.umich.edu{ 1398578Sgblack@eecs.umich.edu if (FULL_SYSTEM) { 1408578Sgblack@eecs.umich.edu DPRINTF(MipsPRA, "Fault %s encountered.\n", name()); 1418578Sgblack@eecs.umich.edu setExceptionState(tc, code()); 1428578Sgblack@eecs.umich.edu tc->pcState(vect(tc)); 1436378Sgblack@eecs.umich.edu } else { 1448578Sgblack@eecs.umich.edu panic("Fault %s encountered.\n", name()); 1456378Sgblack@eecs.umich.edu } 1466378Sgblack@eecs.umich.edu} 1476378Sgblack@eecs.umich.edu 1486378Sgblack@eecs.umich.eduvoid 1497678Sgblack@eecs.umich.eduResetFault::invoke(ThreadContext *tc, StaticInstPtr inst) 1504661Sksewell@umich.edu{ 1518578Sgblack@eecs.umich.edu if (FULL_SYSTEM) { 1528578Sgblack@eecs.umich.edu DPRINTF(MipsPRA, "%s encountered.\n", name()); 1538578Sgblack@eecs.umich.edu /* All reset activity must be invoked from here */ 1548578Sgblack@eecs.umich.edu Addr handler = vect(tc); 1558578Sgblack@eecs.umich.edu tc->pcState(handler); 1568578Sgblack@eecs.umich.edu DPRINTF(MipsPRA, "ResetFault::invoke : PC set to %x", handler); 1578578Sgblack@eecs.umich.edu } 1585224Sksewell@umich.edu 1596378Sgblack@eecs.umich.edu // Set Coprocessor 1 (Floating Point) To Usable 1606383Sgblack@eecs.umich.edu StatusReg status = tc->readMiscRegNoEffect(MISCREG_STATUS); 1616379Sgblack@eecs.umich.edu status.cu.cu1 = 1; 1626383Sgblack@eecs.umich.edu tc->setMiscReg(MISCREG_STATUS, status); 1635222Sksewell@umich.edu} 1645222Sksewell@umich.edu 1656378Sgblack@eecs.umich.eduvoid 1668578Sgblack@eecs.umich.eduSoftResetFault::invoke(ThreadContext *tc, StaticInstPtr inst) 1675222Sksewell@umich.edu{ 1688578Sgblack@eecs.umich.edu panic("Soft reset not implemented.\n"); 1695222Sksewell@umich.edu} 1705222Sksewell@umich.edu 1716378Sgblack@eecs.umich.eduvoid 1728578Sgblack@eecs.umich.eduNonMaskableInterrupt::invoke(ThreadContext *tc, StaticInstPtr inst) 1735222Sksewell@umich.edu{ 1748578Sgblack@eecs.umich.edu panic("Non maskable interrupt not implemented.\n"); 1754661Sksewell@umich.edu} 1764661Sksewell@umich.edu 1772447SN/A} // namespace MipsISA 1782447SN/A 179