faults.cc revision 8829
16019Shines@cs.fsu.edu/*
27093Sgblack@eecs.umich.edu * Copyright (c) 2010 ARM Limited
37093Sgblack@eecs.umich.edu * All rights reserved
47093Sgblack@eecs.umich.edu *
57093Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall
67093Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual
77093Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating
87093Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software
97093Sgblack@eecs.umich.edu * licensed hereunder.  You may use the software subject to the license
107093Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated
117093Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software,
127093Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form.
137093Sgblack@eecs.umich.edu *
146019Shines@cs.fsu.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan
156019Shines@cs.fsu.edu * Copyright (c) 2007-2008 The Florida State University
166019Shines@cs.fsu.edu * All rights reserved.
176019Shines@cs.fsu.edu *
186019Shines@cs.fsu.edu * Redistribution and use in source and binary forms, with or without
196019Shines@cs.fsu.edu * modification, are permitted provided that the following conditions are
206019Shines@cs.fsu.edu * met: redistributions of source code must retain the above copyright
216019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer;
226019Shines@cs.fsu.edu * redistributions in binary form must reproduce the above copyright
236019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer in the
246019Shines@cs.fsu.edu * documentation and/or other materials provided with the distribution;
256019Shines@cs.fsu.edu * neither the name of the copyright holders nor the names of its
266019Shines@cs.fsu.edu * contributors may be used to endorse or promote products derived from
276019Shines@cs.fsu.edu * this software without specific prior written permission.
286019Shines@cs.fsu.edu *
296019Shines@cs.fsu.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
306019Shines@cs.fsu.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
316019Shines@cs.fsu.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
326019Shines@cs.fsu.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
336019Shines@cs.fsu.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
346019Shines@cs.fsu.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
356019Shines@cs.fsu.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
366019Shines@cs.fsu.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
376019Shines@cs.fsu.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
386019Shines@cs.fsu.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
396019Shines@cs.fsu.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
406019Shines@cs.fsu.edu *
416735Sgblack@eecs.umich.edu * Authors: Ali Saidi
426735Sgblack@eecs.umich.edu *          Gabe Black
436019Shines@cs.fsu.edu */
446019Shines@cs.fsu.edu
456019Shines@cs.fsu.edu#include "arch/arm/faults.hh"
468229Snate@binkert.org#include "base/trace.hh"
478229Snate@binkert.org#include "cpu/base.hh"
486019Shines@cs.fsu.edu#include "cpu/thread_context.hh"
498232Snate@binkert.org#include "debug/Faults.hh"
508782Sgblack@eecs.umich.edu#include "sim/full_system.hh"
516019Shines@cs.fsu.edu
526019Shines@cs.fsu.edunamespace ArmISA
536019Shines@cs.fsu.edu{
546019Shines@cs.fsu.edu
557362Sgblack@eecs.umich.edutemplate<> ArmFault::FaultVals ArmFaultVals<Reset>::vals =
566735Sgblack@eecs.umich.edu    {"reset", 0x00, MODE_SVC, 0, 0, true, true};
576019Shines@cs.fsu.edu
587362Sgblack@eecs.umich.edutemplate<> ArmFault::FaultVals ArmFaultVals<UndefinedInstruction>::vals =
596735Sgblack@eecs.umich.edu    {"Undefined Instruction", 0x04, MODE_UNDEFINED, 4 ,2, false, false} ;
606019Shines@cs.fsu.edu
617362Sgblack@eecs.umich.edutemplate<> ArmFault::FaultVals ArmFaultVals<SupervisorCall>::vals =
626735Sgblack@eecs.umich.edu    {"Supervisor Call", 0x08, MODE_SVC, 4, 2, false, false};
636019Shines@cs.fsu.edu
647362Sgblack@eecs.umich.edutemplate<> ArmFault::FaultVals ArmFaultVals<PrefetchAbort>::vals =
656735Sgblack@eecs.umich.edu    {"Prefetch Abort", 0x0C, MODE_ABORT, 4, 4, true, false};
666019Shines@cs.fsu.edu
677362Sgblack@eecs.umich.edutemplate<> ArmFault::FaultVals ArmFaultVals<DataAbort>::vals =
686735Sgblack@eecs.umich.edu    {"Data Abort", 0x10, MODE_ABORT, 8, 8, true, false};
696019Shines@cs.fsu.edu
707362Sgblack@eecs.umich.edutemplate<> ArmFault::FaultVals ArmFaultVals<Interrupt>::vals =
716735Sgblack@eecs.umich.edu    {"IRQ", 0x18, MODE_IRQ, 4, 4, true, false};
726019Shines@cs.fsu.edu
737362Sgblack@eecs.umich.edutemplate<> ArmFault::FaultVals ArmFaultVals<FastInterrupt>::vals =
746735Sgblack@eecs.umich.edu    {"FIQ", 0x1C, MODE_FIQ, 4, 4, true, true};
756019Shines@cs.fsu.edu
767652Sminkyu.jeong@arm.comtemplate<> ArmFault::FaultVals ArmFaultVals<FlushPipe>::vals =
777652Sminkyu.jeong@arm.com    {"Pipe Flush", 0x00, MODE_SVC, 0, 0, true, true}; // some dummy values
787652Sminkyu.jeong@arm.com
798518Sgeoffrey.blake@arm.comtemplate<> ArmFault::FaultVals ArmFaultVals<ArmSev>::vals =
808518Sgeoffrey.blake@arm.com    {"ArmSev Flush", 0x00, MODE_SVC, 0, 0, true, true}; // some dummy values
816735Sgblack@eecs.umich.eduAddr
827362Sgblack@eecs.umich.eduArmFault::getVector(ThreadContext *tc)
836735Sgblack@eecs.umich.edu{
846735Sgblack@eecs.umich.edu    // ARM ARM B1-3
856019Shines@cs.fsu.edu
866735Sgblack@eecs.umich.edu    SCTLR sctlr = tc->readMiscReg(MISCREG_SCTLR);
877400SAli.Saidi@ARM.com
886735Sgblack@eecs.umich.edu    // panic if SCTLR.VE because I have no idea what to do with vectored
896735Sgblack@eecs.umich.edu    // interrupts
906735Sgblack@eecs.umich.edu    assert(!sctlr.ve);
917400SAli.Saidi@ARM.com
926735Sgblack@eecs.umich.edu    if (!sctlr.v)
936735Sgblack@eecs.umich.edu        return offset();
946735Sgblack@eecs.umich.edu    return offset() + HighVecs;
956019Shines@cs.fsu.edu
966019Shines@cs.fsu.edu}
976019Shines@cs.fsu.edu
986735Sgblack@eecs.umich.eduvoid
997678Sgblack@eecs.umich.eduArmFault::invoke(ThreadContext *tc, StaticInstPtr inst)
1006019Shines@cs.fsu.edu{
1016735Sgblack@eecs.umich.edu    // ARM ARM B1.6.3
1026735Sgblack@eecs.umich.edu    FaultBase::invoke(tc);
1038782Sgblack@eecs.umich.edu    if (!FullSystem)
1048782Sgblack@eecs.umich.edu        return;
1056735Sgblack@eecs.umich.edu    countStat()++;
1066019Shines@cs.fsu.edu
1076735Sgblack@eecs.umich.edu    SCTLR sctlr = tc->readMiscReg(MISCREG_SCTLR);
1086735Sgblack@eecs.umich.edu    CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
1098303SAli.Saidi@ARM.com    CPSR saved_cpsr = tc->readMiscReg(MISCREG_CPSR);
1108303SAli.Saidi@ARM.com    saved_cpsr.nz = tc->readIntReg(INTREG_CONDCODES_NZ);
1118303SAli.Saidi@ARM.com    saved_cpsr.c = tc->readIntReg(INTREG_CONDCODES_C);
1128303SAli.Saidi@ARM.com    saved_cpsr.v = tc->readIntReg(INTREG_CONDCODES_V);
1138303SAli.Saidi@ARM.com    saved_cpsr.ge = tc->readIntReg(INTREG_CONDCODES_GE);
1148303SAli.Saidi@ARM.com
1157720Sgblack@eecs.umich.edu    Addr curPc M5_VAR_USED = tc->pcState().pc();
1168205SAli.Saidi@ARM.com    ITSTATE it = tc->pcState().itstate();
1178205SAli.Saidi@ARM.com    saved_cpsr.it2 = it.top6;
1188205SAli.Saidi@ARM.com    saved_cpsr.it1 = it.bottom2;
1196735Sgblack@eecs.umich.edu
1206735Sgblack@eecs.umich.edu    cpsr.mode = nextMode();
1216735Sgblack@eecs.umich.edu    cpsr.it1 = cpsr.it2 = 0;
1226735Sgblack@eecs.umich.edu    cpsr.j = 0;
1236735Sgblack@eecs.umich.edu
1247093Sgblack@eecs.umich.edu    cpsr.t = sctlr.te;
1256735Sgblack@eecs.umich.edu    cpsr.a = cpsr.a | abortDisable();
1266735Sgblack@eecs.umich.edu    cpsr.f = cpsr.f | fiqDisable();
1276735Sgblack@eecs.umich.edu    cpsr.i = 1;
1287302Sgblack@eecs.umich.edu    cpsr.e = sctlr.ee;
1296735Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_CPSR, cpsr);
1308518Sgeoffrey.blake@arm.com    // Make sure mailbox sets to one always
1318518Sgeoffrey.blake@arm.com    tc->setMiscReg(MISCREG_SEV_MAILBOX, 1);
1327720Sgblack@eecs.umich.edu    tc->setIntReg(INTREG_LR, curPc +
1336735Sgblack@eecs.umich.edu            (saved_cpsr.t ? thumbPcOffset() : armPcOffset()));
1346735Sgblack@eecs.umich.edu
1356735Sgblack@eecs.umich.edu    switch (nextMode()) {
1366735Sgblack@eecs.umich.edu      case MODE_FIQ:
1376735Sgblack@eecs.umich.edu        tc->setMiscReg(MISCREG_SPSR_FIQ, saved_cpsr);
1386735Sgblack@eecs.umich.edu        break;
1396735Sgblack@eecs.umich.edu      case MODE_IRQ:
1406735Sgblack@eecs.umich.edu        tc->setMiscReg(MISCREG_SPSR_IRQ, saved_cpsr);
1416735Sgblack@eecs.umich.edu        break;
1426735Sgblack@eecs.umich.edu      case MODE_SVC:
1436735Sgblack@eecs.umich.edu        tc->setMiscReg(MISCREG_SPSR_SVC, saved_cpsr);
1446735Sgblack@eecs.umich.edu        break;
1456735Sgblack@eecs.umich.edu      case MODE_UNDEFINED:
1466735Sgblack@eecs.umich.edu        tc->setMiscReg(MISCREG_SPSR_UND, saved_cpsr);
1476735Sgblack@eecs.umich.edu        break;
1486735Sgblack@eecs.umich.edu      case MODE_ABORT:
1496735Sgblack@eecs.umich.edu        tc->setMiscReg(MISCREG_SPSR_ABT, saved_cpsr);
1506735Sgblack@eecs.umich.edu        break;
1516735Sgblack@eecs.umich.edu      default:
1526735Sgblack@eecs.umich.edu        panic("unknown Mode\n");
1537093Sgblack@eecs.umich.edu    }
1547093Sgblack@eecs.umich.edu
1557720Sgblack@eecs.umich.edu    Addr newPc = getVector(tc);
1567585SAli.Saidi@arm.com    DPRINTF(Faults, "Invoking Fault:%s cpsr:%#x PC:%#x lr:%#x newVec: %#x\n",
1577720Sgblack@eecs.umich.edu            name(), cpsr, curPc, tc->readIntReg(INTREG_LR), newPc);
1587720Sgblack@eecs.umich.edu    PCState pc(newPc);
1597720Sgblack@eecs.umich.edu    pc.thumb(cpsr.t);
1607720Sgblack@eecs.umich.edu    pc.nextThumb(pc.thumb());
1617720Sgblack@eecs.umich.edu    pc.jazelle(cpsr.j);
1627720Sgblack@eecs.umich.edu    pc.nextJazelle(pc.jazelle());
1637720Sgblack@eecs.umich.edu    tc->pcState(pc);
1646019Shines@cs.fsu.edu}
1657189Sgblack@eecs.umich.edu
1667400SAli.Saidi@ARM.comvoid
1677678Sgblack@eecs.umich.eduReset::invoke(ThreadContext *tc, StaticInstPtr inst)
1687400SAli.Saidi@ARM.com{
1698782Sgblack@eecs.umich.edu    if (FullSystem) {
1708782Sgblack@eecs.umich.edu        tc->getCpuPtr()->clearInterrupts();
1718782Sgblack@eecs.umich.edu        tc->clearArchRegs();
1728782Sgblack@eecs.umich.edu    }
1738205SAli.Saidi@ARM.com    ArmFault::invoke(tc, inst);
1747400SAli.Saidi@ARM.com}
1757400SAli.Saidi@ARM.com
1767189Sgblack@eecs.umich.eduvoid
1777678Sgblack@eecs.umich.eduUndefinedInstruction::invoke(ThreadContext *tc, StaticInstPtr inst)
1787189Sgblack@eecs.umich.edu{
1798782Sgblack@eecs.umich.edu    if (FullSystem) {
1808782Sgblack@eecs.umich.edu        ArmFault::invoke(tc, inst);
1818806Sgblack@eecs.umich.edu        return;
1828806Sgblack@eecs.umich.edu    }
1838806Sgblack@eecs.umich.edu
1848806Sgblack@eecs.umich.edu    // If the mnemonic isn't defined this has to be an unknown instruction.
1858806Sgblack@eecs.umich.edu    assert(unknown || mnemonic != NULL);
1868806Sgblack@eecs.umich.edu    if (disabled) {
1878806Sgblack@eecs.umich.edu        panic("Attempted to execute disabled instruction "
1888806Sgblack@eecs.umich.edu                "'%s' (inst 0x%08x)", mnemonic, machInst);
1898806Sgblack@eecs.umich.edu    } else if (unknown) {
1908806Sgblack@eecs.umich.edu        panic("Attempted to execute unknown instruction (inst 0x%08x)",
1918806Sgblack@eecs.umich.edu              machInst);
1927189Sgblack@eecs.umich.edu    } else {
1938806Sgblack@eecs.umich.edu        panic("Attempted to execute unimplemented instruction "
1948806Sgblack@eecs.umich.edu                "'%s' (inst 0x%08x)", mnemonic, machInst);
1957189Sgblack@eecs.umich.edu    }
1967189Sgblack@eecs.umich.edu}
1977189Sgblack@eecs.umich.edu
1987197Sgblack@eecs.umich.eduvoid
1997678Sgblack@eecs.umich.eduSupervisorCall::invoke(ThreadContext *tc, StaticInstPtr inst)
2007197Sgblack@eecs.umich.edu{
2018782Sgblack@eecs.umich.edu    if (FullSystem) {
2028782Sgblack@eecs.umich.edu        ArmFault::invoke(tc, inst);
2038806Sgblack@eecs.umich.edu        return;
2048806Sgblack@eecs.umich.edu    }
2057197Sgblack@eecs.umich.edu
2068806Sgblack@eecs.umich.edu    // As of now, there isn't a 32 bit thumb version of this instruction.
2078806Sgblack@eecs.umich.edu    assert(!machInst.bigThumb);
2088806Sgblack@eecs.umich.edu    uint32_t callNum;
2098806Sgblack@eecs.umich.edu    callNum = tc->readIntReg(INTREG_R7);
2108806Sgblack@eecs.umich.edu    tc->syscall(callNum);
2118806Sgblack@eecs.umich.edu
2128806Sgblack@eecs.umich.edu    // Advance the PC since that won't happen automatically.
2138806Sgblack@eecs.umich.edu    PCState pc = tc->pcState();
2148806Sgblack@eecs.umich.edu    assert(inst);
2158806Sgblack@eecs.umich.edu    inst->advancePC(pc);
2168806Sgblack@eecs.umich.edu    tc->pcState(pc);
2177197Sgblack@eecs.umich.edu}
2187197Sgblack@eecs.umich.edu
2197362Sgblack@eecs.umich.edutemplate<class T>
2207362Sgblack@eecs.umich.eduvoid
2217678Sgblack@eecs.umich.eduAbortFault<T>::invoke(ThreadContext *tc, StaticInstPtr inst)
2227362Sgblack@eecs.umich.edu{
2238205SAli.Saidi@ARM.com    ArmFaultVals<T>::invoke(tc, inst);
2247362Sgblack@eecs.umich.edu    FSR fsr = 0;
2257362Sgblack@eecs.umich.edu    fsr.fsLow = bits(status, 3, 0);
2267362Sgblack@eecs.umich.edu    fsr.fsHigh = bits(status, 4);
2277362Sgblack@eecs.umich.edu    fsr.domain = domain;
2287362Sgblack@eecs.umich.edu    fsr.wnr = (write ? 1 : 0);
2297362Sgblack@eecs.umich.edu    fsr.ext = 0;
2307362Sgblack@eecs.umich.edu    tc->setMiscReg(T::FsrIndex, fsr);
2317362Sgblack@eecs.umich.edu    tc->setMiscReg(T::FarIndex, faultAddr);
2328314Sgeoffrey.blake@arm.com
2338314Sgeoffrey.blake@arm.com    DPRINTF(Faults, "Abort Fault fsr=%#x faultAddr=%#x\n", fsr, faultAddr);
2347362Sgblack@eecs.umich.edu}
2357362Sgblack@eecs.umich.edu
2367652Sminkyu.jeong@arm.comvoid
2377678Sgblack@eecs.umich.eduFlushPipe::invoke(ThreadContext *tc, StaticInstPtr inst) {
2387652Sminkyu.jeong@arm.com    DPRINTF(Faults, "Invoking FlushPipe Fault\n");
2397652Sminkyu.jeong@arm.com
2407652Sminkyu.jeong@arm.com    // Set the PC to the next instruction of the faulting instruction.
2417652Sminkyu.jeong@arm.com    // Net effect is simply squashing all instructions behind and
2427652Sminkyu.jeong@arm.com    // start refetching from the next instruction.
2437720Sgblack@eecs.umich.edu    PCState pc = tc->pcState();
2447720Sgblack@eecs.umich.edu    assert(inst);
2457720Sgblack@eecs.umich.edu    inst->advancePC(pc);
2467720Sgblack@eecs.umich.edu    tc->pcState(pc);
2477652Sminkyu.jeong@arm.com}
2487652Sminkyu.jeong@arm.com
2497678Sgblack@eecs.umich.edutemplate void AbortFault<PrefetchAbort>::invoke(ThreadContext *tc,
2507678Sgblack@eecs.umich.edu                                                StaticInstPtr inst);
2517678Sgblack@eecs.umich.edutemplate void AbortFault<DataAbort>::invoke(ThreadContext *tc,
2527678Sgblack@eecs.umich.edu                                            StaticInstPtr inst);
2537362Sgblack@eecs.umich.edu
2548518Sgeoffrey.blake@arm.comvoid
2558518Sgeoffrey.blake@arm.comArmSev::invoke(ThreadContext *tc, StaticInstPtr inst) {
2568518Sgeoffrey.blake@arm.com    DPRINTF(Faults, "Invoking ArmSev Fault\n");
2578806Sgblack@eecs.umich.edu    if (!FullSystem)
2588806Sgblack@eecs.umich.edu        return;
2598806Sgblack@eecs.umich.edu
2608806Sgblack@eecs.umich.edu    // Set sev_mailbox to 1, clear the pending interrupt from remote
2618806Sgblack@eecs.umich.edu    // SEV execution and let pipeline continue as pcState is still
2628806Sgblack@eecs.umich.edu    // valid.
2638806Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_SEV_MAILBOX, 1);
2648806Sgblack@eecs.umich.edu    tc->getCpuPtr()->clearInterrupt(INT_SEV, 0);
2658518Sgeoffrey.blake@arm.com}
2668518Sgeoffrey.blake@arm.com
2676735Sgblack@eecs.umich.edu// return via SUBS pc, lr, xxx; rfe, movs, ldm
2686019Shines@cs.fsu.edu
2696019Shines@cs.fsu.edu} // namespace ArmISA
270