faults.cc revision 5857
15124Sgblack@eecs.umich.edu/*
25124Sgblack@eecs.umich.edu * Copyright (c) 2003-2007 The Regents of The University of Michigan
35124Sgblack@eecs.umich.edu * All rights reserved.
45124Sgblack@eecs.umich.edu *
55124Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
65124Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
75124Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
85124Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
95124Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
105124Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
115124Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
125124Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
135124Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
145124Sgblack@eecs.umich.edu * this software without specific prior written permission.
155124Sgblack@eecs.umich.edu *
165124Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175124Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
185124Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
195124Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
205124Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
215124Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
225124Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235124Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245124Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255124Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265124Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275124Sgblack@eecs.umich.edu *
285124Sgblack@eecs.umich.edu * Authors: Gabe Black
295124Sgblack@eecs.umich.edu */
305124Sgblack@eecs.umich.edu
315124Sgblack@eecs.umich.edu/*
325124Sgblack@eecs.umich.edu * Copyright (c) 2007 The Hewlett-Packard Development Company
335124Sgblack@eecs.umich.edu * All rights reserved.
345124Sgblack@eecs.umich.edu *
355124Sgblack@eecs.umich.edu * Redistribution and use of this software in source and binary forms,
365124Sgblack@eecs.umich.edu * with or without modification, are permitted provided that the
375124Sgblack@eecs.umich.edu * following conditions are met:
385124Sgblack@eecs.umich.edu *
395124Sgblack@eecs.umich.edu * The software must be used only for Non-Commercial Use which means any
405124Sgblack@eecs.umich.edu * use which is NOT directed to receiving any direct monetary
415124Sgblack@eecs.umich.edu * compensation for, or commercial advantage from such use.  Illustrative
425124Sgblack@eecs.umich.edu * examples of non-commercial use are academic research, personal study,
435124Sgblack@eecs.umich.edu * teaching, education and corporate research & development.
445124Sgblack@eecs.umich.edu * Illustrative examples of commercial use are distributing products for
455124Sgblack@eecs.umich.edu * commercial advantage and providing services using the software for
465124Sgblack@eecs.umich.edu * commercial advantage.
475124Sgblack@eecs.umich.edu *
485124Sgblack@eecs.umich.edu * If you wish to use this software or functionality therein that may be
495124Sgblack@eecs.umich.edu * covered by patents for commercial use, please contact:
505124Sgblack@eecs.umich.edu *     Director of Intellectual Property Licensing
515124Sgblack@eecs.umich.edu *     Office of Strategy and Technology
525124Sgblack@eecs.umich.edu *     Hewlett-Packard Company
535124Sgblack@eecs.umich.edu *     1501 Page Mill Road
545124Sgblack@eecs.umich.edu *     Palo Alto, California  94304
555124Sgblack@eecs.umich.edu *
565124Sgblack@eecs.umich.edu * Redistributions of source code must retain the above copyright notice,
575124Sgblack@eecs.umich.edu * this list of conditions and the following disclaimer.  Redistributions
585124Sgblack@eecs.umich.edu * in binary form must reproduce the above copyright notice, this list of
595124Sgblack@eecs.umich.edu * conditions and the following disclaimer in the documentation and/or
605124Sgblack@eecs.umich.edu * other materials provided with the distribution.  Neither the name of
615124Sgblack@eecs.umich.edu * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
625124Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
635124Sgblack@eecs.umich.edu * this software without specific prior written permission.  No right of
645124Sgblack@eecs.umich.edu * sublicense is granted herewith.  Derivatives of the software and
655124Sgblack@eecs.umich.edu * output created using the software may be prepared, but only for
665124Sgblack@eecs.umich.edu * Non-Commercial Uses.  Derivatives of the software may be shared with
675124Sgblack@eecs.umich.edu * others provided: (i) the others agree to abide by the list of
685124Sgblack@eecs.umich.edu * conditions herein which includes the Non-Commercial Use restrictions;
695124Sgblack@eecs.umich.edu * and (ii) such Derivatives of the software include the above copyright
705124Sgblack@eecs.umich.edu * notice to acknowledge the contribution from this software where
715124Sgblack@eecs.umich.edu * applicable, this list of conditions and the disclaimer below.
725124Sgblack@eecs.umich.edu *
735124Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
745124Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
755124Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
765124Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
775124Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
785124Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
795124Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
805124Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
815124Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
825124Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
835124Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
845124Sgblack@eecs.umich.edu *
855124Sgblack@eecs.umich.edu * Authors: Gabe Black
865124Sgblack@eecs.umich.edu */
875124Sgblack@eecs.umich.edu
885681Sgblack@eecs.umich.edu#include "arch/x86/decoder.hh"
895124Sgblack@eecs.umich.edu#include "arch/x86/faults.hh"
905124Sgblack@eecs.umich.edu#include "base/trace.hh"
915124Sgblack@eecs.umich.edu#include "config/full_system.hh"
925124Sgblack@eecs.umich.edu#include "cpu/thread_context.hh"
935124Sgblack@eecs.umich.edu#if !FULL_SYSTEM
945124Sgblack@eecs.umich.edu#include "arch/x86/isa_traits.hh"
955124Sgblack@eecs.umich.edu#include "mem/page_table.hh"
965124Sgblack@eecs.umich.edu#include "sim/process.hh"
975237Sgblack@eecs.umich.edu#else
985237Sgblack@eecs.umich.edu#include "arch/x86/tlb.hh"
995124Sgblack@eecs.umich.edu#endif
1005124Sgblack@eecs.umich.edu
1015124Sgblack@eecs.umich.edunamespace X86ISA
1025124Sgblack@eecs.umich.edu{
1035124Sgblack@eecs.umich.edu#if FULL_SYSTEM
1045130Sgblack@eecs.umich.edu    void X86Trap::invoke(ThreadContext * tc)
1055124Sgblack@eecs.umich.edu    {
1065124Sgblack@eecs.umich.edu        panic("X86 faults are not implemented!");
1075124Sgblack@eecs.umich.edu    }
1085124Sgblack@eecs.umich.edu
1095130Sgblack@eecs.umich.edu    void X86Abort::invoke(ThreadContext * tc)
1105124Sgblack@eecs.umich.edu    {
1115124Sgblack@eecs.umich.edu        panic("X86 faults are not implemented!");
1125124Sgblack@eecs.umich.edu    }
1135124Sgblack@eecs.umich.edu
1145130Sgblack@eecs.umich.edu    void X86Interrupt::invoke(ThreadContext * tc)
1155124Sgblack@eecs.umich.edu    {
1165681Sgblack@eecs.umich.edu        using namespace X86ISAInst::RomLabels;
1175681Sgblack@eecs.umich.edu        HandyM5Reg m5reg = tc->readMiscRegNoEffect(MISCREG_M5_REG);
1185681Sgblack@eecs.umich.edu        MicroPC entry;
1195681Sgblack@eecs.umich.edu        if (m5reg.mode == LongMode) {
1205681Sgblack@eecs.umich.edu            entry = extern_label_longModeInterrupt;
1215681Sgblack@eecs.umich.edu        } else {
1225681Sgblack@eecs.umich.edu            entry = extern_label_legacyModeInterrupt;
1235681Sgblack@eecs.umich.edu        }
1245681Sgblack@eecs.umich.edu        tc->setIntReg(INTREG_MICRO(1), vector);
1255681Sgblack@eecs.umich.edu        tc->setIntReg(INTREG_MICRO(7), tc->readPC());
1265857Sgblack@eecs.umich.edu        if (errorCode != (uint64_t)(-1)) {
1275857Sgblack@eecs.umich.edu            tc->setIntReg(INTREG_MICRO(15), errorCode);
1285857Sgblack@eecs.umich.edu        }
1295681Sgblack@eecs.umich.edu        tc->setMicroPC(romMicroPC(entry));
1305681Sgblack@eecs.umich.edu        tc->setNextMicroPC(romMicroPC(entry) + 1);
1315124Sgblack@eecs.umich.edu    }
1325237Sgblack@eecs.umich.edu
1335237Sgblack@eecs.umich.edu    void FakeITLBFault::invoke(ThreadContext * tc)
1345237Sgblack@eecs.umich.edu    {
1355237Sgblack@eecs.umich.edu        // Start the page table walker.
1365245Sgblack@eecs.umich.edu        tc->getITBPtr()->walk(tc, vaddr);
1375237Sgblack@eecs.umich.edu    }
1385237Sgblack@eecs.umich.edu
1395237Sgblack@eecs.umich.edu    void FakeDTLBFault::invoke(ThreadContext * tc)
1405237Sgblack@eecs.umich.edu    {
1415237Sgblack@eecs.umich.edu        // Start the page table walker.
1425245Sgblack@eecs.umich.edu        tc->getDTBPtr()->walk(tc, vaddr);
1435237Sgblack@eecs.umich.edu    }
1445237Sgblack@eecs.umich.edu
1455124Sgblack@eecs.umich.edu#else // !FULL_SYSTEM
1465124Sgblack@eecs.umich.edu    void FakeITLBFault::invoke(ThreadContext * tc)
1475124Sgblack@eecs.umich.edu    {
1485124Sgblack@eecs.umich.edu        DPRINTF(TLB, "Invoking an ITLB fault for address %#x at pc %#x.\n",
1495124Sgblack@eecs.umich.edu                vaddr, tc->readPC());
1505124Sgblack@eecs.umich.edu        Process *p = tc->getProcessPtr();
1515184Sgblack@eecs.umich.edu        TlbEntry entry;
1525184Sgblack@eecs.umich.edu        bool success = p->pTable->lookup(vaddr, entry);
1535124Sgblack@eecs.umich.edu        if(!success) {
1545124Sgblack@eecs.umich.edu            panic("Tried to execute unmapped address %#x.\n", vaddr);
1555124Sgblack@eecs.umich.edu        } else {
1565124Sgblack@eecs.umich.edu            Addr alignedVaddr = p->pTable->pageAlign(vaddr);
1575188Sgblack@eecs.umich.edu            DPRINTF(TLB, "Mapping %#x to %#x\n", alignedVaddr,
1585188Sgblack@eecs.umich.edu                    entry.pageStart());
1595124Sgblack@eecs.umich.edu            tc->getITBPtr()->insert(alignedVaddr, entry);
1605124Sgblack@eecs.umich.edu        }
1615124Sgblack@eecs.umich.edu    }
1625124Sgblack@eecs.umich.edu
1635124Sgblack@eecs.umich.edu    void FakeDTLBFault::invoke(ThreadContext * tc)
1645124Sgblack@eecs.umich.edu    {
1655124Sgblack@eecs.umich.edu        DPRINTF(TLB, "Invoking an DTLB fault for address %#x at pc %#x.\n",
1665124Sgblack@eecs.umich.edu                vaddr, tc->readPC());
1675124Sgblack@eecs.umich.edu        Process *p = tc->getProcessPtr();
1685184Sgblack@eecs.umich.edu        TlbEntry entry;
1695184Sgblack@eecs.umich.edu        bool success = p->pTable->lookup(vaddr, entry);
1705124Sgblack@eecs.umich.edu        if(!success) {
1715124Sgblack@eecs.umich.edu            p->checkAndAllocNextPage(vaddr);
1725184Sgblack@eecs.umich.edu            success = p->pTable->lookup(vaddr, entry);
1735124Sgblack@eecs.umich.edu        }
1745124Sgblack@eecs.umich.edu        if(!success) {
1755124Sgblack@eecs.umich.edu            panic("Tried to access unmapped address %#x.\n", vaddr);
1765124Sgblack@eecs.umich.edu        } else {
1775124Sgblack@eecs.umich.edu            Addr alignedVaddr = p->pTable->pageAlign(vaddr);
1785188Sgblack@eecs.umich.edu            DPRINTF(TLB, "Mapping %#x to %#x\n", alignedVaddr,
1795188Sgblack@eecs.umich.edu                    entry.pageStart());
1805124Sgblack@eecs.umich.edu            tc->getDTBPtr()->insert(alignedVaddr, entry);
1815124Sgblack@eecs.umich.edu        }
1825124Sgblack@eecs.umich.edu    }
1835124Sgblack@eecs.umich.edu#endif
1845124Sgblack@eecs.umich.edu} // namespace X86ISA
1855124Sgblack@eecs.umich.edu
186