faults.cc revision 2800
1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Gabe Black 29 * Kevin Lim 30 */ 31 32#include "arch/sparc/faults.hh" 33#include "cpu/thread_context.hh" 34#include "cpu/base.hh" 35#include "base/trace.hh" 36#if !FULL_SYSTEM 37#include "sim/process.hh" 38#include "mem/page_table.hh" 39#endif 40 41namespace SparcISA 42{ 43 44FaultName InternalProcessorError::_name = "intprocerr"; 45TrapType InternalProcessorError::_trapType = 0x029; 46FaultPriority InternalProcessorError::_priority = 4; 47FaultStat InternalProcessorError::_count; 48 49FaultName MemAddressNotAligned::_name = "unalign"; 50TrapType MemAddressNotAligned::_trapType = 0x034; 51FaultPriority MemAddressNotAligned::_priority = 10; 52FaultStat MemAddressNotAligned::_count; 53 54FaultName PowerOnReset::_name = "pow_reset"; 55TrapType PowerOnReset::_trapType = 0x001; 56FaultPriority PowerOnReset::_priority = 0; 57FaultStat PowerOnReset::_count; 58 59FaultName WatchDogReset::_name = "watch_dog_reset"; 60TrapType WatchDogReset::_trapType = 0x002; 61FaultPriority WatchDogReset::_priority = 1; 62FaultStat WatchDogReset::_count; 63 64FaultName ExternallyInitiatedReset::_name = "extern_reset"; 65TrapType ExternallyInitiatedReset::_trapType = 0x003; 66FaultPriority ExternallyInitiatedReset::_priority = 1; 67FaultStat ExternallyInitiatedReset::_count; 68 69FaultName SoftwareInitiatedReset::_name = "software_reset"; 70TrapType SoftwareInitiatedReset::_trapType = 0x004; 71FaultPriority SoftwareInitiatedReset::_priority = 1; 72FaultStat SoftwareInitiatedReset::_count; 73 74FaultName REDStateException::_name = "red_counte"; 75TrapType REDStateException::_trapType = 0x005; 76FaultPriority REDStateException::_priority = 1; 77FaultStat REDStateException::_count; 78 79FaultName InstructionAccessException::_name = "inst_access"; 80TrapType InstructionAccessException::_trapType = 0x008; 81FaultPriority InstructionAccessException::_priority = 5; 82FaultStat InstructionAccessException::_count; 83 84FaultName InstructionAccessMMUMiss::_name = "inst_mmu"; 85TrapType InstructionAccessMMUMiss::_trapType = 0x009; 86FaultPriority InstructionAccessMMUMiss::_priority = 2; 87FaultStat InstructionAccessMMUMiss::_count; 88 89FaultName InstructionAccessError::_name = "inst_error"; 90TrapType InstructionAccessError::_trapType = 0x00A; 91FaultPriority InstructionAccessError::_priority = 3; 92FaultStat InstructionAccessError::_count; 93 94FaultName IllegalInstruction::_name = "illegal_inst"; 95TrapType IllegalInstruction::_trapType = 0x010; 96FaultPriority IllegalInstruction::_priority = 7; 97FaultStat IllegalInstruction::_count; 98 99FaultName PrivilegedOpcode::_name = "priv_opcode"; 100TrapType PrivilegedOpcode::_trapType = 0x011; 101FaultPriority PrivilegedOpcode::_priority = 6; 102FaultStat PrivilegedOpcode::_count; 103 104FaultName UnimplementedLDD::_name = "unimp_ldd"; 105TrapType UnimplementedLDD::_trapType = 0x012; 106FaultPriority UnimplementedLDD::_priority = 6; 107FaultStat UnimplementedLDD::_count; 108 109FaultName UnimplementedSTD::_name = "unimp_std"; 110TrapType UnimplementedSTD::_trapType = 0x013; 111FaultPriority UnimplementedSTD::_priority = 6; 112FaultStat UnimplementedSTD::_count; 113 114FaultName FpDisabled::_name = "fp_disabled"; 115TrapType FpDisabled::_trapType = 0x020; 116FaultPriority FpDisabled::_priority = 8; 117FaultStat FpDisabled::_count; 118 119FaultName FpExceptionIEEE754::_name = "fp_754"; 120TrapType FpExceptionIEEE754::_trapType = 0x021; 121FaultPriority FpExceptionIEEE754::_priority = 11; 122FaultStat FpExceptionIEEE754::_count; 123 124FaultName FpExceptionOther::_name = "fp_other"; 125TrapType FpExceptionOther::_trapType = 0x022; 126FaultPriority FpExceptionOther::_priority = 11; 127FaultStat FpExceptionOther::_count; 128 129FaultName TagOverflow::_name = "tag_overflow"; 130TrapType TagOverflow::_trapType = 0x023; 131FaultPriority TagOverflow::_priority = 14; 132FaultStat TagOverflow::_count; 133 134FaultName DivisionByZero::_name = "div_by_zero"; 135TrapType DivisionByZero::_trapType = 0x028; 136FaultPriority DivisionByZero::_priority = 15; 137FaultStat DivisionByZero::_count; 138 139FaultName DataAccessException::_name = "data_access"; 140TrapType DataAccessException::_trapType = 0x030; 141FaultPriority DataAccessException::_priority = 12; 142FaultStat DataAccessException::_count; 143 144FaultName DataAccessMMUMiss::_name = "data_mmu"; 145TrapType DataAccessMMUMiss::_trapType = 0x031; 146FaultPriority DataAccessMMUMiss::_priority = 12; 147FaultStat DataAccessMMUMiss::_count; 148 149FaultName DataAccessError::_name = "data_error"; 150TrapType DataAccessError::_trapType = 0x032; 151FaultPriority DataAccessError::_priority = 12; 152FaultStat DataAccessError::_count; 153 154FaultName DataAccessProtection::_name = "data_protection"; 155TrapType DataAccessProtection::_trapType = 0x033; 156FaultPriority DataAccessProtection::_priority = 12; 157FaultStat DataAccessProtection::_count; 158 159FaultName LDDFMemAddressNotAligned::_name = "unalign_lddf"; 160TrapType LDDFMemAddressNotAligned::_trapType = 0x035; 161FaultPriority LDDFMemAddressNotAligned::_priority = 10; 162FaultStat LDDFMemAddressNotAligned::_count; 163 164FaultName STDFMemAddressNotAligned::_name = "unalign_stdf"; 165TrapType STDFMemAddressNotAligned::_trapType = 0x036; 166FaultPriority STDFMemAddressNotAligned::_priority = 10; 167FaultStat STDFMemAddressNotAligned::_count; 168 169FaultName PrivilegedAction::_name = "priv_action"; 170TrapType PrivilegedAction::_trapType = 0x037; 171FaultPriority PrivilegedAction::_priority = 11; 172FaultStat PrivilegedAction::_count; 173 174FaultName LDQFMemAddressNotAligned::_name = "unalign_ldqf"; 175TrapType LDQFMemAddressNotAligned::_trapType = 0x038; 176FaultPriority LDQFMemAddressNotAligned::_priority = 10; 177FaultStat LDQFMemAddressNotAligned::_count; 178 179FaultName STQFMemAddressNotAligned::_name = "unalign_stqf"; 180TrapType STQFMemAddressNotAligned::_trapType = 0x039; 181FaultPriority STQFMemAddressNotAligned::_priority = 10; 182FaultStat STQFMemAddressNotAligned::_count; 183 184FaultName AsyncDataError::_name = "async_data"; 185TrapType AsyncDataError::_trapType = 0x040; 186FaultPriority AsyncDataError::_priority = 2; 187FaultStat AsyncDataError::_count; 188 189FaultName CleanWindow::_name = "clean_win"; 190TrapType CleanWindow::_trapType = 0x024; 191FaultPriority CleanWindow::_priority = 10; 192FaultStat CleanWindow::_count; 193 194//The enumerated faults 195 196FaultName InterruptLevelN::_name = "interrupt_n"; 197TrapType InterruptLevelN::_baseTrapType = 0x041; 198FaultStat InterruptLevelN::_count; 199 200FaultName SpillNNormal::_name = "spill_n_normal"; 201TrapType SpillNNormal::_baseTrapType = 0x080; 202FaultPriority SpillNNormal::_priority = 9; 203FaultStat SpillNNormal::_count; 204 205FaultName SpillNOther::_name = "spill_n_other"; 206TrapType SpillNOther::_baseTrapType = 0x0A0; 207FaultPriority SpillNOther::_priority = 9; 208FaultStat SpillNOther::_count; 209 210FaultName FillNNormal::_name = "fill_n_normal"; 211TrapType FillNNormal::_baseTrapType = 0x0C0; 212FaultPriority FillNNormal::_priority = 9; 213FaultStat FillNNormal::_count; 214 215FaultName FillNOther::_name = "fill_n_other"; 216TrapType FillNOther::_baseTrapType = 0x0E0; 217FaultPriority FillNOther::_priority = 9; 218FaultStat FillNOther::_count; 219 220FaultName TrapInstruction::_name = "trap_inst_n"; 221TrapType TrapInstruction::_baseTrapType = 0x100; 222FaultPriority TrapInstruction::_priority = 16; 223FaultStat TrapInstruction::_count; 224 225#if !FULL_SYSTEM 226FaultName PageTableFault::_name = "page_table_fault"; 227TrapType PageTableFault::_trapType = 0x0000; 228FaultPriority PageTableFault::_priority = 0; 229FaultStat PageTableFault::_count; 230#endif 231 232#if FULL_SYSTEM 233 234void SparcFault::invoke(ThreadContext * tc) 235{ 236 FaultBase::invoke(tc); 237 countStat()++; 238 239 //Use the SPARC trap state machine 240 /*// exception restart address 241 if (setRestartAddress() || !tc->inPalMode()) 242 tc->setMiscReg(AlphaISA::IPR_EXC_ADDR, tc->regs.pc); 243 244 if (skipFaultingInstruction()) { 245 // traps... skip faulting instruction. 246 tc->setMiscReg(AlphaISA::IPR_EXC_ADDR, 247 tc->readMiscReg(AlphaISA::IPR_EXC_ADDR) + 4); 248 } 249 250 if (!tc->inPalMode()) 251 AlphaISA::swap_palshadow(&(tc->regs), true); 252 253 tc->regs.pc = tc->readMiscReg(AlphaISA::IPR_PAL_BASE) + vect(); 254 tc->regs.npc = tc->regs.pc + sizeof(MachInst);*/ 255} 256 257#endif 258 259#if !FULL_SYSTEM 260 261void TrapInstruction::invoke(ThreadContext * tc) 262{ 263 // Should be handled in ISA. 264} 265 266void PageTableFault::invoke(ThreadContext *tc) 267{ 268 Process *p = tc->getProcessPtr(); 269 270 // address is higher than the stack region or in the current stack region 271 if (vaddr > p->stack_base || vaddr > p->stack_min) 272 FaultBase::invoke(tc); 273 274 // We've accessed the next page 275 if (vaddr > p->stack_min - PageBytes) { 276 p->stack_min -= PageBytes; 277 if (p->stack_base - p->stack_min > 8*1024*1024) 278 fatal("Over max stack size for one thread\n"); 279 p->pTable->allocate(p->stack_min, PageBytes); 280 warn("Increasing stack size by one page."); 281 } else { 282 FaultBase::invoke(tc); 283 } 284} 285#endif 286 287} // namespace SparcISA 288 289