faults.cc revision 4997
112855Sgabeblack@google.com/* 212855Sgabeblack@google.com * Copyright (c) 2003-2005 The Regents of The University of Michigan 312855Sgabeblack@google.com * All rights reserved. 412855Sgabeblack@google.com * 512855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612855Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112855Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412855Sgabeblack@google.com * this software without specific prior written permission. 1512855Sgabeblack@google.com * 1612855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712855Sgabeblack@google.com * 2812855Sgabeblack@google.com * Authors: Gabe Black 2912855Sgabeblack@google.com * Kevin Lim 3012855Sgabeblack@google.com */ 3112855Sgabeblack@google.com 3212855Sgabeblack@google.com#include "arch/alpha/ev5.hh" 3312855Sgabeblack@google.com#include "arch/alpha/faults.hh" 3412855Sgabeblack@google.com#include "arch/alpha/tlb.hh" 3512855Sgabeblack@google.com#include "cpu/thread_context.hh" 3612855Sgabeblack@google.com#include "cpu/base.hh" 3712855Sgabeblack@google.com#include "base/trace.hh" 3812855Sgabeblack@google.com#if !FULL_SYSTEM 3912855Sgabeblack@google.com#include "sim/process.hh" 4012855Sgabeblack@google.com#include "mem/page_table.hh" 4112855Sgabeblack@google.com#endif 4212855Sgabeblack@google.com 4312855Sgabeblack@google.comnamespace AlphaISA 4412855Sgabeblack@google.com{ 4512855Sgabeblack@google.com 4612855Sgabeblack@google.comFaultName MachineCheckFault::_name = "mchk"; 4712855Sgabeblack@google.comFaultVect MachineCheckFault::_vect = 0x0401; 4812855Sgabeblack@google.comFaultStat MachineCheckFault::_count; 4912855Sgabeblack@google.com 5012855Sgabeblack@google.comFaultName AlignmentFault::_name = "unalign"; 5112855Sgabeblack@google.comFaultVect AlignmentFault::_vect = 0x0301; 5212855Sgabeblack@google.comFaultStat AlignmentFault::_count; 5312855Sgabeblack@google.com 5412855Sgabeblack@google.comFaultName ResetFault::_name = "reset"; 5512855Sgabeblack@google.comFaultVect ResetFault::_vect = 0x0001; 5612855Sgabeblack@google.comFaultStat ResetFault::_count; 5712855Sgabeblack@google.com 5812855Sgabeblack@google.comFaultName ArithmeticFault::_name = "arith"; 5912855Sgabeblack@google.comFaultVect ArithmeticFault::_vect = 0x0501; 6012855Sgabeblack@google.comFaultStat ArithmeticFault::_count; 6112855Sgabeblack@google.com 6212855Sgabeblack@google.comFaultName InterruptFault::_name = "interrupt"; 6312855Sgabeblack@google.comFaultVect InterruptFault::_vect = 0x0101; 6412855Sgabeblack@google.comFaultStat InterruptFault::_count; 6512855Sgabeblack@google.com 6612855Sgabeblack@google.comFaultName NDtbMissFault::_name = "dtb_miss_single"; 6712855Sgabeblack@google.comFaultVect NDtbMissFault::_vect = 0x0201; 6812855Sgabeblack@google.comFaultStat NDtbMissFault::_count; 6912855Sgabeblack@google.com 7012855Sgabeblack@google.comFaultName PDtbMissFault::_name = "dtb_miss_double"; 7112855Sgabeblack@google.comFaultVect PDtbMissFault::_vect = 0x0281; 7212855Sgabeblack@google.comFaultStat PDtbMissFault::_count; 7312855Sgabeblack@google.com 7412855Sgabeblack@google.comFaultName DtbPageFault::_name = "dfault"; 7512855Sgabeblack@google.comFaultVect DtbPageFault::_vect = 0x0381; 7612855Sgabeblack@google.comFaultStat DtbPageFault::_count; 7712855Sgabeblack@google.com 7812855Sgabeblack@google.comFaultName DtbAcvFault::_name = "dfault"; 7912855Sgabeblack@google.comFaultVect DtbAcvFault::_vect = 0x0381; 8012855Sgabeblack@google.comFaultStat DtbAcvFault::_count; 8112855Sgabeblack@google.com 8212855Sgabeblack@google.comFaultName DtbAlignmentFault::_name = "unalign"; 8312855Sgabeblack@google.comFaultVect DtbAlignmentFault::_vect = 0x0301; 8412855Sgabeblack@google.comFaultStat DtbAlignmentFault::_count; 8512855Sgabeblack@google.com 8612855Sgabeblack@google.comFaultName ItbPageFault::_name = "itbmiss"; 8712855Sgabeblack@google.comFaultVect ItbPageFault::_vect = 0x0181; 8812855Sgabeblack@google.comFaultStat ItbPageFault::_count; 8912855Sgabeblack@google.com 9012855Sgabeblack@google.comFaultName ItbAcvFault::_name = "iaccvio"; 9112855Sgabeblack@google.comFaultVect ItbAcvFault::_vect = 0x0081; 9212855Sgabeblack@google.comFaultStat ItbAcvFault::_count; 9312855Sgabeblack@google.com 9412855Sgabeblack@google.comFaultName UnimplementedOpcodeFault::_name = "opdec"; 9512855Sgabeblack@google.comFaultVect UnimplementedOpcodeFault::_vect = 0x0481; 96FaultStat UnimplementedOpcodeFault::_count; 97 98FaultName FloatEnableFault::_name = "fen"; 99FaultVect FloatEnableFault::_vect = 0x0581; 100FaultStat FloatEnableFault::_count; 101 102FaultName PalFault::_name = "pal"; 103FaultVect PalFault::_vect = 0x2001; 104FaultStat PalFault::_count; 105 106FaultName IntegerOverflowFault::_name = "intover"; 107FaultVect IntegerOverflowFault::_vect = 0x0501; 108FaultStat IntegerOverflowFault::_count; 109 110#if FULL_SYSTEM 111 112void AlphaFault::invoke(ThreadContext * tc) 113{ 114 FaultBase::invoke(tc); 115 countStat()++; 116 117 // exception restart address 118 if (setRestartAddress() || !(tc->readPC() & 0x3)) 119 tc->setMiscRegNoEffect(AlphaISA::IPR_EXC_ADDR, tc->readPC()); 120 121 if (skipFaultingInstruction()) { 122 // traps... skip faulting instruction. 123 tc->setMiscRegNoEffect(AlphaISA::IPR_EXC_ADDR, 124 tc->readMiscRegNoEffect(AlphaISA::IPR_EXC_ADDR) + 4); 125 } 126 127 tc->setPC(tc->readMiscRegNoEffect(AlphaISA::IPR_PAL_BASE) + vect()); 128 tc->setNextPC(tc->readPC() + sizeof(MachInst)); 129} 130 131void ArithmeticFault::invoke(ThreadContext * tc) 132{ 133 FaultBase::invoke(tc); 134 panic("Arithmetic traps are unimplemented!"); 135} 136 137void DtbFault::invoke(ThreadContext * tc) 138{ 139 // Set fault address and flags. Even though we're modeling an 140 // EV5, we use the EV6 technique of not latching fault registers 141 // on VPTE loads (instead of locking the registers until IPR_VA is 142 // read, like the EV5). The EV6 approach is cleaner and seems to 143 // work with EV5 PAL code, but not the other way around. 144 if (!tc->misspeculating() 145 && !(reqFlags & VPTE) && !(reqFlags & NO_FAULT)) { 146 // set VA register with faulting address 147 tc->setMiscRegNoEffect(AlphaISA::IPR_VA, vaddr); 148 149 // set MM_STAT register flags 150 tc->setMiscRegNoEffect(AlphaISA::IPR_MM_STAT, 151 (((EV5::Opcode(tc->getInst()) & 0x3f) << 11) 152 | ((EV5::Ra(tc->getInst()) & 0x1f) << 6) 153 | (flags & 0x3f))); 154 155 // set VA_FORM register with faulting formatted address 156 tc->setMiscRegNoEffect(AlphaISA::IPR_VA_FORM, 157 tc->readMiscRegNoEffect(AlphaISA::IPR_MVPTBR) | (vaddr.vpn() << 3)); 158 } 159 160 AlphaFault::invoke(tc); 161} 162 163void ItbFault::invoke(ThreadContext * tc) 164{ 165 if (!tc->misspeculating()) { 166 tc->setMiscRegNoEffect(AlphaISA::IPR_ITB_TAG, pc); 167 tc->setMiscRegNoEffect(AlphaISA::IPR_IFAULT_VA_FORM, 168 tc->readMiscRegNoEffect(AlphaISA::IPR_IVPTBR) | 169 (AlphaISA::VAddr(pc).vpn() << 3)); 170 } 171 172 AlphaFault::invoke(tc); 173} 174 175#else 176 177void ItbPageFault::invoke(ThreadContext * tc) 178{ 179 Process *p = tc->getProcessPtr(); 180 Addr physaddr; 181 bool success = p->pTable->translate(pc, physaddr); 182 if(!success) { 183 panic("Tried to execute unmapped address %#x.\n", pc); 184 } else { 185 VAddr vaddr(pc); 186 VAddr paddr(physaddr); 187 188 PTE pte; 189 pte.tag = vaddr.vpn(); 190 pte.ppn = paddr.vpn(); 191 pte.xre = 15; //This can be read in all modes. 192 pte.xwe = 1; //This can be written only in kernel mode. 193 pte.asn = p->M5_pid; //Address space number. 194 pte.asma = false; //Only match on this ASN. 195 pte.fonr = false; //Don't fault on read. 196 pte.fonw = false; //Don't fault on write. 197 pte.valid = true; //This entry is valid. 198 199 tc->getITBPtr()->insert(vaddr.page(), pte); 200 } 201} 202 203void NDtbMissFault::invoke(ThreadContext * tc) 204{ 205 Process *p = tc->getProcessPtr(); 206 Addr physaddr; 207 bool success = p->pTable->translate(vaddr, physaddr); 208 if(!success) { 209 p->checkAndAllocNextPage(vaddr); 210 success = p->pTable->translate(vaddr, physaddr); 211 } 212 if(!success) { 213 panic("Tried to access unmapped address %#x.\n", (Addr)vaddr); 214 } else { 215 VAddr paddr(physaddr); 216 217 PTE pte; 218 pte.tag = vaddr.vpn(); 219 pte.ppn = paddr.vpn(); 220 pte.xre = 15; //This can be read in all modes. 221 pte.xwe = 15; //This can be written in all modes. 222 pte.asn = p->M5_pid; //Address space number. 223 pte.asma = false; //Only match on this ASN. 224 pte.fonr = false; //Don't fault on read. 225 pte.fonw = false; //Don't fault on write. 226 pte.valid = true; //This entry is valid. 227 228 tc->getDTBPtr()->insert(vaddr.page(), pte); 229 } 230} 231 232#endif 233 234} // namespace AlphaISA 235 236