faults.cc revision 5858
16657Snate@binkert.org/* 26657Snate@binkert.org * Copyright (c) 2003-2007 The Regents of The University of Michigan 36657Snate@binkert.org * All rights reserved. 46657Snate@binkert.org * 56657Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66657Snate@binkert.org * modification, are permitted provided that the following conditions are 76657Snate@binkert.org * met: redistributions of source code must retain the above copyright 86657Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96657Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106657Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116657Snate@binkert.org * documentation and/or other materials provided with the distribution; 126657Snate@binkert.org * neither the name of the copyright holders nor the names of its 136657Snate@binkert.org * contributors may be used to endorse or promote products derived from 146657Snate@binkert.org * this software without specific prior written permission. 156657Snate@binkert.org * 166657Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176657Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186657Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196657Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206657Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216657Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226657Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236657Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246657Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256657Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266657Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276657Snate@binkert.org * 286999Snate@binkert.org * Authors: Gabe Black 296657Snate@binkert.org */ 306657Snate@binkert.org 316657Snate@binkert.org/* 329302Snilay@cs.wisc.edu * Copyright (c) 2007 The Hewlett-Packard Development Company 336657Snate@binkert.org * All rights reserved. 346657Snate@binkert.org * 356657Snate@binkert.org * Redistribution and use of this software in source and binary forms, 366657Snate@binkert.org * with or without modification, are permitted provided that the 376657Snate@binkert.org * following conditions are met: 386657Snate@binkert.org * 396657Snate@binkert.org * The software must be used only for Non-Commercial Use which means any 406657Snate@binkert.org * use which is NOT directed to receiving any direct monetary 416657Snate@binkert.org * compensation for, or commercial advantage from such use. Illustrative 426657Snate@binkert.org * examples of non-commercial use are academic research, personal study, 436657Snate@binkert.org * teaching, education and corporate research & development. 446657Snate@binkert.org * Illustrative examples of commercial use are distributing products for 456657Snate@binkert.org * commercial advantage and providing services using the software for 466657Snate@binkert.org * commercial advantage. 476657Snate@binkert.org * 486657Snate@binkert.org * If you wish to use this software or functionality therein that may be 496657Snate@binkert.org * covered by patents for commercial use, please contact: 506882SBrad.Beckmann@amd.com * Director of Intellectual Property Licensing 516657Snate@binkert.org * Office of Strategy and Technology 526657Snate@binkert.org * Hewlett-Packard Company 536657Snate@binkert.org * 1501 Page Mill Road 546657Snate@binkert.org * Palo Alto, California 94304 556657Snate@binkert.org * 566657Snate@binkert.org * Redistributions of source code must retain the above copyright notice, 576657Snate@binkert.org * this list of conditions and the following disclaimer. Redistributions 586657Snate@binkert.org * in binary form must reproduce the above copyright notice, this list of 596657Snate@binkert.org * conditions and the following disclaimer in the documentation and/or 606657Snate@binkert.org * other materials provided with the distribution. Neither the name of 616657Snate@binkert.org * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its 626657Snate@binkert.org * contributors may be used to endorse or promote products derived from 636657Snate@binkert.org * this software without specific prior written permission. No right of 646657Snate@binkert.org * sublicense is granted herewith. Derivatives of the software and 656657Snate@binkert.org * output created using the software may be prepared, but only for 666657Snate@binkert.org * Non-Commercial Uses. Derivatives of the software may be shared with 676657Snate@binkert.org * others provided: (i) the others agree to abide by the list of 686657Snate@binkert.org * conditions herein which includes the Non-Commercial Use restrictions; 696657Snate@binkert.org * and (ii) such Derivatives of the software include the above copyright 7010228Snilay@cs.wisc.edu * notice to acknowledge the contribution from this software where 716657Snate@binkert.org * applicable, this list of conditions and the disclaimer below. 726657Snate@binkert.org * 7310228Snilay@cs.wisc.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 746657Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 756657Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 766657Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 776657Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 786657Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 796657Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 806657Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 816657Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 826657Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 836657Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 846657Snate@binkert.org * 856657Snate@binkert.org * Authors: Gabe Black 866657Snate@binkert.org */ 876657Snate@binkert.org 886657Snate@binkert.org#include "arch/x86/decoder.hh" 896657Snate@binkert.org#include "arch/x86/faults.hh" 908086SBrad.Beckmann@amd.com#include "base/trace.hh" 918086SBrad.Beckmann@amd.com#include "config/full_system.hh" 928086SBrad.Beckmann@amd.com#include "cpu/thread_context.hh" 936657Snate@binkert.org#if !FULL_SYSTEM 946657Snate@binkert.org#include "arch/x86/isa_traits.hh" 956657Snate@binkert.org#include "mem/page_table.hh" 966657Snate@binkert.org#include "sim/process.hh" 976657Snate@binkert.org#else 986657Snate@binkert.org#include "arch/x86/tlb.hh" 996657Snate@binkert.org#endif 1006657Snate@binkert.org 1016657Snate@binkert.orgnamespace X86ISA 1026657Snate@binkert.org{ 1036657Snate@binkert.org#if FULL_SYSTEM 1046657Snate@binkert.org void X86FaultBase::invoke(ThreadContext * tc) 1056657Snate@binkert.org { 1066657Snate@binkert.org using namespace X86ISAInst::RomLabels; 1076657Snate@binkert.org HandyM5Reg m5reg = tc->readMiscRegNoEffect(MISCREG_M5_REG); 1086657Snate@binkert.org MicroPC entry; 1096657Snate@binkert.org if (m5reg.mode == LongMode) { 1106657Snate@binkert.org if (isSoft()) { 1116657Snate@binkert.org entry = extern_label_longModeSoftInterrupt; 1126657Snate@binkert.org } else { 1136657Snate@binkert.org entry = extern_label_longModeInterrupt; 1146657Snate@binkert.org } 1156657Snate@binkert.org } else { 1166657Snate@binkert.org entry = extern_label_legacyModeInterrupt; 1176657Snate@binkert.org } 1186657Snate@binkert.org tc->setIntReg(INTREG_MICRO(1), vector); 1196657Snate@binkert.org tc->setIntReg(INTREG_MICRO(7), tc->readPC()); 1206657Snate@binkert.org if (errorCode != (uint64_t)(-1)) { 1216657Snate@binkert.org if (m5reg.mode == LongMode) { 1226657Snate@binkert.org entry = extern_label_longModeInterruptWithError; 1236657Snate@binkert.org } else { 1246657Snate@binkert.org panic("Legacy mode interrupts with error codes " 1256657Snate@binkert.org "aren't implementde.\n"); 1266657Snate@binkert.org } 1276657Snate@binkert.org // Software interrupts shouldn't have error codes. If one does, 1286657Snate@binkert.org // there would need to be microcode to set it up. 1299298Snilay@cs.wisc.edu assert(!isSoft()); 1306657Snate@binkert.org tc->setIntReg(INTREG_MICRO(15), errorCode); 1316657Snate@binkert.org } 1326657Snate@binkert.org tc->setMicroPC(romMicroPC(entry)); 1336657Snate@binkert.org tc->setNextMicroPC(romMicroPC(entry) + 1); 1346657Snate@binkert.org } 1356657Snate@binkert.org 1369302Snilay@cs.wisc.edu void X86Trap::invoke(ThreadContext * tc) 1379302Snilay@cs.wisc.edu { 1389302Snilay@cs.wisc.edu X86FaultBase::invoke(tc); 1396657Snate@binkert.org // This is the same as a fault, but it happens -after- the instruction. 1406657Snate@binkert.org tc->setPC(tc->readNextPC()); 1416657Snate@binkert.org tc->setNextPC(tc->readNextNPC()); 1426657Snate@binkert.org tc->setNextNPC(tc->readNextNPC() + sizeof(MachInst)); 1436657Snate@binkert.org } 1446657Snate@binkert.org 1456657Snate@binkert.org void X86Abort::invoke(ThreadContext * tc) 1466657Snate@binkert.org { 1476882SBrad.Beckmann@amd.com panic("Abort exception!"); 1486882SBrad.Beckmann@amd.com } 1496882SBrad.Beckmann@amd.com 1508086SBrad.Beckmann@amd.com void PageFault::invoke(ThreadContext * tc) 1518086SBrad.Beckmann@amd.com { 1528086SBrad.Beckmann@amd.com HandyM5Reg m5reg = tc->readMiscRegNoEffect(MISCREG_M5_REG); 15310307Snilay@cs.wisc.edu X86FaultBase::invoke(tc); 15410307Snilay@cs.wisc.edu /* 1556657Snate@binkert.org * If something bad happens while trying to enter the page fault 1566657Snate@binkert.org * handler, I'm pretty sure that's a double fault and then all bets are 1576657Snate@binkert.org * off. That means it should be safe to update this state now. 15810307Snilay@cs.wisc.edu */ 1599298Snilay@cs.wisc.edu if (m5reg.mode == LongMode) { 1609298Snilay@cs.wisc.edu tc->setMiscReg(MISCREG_CR2, addr); 1619298Snilay@cs.wisc.edu } else { 1626657Snate@binkert.org tc->setMiscReg(MISCREG_CR2, (uint32_t)addr); 1636657Snate@binkert.org } 1646657Snate@binkert.org } 1656657Snate@binkert.org 1666657Snate@binkert.org void FakeITLBFault::invoke(ThreadContext * tc) 1676657Snate@binkert.org { 1686657Snate@binkert.org // Start the page table walker. 1696657Snate@binkert.org tc->getITBPtr()->walk(tc, vaddr); 1706657Snate@binkert.org } 1716657Snate@binkert.org 1726657Snate@binkert.org void FakeDTLBFault::invoke(ThreadContext * tc) 1739219Spower.jg@gmail.com { 1746657Snate@binkert.org // Start the page table walker. 1756657Snate@binkert.org tc->getDTBPtr()->walk(tc, vaddr); 1766657Snate@binkert.org } 1776657Snate@binkert.org 1786657Snate@binkert.org#else // !FULL_SYSTEM 1796657Snate@binkert.org void FakeITLBFault::invoke(ThreadContext * tc) 1806657Snate@binkert.org { 1816657Snate@binkert.org DPRINTF(TLB, "Invoking an ITLB fault for address %#x at pc %#x.\n", 1826657Snate@binkert.org vaddr, tc->readPC()); 1836657Snate@binkert.org Process *p = tc->getProcessPtr(); 1846657Snate@binkert.org TlbEntry entry; 1856657Snate@binkert.org bool success = p->pTable->lookup(vaddr, entry); 1866999Snate@binkert.org if(!success) { 1876657Snate@binkert.org panic("Tried to execute unmapped address %#x.\n", vaddr); 1886657Snate@binkert.org } else { 1896657Snate@binkert.org Addr alignedVaddr = p->pTable->pageAlign(vaddr); 1906657Snate@binkert.org DPRINTF(TLB, "Mapping %#x to %#x\n", alignedVaddr, 1916657Snate@binkert.org entry.pageStart()); 1926657Snate@binkert.org tc->getITBPtr()->insert(alignedVaddr, entry); 1936657Snate@binkert.org } 1947007Snate@binkert.org } 1957007Snate@binkert.org 1966657Snate@binkert.org void FakeDTLBFault::invoke(ThreadContext * tc) 1977002Snate@binkert.org { 1987002Snate@binkert.org DPRINTF(TLB, "Invoking an DTLB fault for address %#x at pc %#x.\n", 1999466Snilay@cs.wisc.edu vaddr, tc->readPC()); 2006657Snate@binkert.org Process *p = tc->getProcessPtr(); 2016657Snate@binkert.org TlbEntry entry; 2026657Snate@binkert.org bool success = p->pTable->lookup(vaddr, entry); 2036657Snate@binkert.org if(!success) { 2046657Snate@binkert.org p->checkAndAllocNextPage(vaddr); 2056657Snate@binkert.org success = p->pTable->lookup(vaddr, entry); 2066657Snate@binkert.org } 2076657Snate@binkert.org if(!success) { 2086657Snate@binkert.org panic("Tried to access unmapped address %#x.\n", vaddr); 2096657Snate@binkert.org } else { 2106657Snate@binkert.org Addr alignedVaddr = p->pTable->pageAlign(vaddr); 2116657Snate@binkert.org DPRINTF(TLB, "Mapping %#x to %#x\n", alignedVaddr, 2127007Snate@binkert.org entry.pageStart()); 2137007Snate@binkert.org tc->getDTBPtr()->insert(alignedVaddr, entry); 2146657Snate@binkert.org } 2159466Snilay@cs.wisc.edu } 2166657Snate@binkert.org#endif 2176657Snate@binkert.org} // namespace X86ISA 2189466Snilay@cs.wisc.edu 2199508Snilay@cs.wisc.edu