gem5 v23.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met: redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer;
11 * redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution;
14 * neither the name of the copyright holders nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef __ARCH_RISCV_FAULTS_HH__
32#define __ARCH_RISCV_FAULTS_HH__
33
34#include <cstdint>
35#include <string>
36
37#include "arch/riscv/isa.hh"
39#include "sim/faults.hh"
40
41namespace gem5
42{
43
44class ThreadContext;
45
46namespace RiscvISA
47{
48
49enum FloatException : uint64_t
50{
55 FloatInvalid = 0x10
56};
57
58/*
59 * In RISC-V, exception and interrupt codes share some values. They can be
60 * differentiated by an 'Interrupt' flag that is enabled for interrupt faults
61 * but not exceptions. The full fault cause can be computed by placing the
62 * exception (or interrupt) code in the least significant bits of the CAUSE
63 * CSR and then setting the highest bit of CAUSE with the 'Interrupt' flag.
64 * For more details on exception causes, see Chapter 3.1.20 of the RISC-V
65 * privileged specification v 1.10. Codes are enumerated in Table 3.6.
66 */
67enum ExceptionCode : uint64_t
68{
86
97 // INT_NMI does not exist in the spec, it's a modeling artifact for NMI. We
98 // intentionally set it to be NumInterruptTypes so it can never conflict
99 // with any real INT_NUM in used.
101};
102
103enum class FaultType
104{
105 INTERRUPT,
107 OTHERS,
108};
109
110class RiscvFault : public FaultBase
111{
112 protected:
116
118 : _name(n), _fault_type(ft), _code(c)
119 {}
120
121 FaultName name() const override { return _name; }
122 bool isInterrupt() const { return _fault_type == FaultType::INTERRUPT; }
124 {
126 }
127 ExceptionCode exception() const { return _code; }
128 virtual RegVal trap_value() const { return 0; }
129
130 virtual void invokeSE(ThreadContext *tc, const StaticInstPtr &inst);
131 void invoke(ThreadContext *tc, const StaticInstPtr &inst) override;
132};
133
134class Reset : public FaultBase
135{
136 private:
138
139 public:
140 Reset() : _name("reset") {}
141 FaultName name() const override { return _name; }
142
143 void invoke(ThreadContext *tc, const StaticInstPtr &inst =
144 nullStaticInstPtr) override;
145};
146
148{
149 public:
151 : RiscvFault("interrupt", FaultType::INTERRUPT, c)
152 {}
154};
155
157{
158 public:
160 : RiscvFault("non_maskable_interrupt",
162 static_cast<ExceptionCode>(0))
163 {}
164};
165
166class InstFault : public RiscvFault
167{
168 protected:
170
171 public:
174 {}
175
176 RegVal trap_value() const override { return bits(_inst, 31, 0); }
177};
178
180{
181 public:
183 : InstFault("Unknown instruction", inst)
184 {}
185
186 void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override;
187};
188
190{
191 private:
192 const std::string reason;
193
194 public:
195 IllegalInstFault(std::string r, const ExtMachInst inst)
196 : InstFault("Illegal instruction", inst),
197 reason(r)
198 {}
199
200 void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override;
201};
202
204{
205 private:
206 const std::string instName;
207
208 public:
209 UnimplementedFault(std::string name, const ExtMachInst inst)
210 : InstFault("Unimplemented instruction", inst),
212 {}
213
214 void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override;
215};
216
218{
219 private:
220 const uint8_t frm;
221
222 public:
223 IllegalFrmFault(uint8_t r, const ExtMachInst inst)
224 : InstFault("Illegal floating-point rounding mode", inst),
225 frm(r)
226 {}
227
228 void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override;
229};
230
232{
233 private:
234 const Addr _addr;
235
236 public:
238 : RiscvFault("Address", FaultType::OTHERS, code), _addr(addr)
239 {}
240
241 RegVal trap_value() const override { return _addr; }
242};
243
245{
246 private:
248
249 public:
251 : RiscvFault("Breakpoint", FaultType::OTHERS, BREAKPOINT),
252 pcState(pc.as<PCState>())
253 {}
254
255 RegVal trap_value() const override { return pcState.pc(); }
256 void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override;
257};
258
260{
261 public:
263 : RiscvFault("System call", FaultType::OTHERS, ECALL_USER)
264 {
265 switch (prv) {
266 case PRV_U:
268 break;
269 case PRV_S:
271 break;
272 case PRV_M:
274 break;
275 default:
276 panic("Unknown privilege mode %d.", prv);
277 break;
278 }
279 }
280
281 void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override;
282};
283
284} // namespace RiscvISA
285} // namespace gem5
286
287#endif // __ARCH_RISCV_FAULTS_HH__
RegVal trap_value() const override
Definition faults.hh:241
AddressFault(const Addr addr, ExceptionCode code)
Definition faults.hh:237
BreakpointFault(const PCStateBase &pc)
Definition faults.hh:250
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition faults.cc:228
RegVal trap_value() const override
Definition faults.hh:255
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition faults.cc:221
IllegalFrmFault(uint8_t r, const ExtMachInst inst)
Definition faults.hh:223
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition faults.cc:207
IllegalInstFault(std::string r, const ExtMachInst inst)
Definition faults.hh:195
RegVal trap_value() const override
Definition faults.hh:176
InstFault(FaultName n, const ExtMachInst inst)
Definition faults.hh:172
const ExtMachInst _inst
Definition faults.hh:169
InterruptFault(ExceptionCode c)
Definition faults.hh:150
void invoke(ThreadContext *tc, const StaticInstPtr &inst=nullStaticInstPtr) override
Definition faults.cc:173
FaultName name() const override
Definition faults.hh:141
const FaultName _name
Definition faults.hh:137
RiscvFault(FaultName n, FaultType ft, ExceptionCode c)
Definition faults.hh:117
bool isInterrupt() const
Definition faults.hh:122
virtual void invokeSE(ThreadContext *tc, const StaticInstPtr &inst)
Definition faults.cc:54
ExceptionCode exception() const
Definition faults.hh:127
const FaultType _fault_type
Definition faults.hh:114
void invoke(ThreadContext *tc, const StaticInstPtr &inst) override
Definition faults.cc:60
FaultName name() const override
Definition faults.hh:121
bool isNonMaskableInterrupt() const
Definition faults.hh:123
const FaultName _name
Definition faults.hh:113
virtual RegVal trap_value() const
Definition faults.hh:128
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition faults.cc:234
SyscallFault(PrivilegeMode prv)
Definition faults.hh:262
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition faults.cc:215
UnimplementedFault(std::string name, const ExtMachInst inst)
Definition faults.hh:209
UnknownInstFault(const ExtMachInst inst)
Definition faults.hh:182
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition faults.cc:199
ThreadContext is the external interface to all thread state for anything outside of the CPU.
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition bitfield.hh:76
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 31 > n
Bitfield< 36 > as
Bitfield< 4 > pc
Bitfield< 5, 3 > c
@ STORE_ADDR_MISALIGNED
Definition faults.hh:75
@ AMO_ADDR_MISALIGNED
Definition faults.hh:76
@ INST_ADDR_MISALIGNED
Definition faults.hh:69
@ INT_TIMER_MACHINE
Definition faults.hh:92
@ INT_SOFTWARE_SUPER
Definition faults.hh:88
@ INT_SOFTWARE_MACHINE
Definition faults.hh:89
@ INT_SOFTWARE_USER
Definition faults.hh:87
@ LOAD_ADDR_MISALIGNED
Definition faults.hh:73
@ NumInterruptTypes
Definition faults.hh:96
Bitfield< 1 > r
Definition pagetable.hh:75
Bitfield< 3 > addr
Definition types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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
uint64_t RegVal
Definition types.hh:173
const StaticInstPtr nullStaticInstPtr
Statically allocated null StaticInstPtr.

Generated on Mon Jul 10 2023 14:24:26 for gem5 by doxygen 1.9.7