2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * Copyright (c) 2007 MIPS Technologies, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "arch/mips/faults.hh"
35 #include "arch/mips/pra_constants.hh"
36 #include "base/trace.hh"
37 #include "cpu/base.hh"
38 #include "cpu/thread_context.hh"
39 #include "debug/MipsPRA.hh"
42 #include "mem/page_table.hh"
43 #include "sim/process.hh"
49 typedef MipsFaultBase::FaultVals FaultVals
;
51 template <> FaultVals MipsFault
<MachineCheckFault
>::vals
=
52 { "Machine Check", 0x0401 };
54 template <> FaultVals MipsFault
<ResetFault
>::vals
=
56 { "Reset Fault", 0xBFC00000};
58 { "Reset Fault", 0x001};
61 template <> FaultVals MipsFault
<AddressErrorFault
>::vals
=
62 { "Address Error", 0x0180 };
64 template <> FaultVals MipsFault
<StoreAddressErrorFault
>::vals
=
65 { "Store Address Error", 0x0180 };
67 template <> FaultVals MipsFault
<SystemCallFault
>::vals
=
68 { "Syscall", 0x0180 };
70 template <> FaultVals MipsFault
<CoprocessorUnusableFault
>::vals
=
71 { "Coprocessor Unusable Fault", 0x180 };
73 template <> FaultVals MipsFault
<ReservedInstructionFault
>::vals
=
74 { "Reserved Instruction Fault", 0x0180 };
76 template <> FaultVals MipsFault
<ThreadFault
>::vals
=
77 { "Thread Fault", 0x00F1 };
79 template <> FaultVals MipsFault
<IntegerOverflowFault
>::vals
=
80 { "Integer Overflow Exception", 0x180 };
82 template <> FaultVals MipsFault
<InterruptFault
>::vals
=
83 { "interrupt", 0x0180 };
85 template <> FaultVals MipsFault
<TrapFault
>::vals
=
88 template <> FaultVals MipsFault
<BreakpointFault
>::vals
=
89 { "Breakpoint", 0x0180 };
91 template <> FaultVals MipsFault
<ItbInvalidFault
>::vals
=
92 { "Invalid TLB Entry Exception (I-Fetch/LW)", 0x0180 };
94 template <> FaultVals MipsFault
<ItbRefillFault
>::vals
=
95 { "TLB Refill Exception (I-Fetch/LW)", 0x0180 };
97 template <> FaultVals MipsFault
<DtbInvalidFault
>::vals
=
98 { "Invalid TLB Entry Exception (Store)", 0x0180 };
100 template <> FaultVals MipsFault
<DtbRefillFault
>::vals
=
101 { "TLB Refill Exception (Store)", 0x0180 };
103 template <> FaultVals MipsFault
<TLBModifiedFault
>::vals
=
104 { "TLB Modified Exception", 0x0180 };
106 template <> FaultVals MipsFault
<DspStateDisabledFault
>::vals
=
107 { "DSP Disabled Fault", 0x001a };
111 MipsFaultBase::setHandlerPC(Addr HandlerBase
, ThreadContext
*tc
)
113 tc
->setPC(HandlerBase
);
114 tc
->setNextPC(HandlerBase
+ sizeof(MachInst
));
115 tc
->setNextNPC(HandlerBase
+ 2 * sizeof(MachInst
));
119 MipsFaultBase::setExceptionState(ThreadContext
*tc
, uint8_t excCode
)
121 // modify SRS Ctl - Save CSS, put ESS into CSS
122 StatusReg status
= tc
->readMiscReg(MISCREG_STATUS
);
123 if (status
.exl
!= 1 && status
.bev
!= 1) {
124 // SRS Ctl is modified only if Status_EXL and Status_BEV are not set
125 SRSCtlReg srsCtl
= tc
->readMiscReg(MISCREG_SRSCTL
);
126 srsCtl
.pss
= srsCtl
.css
;
127 srsCtl
.css
= srsCtl
.ess
;
128 tc
->setMiscRegNoEffect(MISCREG_SRSCTL
, srsCtl
);
131 // set EXL bit (don't care if it is already set!)
133 tc
->setMiscRegNoEffect(MISCREG_STATUS
, status
);
136 // CHECK ME or FIXME or FIX ME or POSSIBLE HACK
137 // Check to see if the exception occurred in the branch delay slot
138 DPRINTF(MipsPRA
, "PC: %x, NextPC: %x, NNPC: %x\n",
139 tc
->readPC(), tc
->readNextPC(), tc
->readNextNPC());
141 if (tc
->readPC() + sizeof(MachInst
) != tc
->readNextPC()) {
142 tc
->setMiscRegNoEffect(MISCREG_EPC
, tc
->readPC() - sizeof(MachInst
));
143 // In the branch delay slot? set CAUSE_31
146 tc
->setMiscRegNoEffect(MISCREG_EPC
, tc
->readPC());
147 // In the branch delay slot? reset CAUSE_31
151 // Set Cause_EXCCODE field
152 CauseReg cause
= tc
->readMiscReg(MISCREG_CAUSE
);
153 cause
.excCode
= excCode
;
156 tc
->setMiscRegNoEffect(MISCREG_CAUSE
, cause
);
160 IntegerOverflowFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
162 DPRINTF(MipsPRA
, "%s encountered.\n", name());
163 setExceptionState(tc
, 0xC);
167 StatusReg status
= tc
->readMiscReg(MISCREG_STATUS
);
168 // Here, the handler is dependent on BEV, which is not modified by
169 // setExceptionState()
171 // See MIPS ARM Vol 3, Revision 2, Page 38
172 HandlerBase
= vect() + tc
->readMiscReg(MISCREG_EBASE
);
174 HandlerBase
= 0xBFC00200;
176 setHandlerPC(HandlerBase
, tc
);
180 StoreAddressErrorFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
182 DPRINTF(MipsPRA
, "%s encountered.\n", name());
183 setExceptionState(tc
, 0x5);
184 tc
->setMiscRegNoEffect(MISCREG_BADVADDR
, badVAddr
);
188 // Offset 0x180 - General Exception Vector
189 HandlerBase
= vect() + tc
->readMiscReg(MISCREG_EBASE
);
190 setHandlerPC(HandlerBase
, tc
);
194 TrapFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
196 DPRINTF(MipsPRA
, "%s encountered.\n", name());
197 setExceptionState(tc
, 0xD);
201 // Offset 0x180 - General Exception Vector
202 HandlerBase
= vect() + tc
->readMiscReg(MISCREG_EBASE
);
203 setHandlerPC(HandlerBase
, tc
);
207 BreakpointFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
209 setExceptionState(tc
, 0x9);
213 // Offset 0x180 - General Exception Vector
214 HandlerBase
= vect() + tc
->readMiscReg(MISCREG_EBASE
);
215 setHandlerPC(HandlerBase
, tc
);
219 DtbInvalidFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
221 DPRINTF(MipsPRA
, "%s encountered.\n", name());
223 tc
->setMiscRegNoEffect(MISCREG_BADVADDR
, badVAddr
);
224 EntryHiReg entryHi
= tc
->readMiscReg(MISCREG_ENTRYHI
);
225 entryHi
.asid
= entryHiAsid
;
226 entryHi
.vpn2
= entryHiVPN2
;
227 entryHi
.vpn2x
= entryHiVPN2X
;
228 tc
->setMiscRegNoEffect(MISCREG_ENTRYHI
, entryHi
);
230 ContextReg context
= tc
->readMiscReg(MISCREG_CONTEXT
);
231 context
.badVPN2
= contextBadVPN2
;
232 tc
->setMiscRegNoEffect(MISCREG_CONTEXT
, context
);
233 setExceptionState(tc
, 0x3);
238 // Offset 0x180 - General Exception Vector
239 HandlerBase
= vect() + tc
->readMiscReg(MISCREG_EBASE
);
240 setHandlerPC(HandlerBase
, tc
);
244 AddressErrorFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
246 DPRINTF(MipsPRA
, "%s encountered.\n", name());
247 setExceptionState(tc
, 0x4);
248 tc
->setMiscRegNoEffect(MISCREG_BADVADDR
, badVAddr
);
252 // Offset 0x180 - General Exception Vector
253 HandlerBase
= vect() + tc
->readMiscReg(MISCREG_EBASE
);
254 setHandlerPC(HandlerBase
, tc
);
258 ItbInvalidFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
260 DPRINTF(MipsPRA
, "%s encountered.\n", name());
261 setExceptionState(tc
, 0x2);
262 tc
->setMiscRegNoEffect(MISCREG_BADVADDR
, badVAddr
);
263 EntryHiReg entryHi
= tc
->readMiscReg(MISCREG_ENTRYHI
);
264 entryHi
.asid
= entryHiAsid
;
265 entryHi
.vpn2
= entryHiVPN2
;
266 entryHi
.vpn2x
= entryHiVPN2X
;
267 tc
->setMiscRegNoEffect(MISCREG_ENTRYHI
, entryHi
);
269 ContextReg context
= tc
->readMiscReg(MISCREG_CONTEXT
);
270 context
.badVPN2
= contextBadVPN2
;
271 tc
->setMiscRegNoEffect(MISCREG_CONTEXT
, context
);
276 // Offset 0x180 - General Exception Vector
277 HandlerBase
= vect() + tc
->readMiscReg(MISCREG_EBASE
);
278 setHandlerPC(HandlerBase
,tc
);
279 DPRINTF(MipsPRA
, "Exception Handler At: %x , EPC set to %x\n",
280 HandlerBase
, tc
->readMiscReg(MISCREG_EPC
));
284 ItbRefillFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
286 DPRINTF(MipsPRA
, "%s encountered (%x).\n", name(), MISCREG_BADVADDR
);
288 tc
->setMiscRegNoEffect(MISCREG_BADVADDR
, badVAddr
);
289 EntryHiReg entryHi
= tc
->readMiscReg(MISCREG_ENTRYHI
);
290 entryHi
.asid
= entryHiAsid
;
291 entryHi
.vpn2
= entryHiVPN2
;
292 entryHi
.vpn2x
= entryHiVPN2X
;
293 tc
->setMiscRegNoEffect(MISCREG_ENTRYHI
, entryHi
);
294 ContextReg context
= tc
->readMiscReg(MISCREG_CONTEXT
);
295 context
.badVPN2
= contextBadVPN2
;
296 tc
->setMiscRegNoEffect(MISCREG_CONTEXT
, context
);
298 StatusReg status
= tc
->readMiscReg(MISCREG_STATUS
);
299 // Since handler depends on EXL bit, must check EXL bit before setting it!!
300 // See MIPS ARM Vol 3, Revision 2, Page 38
301 if (status
.exl
== 1) {
302 // Offset 0x180 - General Exception Vector
303 HandlerBase
= vect() + tc
->readMiscReg(MISCREG_EBASE
);
306 HandlerBase
= tc
->readMiscReg(MISCREG_EBASE
);
309 setExceptionState(tc
, 0x2);
310 setHandlerPC(HandlerBase
, tc
);
314 DtbRefillFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
317 DPRINTF(MipsPRA
, "%s encountered.\n", name());
319 tc
->setMiscRegNoEffect(MISCREG_BADVADDR
, badVAddr
);
320 EntryHiReg entryHi
= tc
->readMiscReg(MISCREG_ENTRYHI
);
321 entryHi
.asid
= entryHiAsid
;
322 entryHi
.vpn2
= entryHiVPN2
;
323 entryHi
.vpn2x
= entryHiVPN2X
;
324 tc
->setMiscRegNoEffect(MISCREG_ENTRYHI
, entryHi
);
326 ContextReg context
= tc
->readMiscReg(MISCREG_CONTEXT
);
327 context
.badVPN2
= contextBadVPN2
;
328 tc
->setMiscRegNoEffect(MISCREG_CONTEXT
, context
);
330 StatusReg status
= tc
->readMiscReg(MISCREG_STATUS
);
331 // Since handler depends on EXL bit, must check EXL bit before setting it!!
332 // See MIPS ARM Vol 3, Revision 2, Page 38
334 // Offset 0x180 - General Exception Vector
335 HandlerBase
= vect() + tc
->readMiscReg(MISCREG_EBASE
);
338 HandlerBase
= tc
->readMiscReg(MISCREG_EBASE
);
341 setExceptionState(tc
, 0x3);
343 setHandlerPC(HandlerBase
, tc
);
347 TLBModifiedFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
349 DPRINTF(MipsPRA
, "%s encountered.\n", name());
350 tc
->setMiscRegNoEffect(MISCREG_BADVADDR
, badVAddr
);
351 EntryHiReg entryHi
= tc
->readMiscReg(MISCREG_ENTRYHI
);
352 entryHi
.asid
= entryHiAsid
;
353 entryHi
.vpn2
= entryHiVPN2
;
354 entryHi
.vpn2x
= entryHiVPN2X
;
355 tc
->setMiscRegNoEffect(MISCREG_ENTRYHI
, entryHi
);
357 ContextReg context
= tc
->readMiscReg(MISCREG_CONTEXT
);
358 context
.badVPN2
= contextBadVPN2
;
359 tc
->setMiscRegNoEffect(MISCREG_CONTEXT
, context
);
363 // Offset 0x180 - General Exception Vector
364 HandlerBase
= vect() + tc
->readMiscReg(MISCREG_EBASE
);
365 setExceptionState(tc
, 0x1);
366 setHandlerPC(HandlerBase
, tc
);
371 SystemCallFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
373 DPRINTF(MipsPRA
, "%s encountered.\n", name());
374 setExceptionState(tc
, 0x8);
378 // Offset 0x180 - General Exception Vector
379 HandlerBase
= vect() + tc
->readMiscReg(MISCREG_EBASE
);
380 setHandlerPC(HandlerBase
, tc
);
384 InterruptFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
387 DPRINTF(MipsPRA
, "%s encountered.\n", name());
388 setExceptionState(tc
, 0x0A);
391 CauseReg cause
= tc
->readMiscRegNoEffect(MISCREG_CAUSE
);
393 // Offset 200 for release 2
394 HandlerBase
= 0x20 + vect() + tc
->readMiscRegNoEffect(MISCREG_EBASE
);
396 //Ofset at 180 for release 1
397 HandlerBase
= vect() + tc
->readMiscRegNoEffect(MISCREG_EBASE
);
400 setHandlerPC(HandlerBase
, tc
);
404 #endif // FULL_SYSTEM
407 ResetFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
410 DPRINTF(MipsPRA
, "%s encountered.\n", name());
411 /* All reset activity must be invoked from here */
413 tc
->setNextPC(vect() + sizeof(MachInst
));
414 tc
->setNextNPC(vect() + sizeof(MachInst
) + sizeof(MachInst
));
415 DPRINTF(MipsPRA
, "ResetFault::invoke : PC set to %x", tc
->readPC());
418 // Set Coprocessor 1 (Floating Point) To Usable
419 StatusReg status
= tc
->readMiscRegNoEffect(MISCREG_STATUS
);
421 tc
->setMiscReg(MISCREG_STATUS
, status
);
425 ReservedInstructionFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
428 DPRINTF(MipsPRA
, "%s encountered.\n", name());
429 setExceptionState(tc
, 0x0A);
431 // Offset 0x180 - General Exception Vector
432 HandlerBase
= vect() + tc
->readMiscRegNoEffect(MISCREG_EBASE
);
433 setHandlerPC(HandlerBase
, tc
);
435 panic("%s encountered.\n", name());
440 ThreadFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
442 DPRINTF(MipsPRA
, "%s encountered.\n", name());
443 panic("%s encountered.\n", name());
447 DspStateDisabledFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
449 DPRINTF(MipsPRA
, "%s encountered.\n", name());
450 panic("%s encountered.\n", name());
454 CoprocessorUnusableFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
457 DPRINTF(MipsPRA
, "%s encountered.\n", name());
458 setExceptionState(tc
, 0xb);
459 // The ID of the coprocessor causing the exception is stored in
460 // CoprocessorUnusableFault::coProcID
461 CauseReg cause
= tc
->readMiscReg(MISCREG_CAUSE
);
463 tc
->setMiscRegNoEffect(MISCREG_CAUSE
, cause
);
466 // Offset 0x180 - General Exception Vector
467 HandlerBase
= vect() + tc
->readMiscReg(MISCREG_EBASE
);
468 setHandlerPC(HandlerBase
, tc
);
471 warn("%s (CP%d) encountered.\n", name(), coProcID
);
475 } // namespace MipsISA