gem5 v24.0.0.0
Loading...
Searching...
No Matches
faults.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 RISC-V Foundation
3 * Copyright (c) 2016 The University of Virginia
4 * Copyright (c) 2018 TU Dresden
5 * Copyright (c) 2024 University of Rostock
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met: redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer;
12 * redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution;
15 * neither the name of the copyright holders nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef __ARCH_RISCV_FAULTS_HH__
33#define __ARCH_RISCV_FAULTS_HH__
34
35#include <cstdint>
36#include <string>
37
38#include "arch/riscv/isa.hh"
40#include "sim/faults.hh"
41
42namespace gem5
43{
44
45class ThreadContext;
46
47namespace RiscvISA
48{
49
50enum FloatException : uint64_t
51{
56 FloatInvalid = 0x10
57};
58
59/*
60 * In RISC-V, exception and interrupt codes share some values. They can be
61 * differentiated by an 'Interrupt' flag that is enabled for interrupt faults
62 * but not exceptions. The full fault cause can be computed by placing the
63 * exception (or interrupt) code in the least significant bits of the CAUSE
64 * CSR and then setting the highest bit of CAUSE with the 'Interrupt' flag.
65 * For more details on exception causes, see Chapter 3.1.20 of the RISC-V
66 * privileged specification v 1.10. Codes are enumerated in Table 3.6.
67 */
68enum ExceptionCode : uint64_t
69{
87
146 // INT_NMI does not exist in the spec, it's a modeling artifact for NMI. We
147 // intentionally set it to be NumInterruptTypes so it can never conflict
148 // with any real INT_NUM in used.
150};
151
152enum class FaultType
153{
154 INTERRUPT,
156 OTHERS,
157};
158
159class RiscvFault : public FaultBase
160{
161 protected:
165
169
170 FaultName name() const override { return _name; }
171 bool isInterrupt() const { return _fault_type == FaultType::INTERRUPT; }
176 ExceptionCode exception() const { return _code; }
177 virtual RegVal trap_value() const { return 0; }
178
179 virtual void invokeSE(ThreadContext *tc, const StaticInstPtr &inst);
180 void invoke(ThreadContext *tc, const StaticInstPtr &inst) override;
181};
182
183class Reset : public FaultBase
184{
185 private:
187
188 public:
189 Reset() : _name("reset") {}
190 FaultName name() const override { return _name; }
191
192 void invoke(ThreadContext *tc, const StaticInstPtr &inst =
193 nullStaticInstPtr) override;
194};
195
197{
198 public:
203};
204
206{
207 public:
209 : RiscvFault("non_maskable_interrupt",
211 static_cast<ExceptionCode>(0))
212 {}
213};
214
215class InstFault : public RiscvFault
216{
217 protected:
219
220 public:
224
225 RegVal trap_value() const override { return _inst.instBits; }
226};
227
229{
230 public:
232 : InstFault("Unknown instruction", inst)
233 {}
234
235 void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override;
236};
237
239{
240 private:
241 const std::string reason;
242
243 public:
244 IllegalInstFault(std::string r, const ExtMachInst inst)
245 : InstFault("Illegal instruction", inst),
246 reason(r)
247 {}
248
249 void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override;
250};
251
253{
254 private:
255 const std::string instName;
256
257 public:
258 UnimplementedFault(std::string name, const ExtMachInst inst)
259 : InstFault("Unimplemented instruction", inst),
261 {}
262
263 void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override;
264};
265
267{
268 private:
269 const uint8_t frm;
270
271 public:
272 IllegalFrmFault(uint8_t r, const ExtMachInst inst)
273 : InstFault("Illegal floating-point rounding mode", inst),
274 frm(r)
275 {}
276
277 void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override;
278};
279
281{
282 private:
283 const Addr _addr;
284
285 public:
287 : RiscvFault("Address", FaultType::OTHERS, code), _addr(addr)
288 {}
289
290 RegVal trap_value() const override { return _addr; }
291};
292
294{
295 private:
297
298 public:
300 : RiscvFault("Breakpoint", FaultType::OTHERS, BREAKPOINT),
301 pcState(pc.as<PCState>())
302 {}
303
304 RegVal trap_value() const override { return pcState.pc(); }
305 void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override;
306};
307
309{
310 public:
312 : RiscvFault("System call", FaultType::OTHERS, ECALL_USER)
313 {
314 switch (prv) {
315 case PRV_U:
317 break;
318 case PRV_S:
320 break;
321 case PRV_M:
323 break;
324 default:
325 panic("Unknown privilege mode %d.", prv);
326 break;
327 }
328 }
329
330 void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override;
331};
332
343bool getFaultVAddr(Fault fault, Addr &va);
344
345} // namespace RiscvISA
346} // namespace gem5
347
348#endif // __ARCH_RISCV_FAULTS_HH__
RegVal trap_value() const override
Definition faults.hh:290
AddressFault(const Addr addr, ExceptionCode code)
Definition faults.hh:286
BreakpointFault(const PCStateBase &pc)
Definition faults.hh:299
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition faults.cc:232
RegVal trap_value() const override
Definition faults.hh:304
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition faults.cc:225
IllegalFrmFault(uint8_t r, const ExtMachInst inst)
Definition faults.hh:272
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition faults.cc:209
IllegalInstFault(std::string r, const ExtMachInst inst)
Definition faults.hh:244
RegVal trap_value() const override
Definition faults.hh:225
InstFault(FaultName n, const ExtMachInst inst)
Definition faults.hh:221
const ExtMachInst _inst
Definition faults.hh:218
InterruptFault(ExceptionCode c)
Definition faults.hh:199
void invoke(ThreadContext *tc, const StaticInstPtr &inst=nullStaticInstPtr) override
Definition faults.cc:171
FaultName name() const override
Definition faults.hh:190
const FaultName _name
Definition faults.hh:186
RiscvFault(FaultName n, FaultType ft, ExceptionCode c)
Definition faults.hh:166
bool isInterrupt() const
Definition faults.hh:171
virtual void invokeSE(ThreadContext *tc, const StaticInstPtr &inst)
Definition faults.cc:54
ExceptionCode exception() const
Definition faults.hh:176
const FaultType _fault_type
Definition faults.hh:163
void invoke(ThreadContext *tc, const StaticInstPtr &inst) override
Definition faults.cc:60
FaultName name() const override
Definition faults.hh:170
bool isNonMaskableInterrupt() const
Definition faults.hh:172
const FaultName _name
Definition faults.hh:162
virtual RegVal trap_value() const
Definition faults.hh:177
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition faults.cc:240
SyscallFault(PrivilegeMode prv)
Definition faults.hh:311
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition faults.cc:219
UnimplementedFault(std::string name, const ExtMachInst inst)
Definition faults.hh:258
UnknownInstFault(const ExtMachInst inst)
Definition faults.hh:231
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition faults.cc:201
ThreadContext is the external interface to all thread state for anything outside of the CPU.
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 31 > n
Bitfield< 36 > as
Bitfield< 8 > va
bool getFaultVAddr(Fault fault, Addr &va)
Returns true if the fault passed as a first argument was triggered by a memory access,...
Definition faults.cc:252
Bitfield< 4 > pc
Bitfield< 5, 3 > c
@ STORE_ADDR_MISALIGNED
Definition faults.hh:76
@ AMO_ADDR_MISALIGNED
Definition faults.hh:77
@ INST_ADDR_MISALIGNED
Definition faults.hh:70
@ INT_TIMER_MACHINE
Definition faults.hh:93
@ INT_SOFTWARE_SUPER
Definition faults.hh:89
@ INT_SOFTWARE_MACHINE
Definition faults.hh:90
@ INT_SOFTWARE_USER
Definition faults.hh:88
@ LOAD_ADDR_MISALIGNED
Definition faults.hh:74
Bitfield< 1 > r
Definition pagetable.hh:75
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
uint64_t RegVal
Definition types.hh:173
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
const char * FaultName
Definition faults.hh:55
const StaticInstPtr nullStaticInstPtr
Statically allocated null StaticInstPtr.

Generated on Tue Jun 18 2024 16:23:57 for gem5 by doxygen 1.11.0