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
<SystemCallFault
>::vals
=
65 { "Syscall", 0x0180 };
67 template <> FaultVals MipsFault
<CoprocessorUnusableFault
>::vals
=
68 { "Coprocessor Unusable Fault", 0x180 };
70 template <> FaultVals MipsFault
<ReservedInstructionFault
>::vals
=
71 { "Reserved Instruction Fault", 0x0180 };
73 template <> FaultVals MipsFault
<ThreadFault
>::vals
=
74 { "Thread Fault", 0x00F1 };
76 template <> FaultVals MipsFault
<IntegerOverflowFault
>::vals
=
77 { "Integer Overflow Exception", 0x180 };
79 template <> FaultVals MipsFault
<InterruptFault
>::vals
=
80 { "interrupt", 0x0180 };
82 template <> FaultVals MipsFault
<TrapFault
>::vals
=
85 template <> FaultVals MipsFault
<BreakpointFault
>::vals
=
86 { "Breakpoint", 0x0180 };
88 template <> FaultVals MipsFault
<TlbInvalidFault
>::vals
=
89 { "Invalid TLB Entry Exception", 0x0180 };
91 template <> FaultVals MipsFault
<TlbRefillFault
>::vals
=
92 { "TLB Refill Exception", 0x0180 };
94 template <> FaultVals MipsFault
<TlbModifiedFault
>::vals
=
95 { "TLB Modified Exception", 0x0180 };
97 template <> FaultVals MipsFault
<DspStateDisabledFault
>::vals
=
98 { "DSP Disabled Fault", 0x001a };
101 MipsFaultBase::setExceptionState(ThreadContext
*tc
, uint8_t excCode
)
103 // modify SRS Ctl - Save CSS, put ESS into CSS
104 StatusReg status
= tc
->readMiscReg(MISCREG_STATUS
);
105 if (status
.exl
!= 1 && status
.bev
!= 1) {
106 // SRS Ctl is modified only if Status_EXL and Status_BEV are not set
107 SRSCtlReg srsCtl
= tc
->readMiscReg(MISCREG_SRSCTL
);
108 srsCtl
.pss
= srsCtl
.css
;
109 srsCtl
.css
= srsCtl
.ess
;
110 tc
->setMiscRegNoEffect(MISCREG_SRSCTL
, srsCtl
);
113 // set EXL bit (don't care if it is already set!)
115 tc
->setMiscRegNoEffect(MISCREG_STATUS
, status
);
118 PCState pc
= tc
->pcState();
119 DPRINTF(MipsPRA
, "PC: %s\n", pc
);
120 bool delay_slot
= pc
.pc() + sizeof(MachInst
) != pc
.npc();
121 tc
->setMiscRegNoEffect(MISCREG_EPC
,
122 pc
.pc() - delay_slot
? sizeof(MachInst
) : 0);
124 // Set Cause_EXCCODE field
125 CauseReg cause
= tc
->readMiscReg(MISCREG_CAUSE
);
126 cause
.excCode
= excCode
;
127 cause
.bd
= delay_slot
? 1 : 0;
129 tc
->setMiscRegNoEffect(MISCREG_CAUSE
, cause
);
135 IntegerOverflowFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
137 DPRINTF(MipsPRA
, "%s encountered.\n", name());
138 setExceptionState(tc
, 0xC);
141 StatusReg status
= tc
->readMiscReg(MISCREG_STATUS
);
143 // See MIPS ARM Vol 3, Revision 2, Page 38
144 tc
->pcState(vect() + tc
->readMiscReg(MISCREG_EBASE
));
146 tc
->pcState(0xBFC00200);
151 TrapFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
153 DPRINTF(MipsPRA
, "%s encountered.\n", name());
154 setExceptionState(tc
, 0xD);
156 tc
->pcState(vect() + tc
->readMiscReg(MISCREG_EBASE
));
160 BreakpointFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
162 setExceptionState(tc
, 0x9);
164 tc
->pcState(vect() + tc
->readMiscReg(MISCREG_EBASE
));
168 AddressErrorFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
170 DPRINTF(MipsPRA
, "%s encountered.\n", name());
171 setExceptionState(tc
, store
? 0x5 : 0x4);
172 tc
->setMiscRegNoEffect(MISCREG_BADVADDR
, vaddr
);
174 tc
->pcState(vect() + tc
->readMiscReg(MISCREG_EBASE
));
178 TlbInvalidFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
180 setTlbExceptionState(tc
, store
? 0x3 : 0x2);
181 tc
->pcState(vect() + tc
->readMiscReg(MISCREG_EBASE
));
185 TlbRefillFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
187 // Since handler depends on EXL bit, must check EXL bit before setting it!!
188 StatusReg status
= tc
->readMiscReg(MISCREG_STATUS
);
190 setTlbExceptionState(tc
, store
? 0x3 : 0x2);
192 // See MIPS ARM Vol 3, Revision 2, Page 38
193 if (status
.exl
== 1) {
194 tc
->pcState(vect() + tc
->readMiscReg(MISCREG_EBASE
));
196 tc
->pcState(tc
->readMiscReg(MISCREG_EBASE
));
201 TlbModifiedFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
203 setTlbExceptionState(tc
, 0x1);
205 tc
->pcState(vect() + tc
->readMiscReg(MISCREG_EBASE
));
209 SystemCallFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
211 DPRINTF(MipsPRA
, "%s encountered.\n", name());
212 setExceptionState(tc
, 0x8);
214 tc
->pcState(vect() + tc
->readMiscReg(MISCREG_EBASE
));
218 InterruptFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
220 DPRINTF(MipsPRA
, "%s encountered.\n", name());
221 setExceptionState(tc
, 0x0A);
223 CauseReg cause
= tc
->readMiscRegNoEffect(MISCREG_CAUSE
);
225 // Offset 200 for release 2
226 tc
->pcState(0x20 + vect() + tc
->readMiscRegNoEffect(MISCREG_EBASE
));
228 //Ofset at 180 for release 1
229 tc
->pcState(vect() + tc
->readMiscRegNoEffect(MISCREG_EBASE
));
233 #endif // FULL_SYSTEM
236 ResetFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
239 DPRINTF(MipsPRA
, "%s encountered.\n", name());
240 /* All reset activity must be invoked from here */
242 DPRINTF(MipsPRA
, "ResetFault::invoke : PC set to %x", tc
->readPC());
245 // Set Coprocessor 1 (Floating Point) To Usable
246 StatusReg status
= tc
->readMiscRegNoEffect(MISCREG_STATUS
);
248 tc
->setMiscReg(MISCREG_STATUS
, status
);
252 ReservedInstructionFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
255 DPRINTF(MipsPRA
, "%s encountered.\n", name());
256 setExceptionState(tc
, 0x0A);
257 tc
->pcState(vect() + tc
->readMiscRegNoEffect(MISCREG_EBASE
));
259 panic("%s encountered.\n", name());
264 ThreadFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
266 DPRINTF(MipsPRA
, "%s encountered.\n", name());
267 panic("%s encountered.\n", name());
271 DspStateDisabledFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
273 DPRINTF(MipsPRA
, "%s encountered.\n", name());
274 panic("%s encountered.\n", name());
278 CoprocessorUnusableFault::invoke(ThreadContext
*tc
, StaticInstPtr inst
)
281 DPRINTF(MipsPRA
, "%s encountered.\n", name());
282 setExceptionState(tc
, 0xb);
283 // The ID of the coprocessor causing the exception is stored in
284 // CoprocessorUnusableFault::coProcID
285 CauseReg cause
= tc
->readMiscReg(MISCREG_CAUSE
);
287 tc
->setMiscRegNoEffect(MISCREG_CAUSE
, cause
);
288 tc
->pcState(vect() + tc
->readMiscReg(MISCREG_EBASE
));
290 warn("%s (CP%d) encountered.\n", name(), coProcID
);
294 } // namespace MipsISA