faults.cc revision 7412
15132Sgblack@eecs.umich.edu/* 25132Sgblack@eecs.umich.edu * Copyright (c) 2010 ARM Limited 35132Sgblack@eecs.umich.edu * All rights reserved 45132Sgblack@eecs.umich.edu * 57087Snate@binkert.org * The license below extends only to copyright in the software and shall 67087Snate@binkert.org * not be construed as granting a license to any other intellectual 77087Snate@binkert.org * property including but not limited to intellectual property relating 87087Snate@binkert.org * to a hardware implementation of the functionality of the software 97087Snate@binkert.org * licensed hereunder. You may use the software subject to the license 107087Snate@binkert.org * terms below provided that you ensure that this notice is replicated 117087Snate@binkert.org * unmodified and in its entirety in all distributions of the software, 127087Snate@binkert.org * modified or unmodified, in source code or in binary form. 135132Sgblack@eecs.umich.edu * 147087Snate@binkert.org * Copyright (c) 2003-2005 The Regents of The University of Michigan 157087Snate@binkert.org * Copyright (c) 2007-2008 The Florida State University 167087Snate@binkert.org * All rights reserved. 177087Snate@binkert.org * 187087Snate@binkert.org * Redistribution and use in source and binary forms, with or without 197087Snate@binkert.org * modification, are permitted provided that the following conditions are 207087Snate@binkert.org * met: redistributions of source code must retain the above copyright 217087Snate@binkert.org * notice, this list of conditions and the following disclaimer; 225132Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 237087Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 245132Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 255132Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 265132Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 275132Sgblack@eecs.umich.edu * this software without specific prior written permission. 285132Sgblack@eecs.umich.edu * 295132Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 305132Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 315132Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 325132Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 335132Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 345132Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 355132Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 365132Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 375132Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 385132Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 395132Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 405132Sgblack@eecs.umich.edu * 415132Sgblack@eecs.umich.edu * Authors: Ali Saidi 425132Sgblack@eecs.umich.edu * Gabe Black 435132Sgblack@eecs.umich.edu */ 445132Sgblack@eecs.umich.edu 455132Sgblack@eecs.umich.edu#include "arch/arm/faults.hh" 465132Sgblack@eecs.umich.edu#include "cpu/thread_context.hh" 475132Sgblack@eecs.umich.edu#include "cpu/base.hh" 485132Sgblack@eecs.umich.edu#include "base/trace.hh" 495132Sgblack@eecs.umich.edu 505132Sgblack@eecs.umich.edunamespace ArmISA 515132Sgblack@eecs.umich.edu{ 525132Sgblack@eecs.umich.edu 535334Sgblack@eecs.umich.edutemplate<> ArmFault::FaultVals ArmFaultVals<Reset>::vals = 545334Sgblack@eecs.umich.edu {"reset", 0x00, MODE_SVC, 0, 0, true, true}; 555334Sgblack@eecs.umich.edu 565334Sgblack@eecs.umich.edutemplate<> ArmFault::FaultVals ArmFaultVals<UndefinedInstruction>::vals = 575334Sgblack@eecs.umich.edu {"Undefined Instruction", 0x04, MODE_UNDEFINED, 4 ,2, false, false} ; 585334Sgblack@eecs.umich.edu 595625Sgblack@eecs.umich.edutemplate<> ArmFault::FaultVals ArmFaultVals<SupervisorCall>::vals = 605625Sgblack@eecs.umich.edu {"Supervisor Call", 0x08, MODE_SVC, 4, 2, false, false}; 615625Sgblack@eecs.umich.edu 625625Sgblack@eecs.umich.edutemplate<> ArmFault::FaultVals ArmFaultVals<PrefetchAbort>::vals = 635625Sgblack@eecs.umich.edu {"Prefetch Abort", 0x0C, MODE_ABORT, 4, 4, true, false}; 645334Sgblack@eecs.umich.edu 655334Sgblack@eecs.umich.edutemplate<> ArmFault::FaultVals ArmFaultVals<DataAbort>::vals = 665132Sgblack@eecs.umich.edu {"Data Abort", 0x10, MODE_ABORT, 8, 8, true, false}; 675132Sgblack@eecs.umich.edu 685132Sgblack@eecs.umich.edutemplate<> ArmFault::FaultVals ArmFaultVals<Interrupt>::vals = 695132Sgblack@eecs.umich.edu {"IRQ", 0x18, MODE_IRQ, 4, 4, true, false}; 705132Sgblack@eecs.umich.edu 715132Sgblack@eecs.umich.edutemplate<> ArmFault::FaultVals ArmFaultVals<FastInterrupt>::vals = 725132Sgblack@eecs.umich.edu {"FIQ", 0x1C, MODE_FIQ, 4, 4, true, true}; 735132Sgblack@eecs.umich.edu 745132Sgblack@eecs.umich.eduAddr 755132Sgblack@eecs.umich.eduArmFault::getVector(ThreadContext *tc) 765132Sgblack@eecs.umich.edu{ 775299Sgblack@eecs.umich.edu // ARM ARM B1-3 785299Sgblack@eecs.umich.edu 795299Sgblack@eecs.umich.edu SCTLR sctlr = tc->readMiscReg(MISCREG_SCTLR); 807532Ssteve.reinhardt@amd.com 815132Sgblack@eecs.umich.edu // panic if SCTLR.VE because I have no idea what to do with vectored 825132Sgblack@eecs.umich.edu // interrupts 835334Sgblack@eecs.umich.edu assert(!sctlr.ve); 845334Sgblack@eecs.umich.edu 855625Sgblack@eecs.umich.edu if (!sctlr.v) 865625Sgblack@eecs.umich.edu return offset(); 875627Sgblack@eecs.umich.edu return offset() + HighVecs; 885334Sgblack@eecs.umich.edu 895615Sgblack@eecs.umich.edu} 905615Sgblack@eecs.umich.edu 915334Sgblack@eecs.umich.edu#if FULL_SYSTEM 925625Sgblack@eecs.umich.edu 935625Sgblack@eecs.umich.eduvoid 945625Sgblack@eecs.umich.eduArmFault::invoke(ThreadContext *tc) 955132Sgblack@eecs.umich.edu{ 965132Sgblack@eecs.umich.edu // ARM ARM B1.6.3 975132Sgblack@eecs.umich.edu FaultBase::invoke(tc); 985132Sgblack@eecs.umich.edu countStat()++; 995132Sgblack@eecs.umich.edu 1005132Sgblack@eecs.umich.edu SCTLR sctlr = tc->readMiscReg(MISCREG_SCTLR); 1015132Sgblack@eecs.umich.edu CPSR cpsr = tc->readMiscReg(MISCREG_CPSR); 1025132Sgblack@eecs.umich.edu CPSR saved_cpsr = tc->readMiscReg(MISCREG_CPSR) | 1035132Sgblack@eecs.umich.edu tc->readIntReg(INTREG_CONDCODES); 1045132Sgblack@eecs.umich.edu 1055132Sgblack@eecs.umich.edu 106 cpsr.mode = nextMode(); 107 cpsr.it1 = cpsr.it2 = 0; 108 cpsr.j = 0; 109 110 cpsr.t = sctlr.te; 111 cpsr.a = cpsr.a | abortDisable(); 112 cpsr.f = cpsr.f | fiqDisable(); 113 cpsr.i = 1; 114 cpsr.e = sctlr.ee; 115 tc->setMiscReg(MISCREG_CPSR, cpsr); 116 tc->setIntReg(INTREG_LR, tc->readPC() + 117 (saved_cpsr.t ? thumbPcOffset() : armPcOffset())); 118 119 switch (nextMode()) { 120 case MODE_FIQ: 121 tc->setMiscReg(MISCREG_SPSR_FIQ, saved_cpsr); 122 break; 123 case MODE_IRQ: 124 tc->setMiscReg(MISCREG_SPSR_IRQ, saved_cpsr); 125 break; 126 case MODE_SVC: 127 tc->setMiscReg(MISCREG_SPSR_SVC, saved_cpsr); 128 break; 129 case MODE_UNDEFINED: 130 tc->setMiscReg(MISCREG_SPSR_UND, saved_cpsr); 131 break; 132 case MODE_ABORT: 133 tc->setMiscReg(MISCREG_SPSR_ABT, saved_cpsr); 134 break; 135 default: 136 panic("unknown Mode\n"); 137 } 138 139 Addr pc = tc->readPC(); 140 Addr newPc = getVector(tc) | (sctlr.te ? (ULL(1) << PcTBitShift) : 0); 141 DPRINTF(Faults, "Invoking Fault: %s cpsr: %#x PC: %#x lr: %#x newVector: %#x\n", 142 name(), cpsr, pc, tc->readIntReg(INTREG_LR), newPc); 143 tc->setPC(newPc); 144 tc->setNextPC(newPc + cpsr.t ? 2 : 4 ); 145 tc->setMicroPC(0); 146 tc->setNextMicroPC(1); 147} 148 149void 150Reset::invoke(ThreadContext *tc) 151{ 152 tc->getCpuPtr()->clearInterrupts(); 153 tc->clearArchRegs(); 154 ArmFault::invoke(tc); 155} 156 157#else 158 159void 160UndefinedInstruction::invoke(ThreadContext *tc) 161{ 162 assert(unknown || mnemonic != NULL); 163 if (unknown) { 164 panic("Attempted to execute unknown instruction " 165 "(inst 0x%08x, opcode 0x%x, binary:%s)", 166 machInst, machInst.opcode, inst2string(machInst)); 167 } else { 168 panic("Attempted to execute unimplemented instruction '%s' " 169 "(inst 0x%08x, opcode 0x%x, binary:%s)", 170 mnemonic, machInst, machInst.opcode, inst2string(machInst)); 171 } 172} 173 174void 175SupervisorCall::invoke(ThreadContext *tc) 176{ 177 // As of now, there isn't a 32 bit thumb version of this instruction. 178 assert(!machInst.bigThumb); 179 uint32_t callNum; 180 if (machInst.thumb) { 181 callNum = bits(machInst, 7, 0); 182 } else { 183 callNum = bits(machInst, 23, 0); 184 } 185 if (callNum == 0) { 186 callNum = tc->readIntReg(INTREG_R7); 187 } 188 tc->syscall(callNum); 189 190 // Advance the PC since that won't happen automatically. 191 tc->setPC(tc->readNextPC()); 192 tc->setNextPC(tc->readNextNPC()); 193 tc->setMicroPC(0); 194 tc->setNextMicroPC(1); 195} 196 197#endif // FULL_SYSTEM 198 199template<class T> 200void 201AbortFault<T>::invoke(ThreadContext *tc) 202{ 203 ArmFaultVals<T>::invoke(tc); 204 FSR fsr = 0; 205 fsr.fsLow = bits(status, 3, 0); 206 fsr.fsHigh = bits(status, 4); 207 fsr.domain = domain; 208 fsr.wnr = (write ? 1 : 0); 209 fsr.ext = 0; 210 tc->setMiscReg(T::FsrIndex, fsr); 211 tc->setMiscReg(T::FarIndex, faultAddr); 212} 213 214template void AbortFault<PrefetchAbort>::invoke(ThreadContext *tc); 215template void AbortFault<DataAbort>::invoke(ThreadContext *tc); 216 217// return via SUBS pc, lr, xxx; rfe, movs, ldm 218 219 220 221} // namespace ArmISA 222 223