gem5  [DEVELOP-FOR-23.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"
38 #include "cpu/null_static_inst.hh"
39 #include "sim/faults.hh"
40 
41 namespace gem5
42 {
43 
44 class ThreadContext;
45 
46 namespace RiscvISA
47 {
48 
49 enum FloatException : uint64_t
50 {
51  FloatInexact = 0x1,
54  FloatDivZero = 0x8,
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  */
67 enum ExceptionCode : uint64_t
68 {
82  INST_PAGE = 12,
83  LOAD_PAGE = 13,
84  STORE_PAGE = 15,
85  AMO_PAGE = 15,
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 
103 enum class FaultType
104 {
105  INTERRUPT,
107  OTHERS,
108 };
109 
110 class 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 
134 class 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  {}
153  InterruptFault(int c) : InterruptFault(static_cast<ExceptionCode>(c)) {}
154 };
155 
157 {
158  public:
160  : RiscvFault("non_maskable_interrupt",
162  static_cast<ExceptionCode>(0))
163  {}
164 };
165 
166 class 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),
211  instName(name)
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 
231 class AddressFault : public RiscvFault
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 
259 class SyscallFault : public RiscvFault
260 {
261  public:
263  : RiscvFault("System call", FaultType::OTHERS, ECALL_USER)
264  {
265  switch (prv) {
266  case PRV_U:
267  _code = ECALL_USER;
268  break;
269  case PRV_S:
270  _code = ECALL_SUPER;
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__
gem5::GenericISA::PCStateWithNext::pc
Addr pc() const
Definition: pcstate.hh:263
gem5::RiscvISA::PRV_S
@ PRV_S
Definition: isa.hh:58
gem5::RiscvISA::INT_EXT_MACHINE
@ INT_EXT_MACHINE
Definition: faults.hh:95
gem5::RiscvISA::FaultType::INTERRUPT
@ INTERRUPT
gem5::RiscvISA::UnimplementedFault::instName
const std::string instName
Definition: faults.hh:206
gem5::RiscvISA::INT_TIMER_USER
@ INT_TIMER_USER
Definition: faults.hh:90
gem5::RiscvISA::INT_TIMER_SUPER
@ INT_TIMER_SUPER
Definition: faults.hh:91
gem5::RiscvISA::PRV_M
@ PRV_M
Definition: isa.hh:59
gem5::RegVal
uint64_t RegVal
Definition: types.hh:173
gem5::RiscvISA::FloatDivZero
@ FloatDivZero
Definition: faults.hh:54
gem5::RiscvISA::LOAD_PAGE
@ LOAD_PAGE
Definition: faults.hh:83
gem5::RiscvISA::RiscvFault::_fault_type
const FaultType _fault_type
Definition: faults.hh:114
gem5::RiscvISA::INT_EXT_USER
@ INT_EXT_USER
Definition: faults.hh:93
gem5::RiscvISA::RiscvFault::_name
const FaultName _name
Definition: faults.hh:113
gem5::RiscvISA::RiscvFault::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst) override
Definition: faults.cc:60
gem5::RiscvISA::BreakpointFault::BreakpointFault
BreakpointFault(const PCStateBase &pc)
Definition: faults.hh:250
gem5::RiscvISA::AddressFault::trap_value
RegVal trap_value() const override
Definition: faults.hh:241
gem5::RiscvISA::PrivilegeMode
PrivilegeMode
Definition: isa.hh:55
gem5::RiscvISA::BREAKPOINT
@ BREAKPOINT
Definition: faults.hh:72
gem5::RiscvISA::IllegalFrmFault::frm
const uint8_t frm
Definition: faults.hh:220
gem5::RiscvISA::INT_SOFTWARE_USER
@ INT_SOFTWARE_USER
Definition: faults.hh:87
gem5::RiscvISA::NonMaskableInterruptFault
Definition: faults.hh:156
gem5::RiscvISA::FloatInexact
@ FloatInexact
Definition: faults.hh:51
gem5::RiscvISA::BreakpointFault::trap_value
RegVal trap_value() const override
Definition: faults.hh:255
gem5::RiscvISA::RiscvFault::isInterrupt
bool isInterrupt() const
Definition: faults.hh:122
gem5::RiscvISA::AddressFault::AddressFault
AddressFault(const Addr addr, ExceptionCode code)
Definition: faults.hh:237
faults.hh
gem5::RiscvISA::c
Bitfield< 5, 3 > c
Definition: pra_constants.hh:59
gem5::RiscvISA::AddressFault::_addr
const Addr _addr
Definition: faults.hh:234
isa.hh
gem5::ArmISA::as
Bitfield< 36 > as
Definition: misc_types.hh:565
gem5::RefCountingPtr
If you want a reference counting pointer to a mutable object, create it like this:
Definition: refcnt.hh:126
gem5::RiscvISA::Reset
Definition: faults.hh:134
gem5::RiscvISA::PCState
Definition: pcstate.hh:57
gem5::RiscvISA::INT_EXT_SUPER
@ INT_EXT_SUPER
Definition: faults.hh:94
gem5::RiscvISA::STORE_ADDR_MISALIGNED
@ STORE_ADDR_MISALIGNED
Definition: faults.hh:75
gem5::RiscvISA::NonMaskableInterruptFault::NonMaskableInterruptFault
NonMaskableInterruptFault()
Definition: faults.hh:159
gem5::RiscvISA::IllegalInstFault::IllegalInstFault
IllegalInstFault(std::string r, const ExtMachInst inst)
Definition: faults.hh:195
gem5::nullStaticInstPtr
const StaticInstPtr nullStaticInstPtr
Statically allocated null StaticInstPtr.
Definition: null_static_inst.cc:36
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
gem5::RiscvISA::LOAD_ACCESS
@ LOAD_ACCESS
Definition: faults.hh:74
gem5::RiscvISA::FloatUnderflow
@ FloatUnderflow
Definition: faults.hh:52
gem5::RiscvISA::LOAD_ADDR_MISALIGNED
@ LOAD_ADDR_MISALIGNED
Definition: faults.hh:73
gem5::RiscvISA::InstFault::trap_value
RegVal trap_value() const override
Definition: faults.hh:176
gem5::RiscvISA::INT_TIMER_MACHINE
@ INT_TIMER_MACHINE
Definition: faults.hh:92
gem5::RiscvISA::UnimplementedFault::UnimplementedFault
UnimplementedFault(std::string name, const ExtMachInst inst)
Definition: faults.hh:209
gem5::RiscvISA::RiscvFault
Definition: faults.hh:110
gem5::RiscvISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:243
gem5::RiscvISA::Reset::Reset
Reset()
Definition: faults.hh:140
gem5::RiscvISA::ECALL_MACHINE
@ ECALL_MACHINE
Definition: faults.hh:81
gem5::RiscvISA::INST_ACCESS
@ INST_ACCESS
Definition: faults.hh:70
gem5::RiscvISA::RiscvFault::name
FaultName name() const override
Definition: faults.hh:121
gem5::RiscvISA::IllegalInstFault::reason
const std::string reason
Definition: faults.hh:192
gem5::RiscvISA::INT_SOFTWARE_SUPER
@ INT_SOFTWARE_SUPER
Definition: faults.hh:88
gem5::RiscvISA::INST_PAGE
@ INST_PAGE
Definition: faults.hh:82
gem5::RiscvISA::RiscvFault::RiscvFault
RiscvFault(FaultName n, FaultType ft, ExceptionCode c)
Definition: faults.hh:117
gem5::RiscvISA::FaultType
FaultType
Definition: faults.hh:103
gem5::RiscvISA::IllegalFrmFault
Definition: faults.hh:217
gem5::RiscvISA::STORE_ACCESS
@ STORE_ACCESS
Definition: faults.hh:77
gem5::RiscvISA::RiscvFault::_code
ExceptionCode _code
Definition: faults.hh:115
gem5::RiscvISA::NumInterruptTypes
@ NumInterruptTypes
Definition: faults.hh:96
gem5::bits
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
gem5::RiscvISA::r
Bitfield< 1 > r
Definition: pagetable.hh:75
gem5::RiscvISA::Reset::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=nullStaticInstPtr) override
Definition: faults.cc:174
gem5::RiscvISA::InstFault
Definition: faults.hh:166
gem5::RiscvISA::ExceptionCode
ExceptionCode
Definition: faults.hh:67
gem5::RiscvISA::BreakpointFault::pcState
const PCState pcState
Definition: faults.hh:247
gem5::RiscvISA::ECALL_SUPER
@ ECALL_SUPER
Definition: faults.hh:80
null_static_inst.hh
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::RiscvISA::AMO_ADDR_MISALIGNED
@ AMO_ADDR_MISALIGNED
Definition: faults.hh:76
gem5::RiscvISA::INT_SOFTWARE_MACHINE
@ INT_SOFTWARE_MACHINE
Definition: faults.hh:89
gem5::RiscvISA::UnknownInstFault::UnknownInstFault
UnknownInstFault(const ExtMachInst inst)
Definition: faults.hh:182
gem5::RiscvISA::InstFault::InstFault
InstFault(FaultName n, const ExtMachInst inst)
Definition: faults.hh:172
gem5::RiscvISA::Reset::_name
const FaultName _name
Definition: faults.hh:137
gem5::RiscvISA::IllegalInstFault
Definition: faults.hh:189
gem5::FaultName
const typedef char * FaultName
Definition: faults.hh:53
gem5::RiscvISA::UnknownInstFault::invokeSE
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition: faults.cc:200
gem5::RiscvISA::AMO_PAGE
@ AMO_PAGE
Definition: faults.hh:85
gem5::X86ISA::ExtMachInst
Definition: types.hh:212
gem5::RiscvISA::InterruptFault::InterruptFault
InterruptFault(int c)
Definition: faults.hh:153
gem5::RiscvISA::ECALL_USER
@ ECALL_USER
Definition: faults.hh:79
gem5::RiscvISA::UnknownInstFault
Definition: faults.hh:179
gem5::RiscvISA::FloatInvalid
@ FloatInvalid
Definition: faults.hh:55
gem5::RiscvISA::BreakpointFault
Definition: faults.hh:244
gem5::RiscvISA::IllegalFrmFault::invokeSE
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition: faults.cc:222
gem5::RiscvISA::STORE_PAGE
@ STORE_PAGE
Definition: faults.hh:84
gem5::RiscvISA::FaultType::NON_MASKABLE_INTERRUPT
@ NON_MASKABLE_INTERRUPT
gem5::RiscvISA::FloatOverflow
@ FloatOverflow
Definition: faults.hh:53
gem5::FaultBase
Definition: translation_gen.test.cc:49
gem5::ArmISA::n
Bitfield< 31 > n
Definition: misc_types.hh:513
gem5::RiscvISA::SyscallFault::invokeSE
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition: faults.cc:235
gem5::RiscvISA::RiscvFault::exception
ExceptionCode exception() const
Definition: faults.hh:127
gem5::RiscvISA::AddressFault
Definition: faults.hh:231
gem5::RiscvISA::FloatException
FloatException
Definition: faults.hh:49
gem5::RiscvISA::BreakpointFault::invokeSE
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition: faults.cc:229
gem5::RiscvISA::UnimplementedFault
Definition: faults.hh:203
gem5::RiscvISA::IllegalInstFault::invokeSE
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition: faults.cc:208
gem5::RiscvISA::InterruptFault
Definition: faults.hh:147
gem5::RiscvISA::SyscallFault::SyscallFault
SyscallFault(PrivilegeMode prv)
Definition: faults.hh:262
gem5::RiscvISA::InterruptFault::InterruptFault
InterruptFault(ExceptionCode c)
Definition: faults.hh:150
gem5::RiscvISA::PRV_U
@ PRV_U
Definition: isa.hh:57
gem5::RiscvISA::RiscvFault::trap_value
virtual RegVal trap_value() const
Definition: faults.hh:128
gem5::RiscvISA::INT_NMI
@ INT_NMI
Definition: faults.hh:100
gem5::RiscvISA::INST_ILLEGAL
@ INST_ILLEGAL
Definition: faults.hh:71
gem5::PCStateBase
Definition: pcstate.hh:57
gem5::RiscvISA::Reset::name
FaultName name() const override
Definition: faults.hh:141
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::RiscvISA::SyscallFault
Definition: faults.hh:259
gem5::RiscvISA::UnimplementedFault::invokeSE
void invokeSE(ThreadContext *tc, const StaticInstPtr &inst) override
Definition: faults.cc:216
gem5::RiscvISA::IllegalFrmFault::IllegalFrmFault
IllegalFrmFault(uint8_t r, const ExtMachInst inst)
Definition: faults.hh:223
gem5::RiscvISA::FaultType::OTHERS
@ OTHERS
gem5::RiscvISA::RiscvFault::invokeSE
virtual void invokeSE(ThreadContext *tc, const StaticInstPtr &inst)
Definition: faults.cc:54
gem5::RiscvISA::RiscvFault::isNonMaskableInterrupt
bool isNonMaskableInterrupt() const
Definition: faults.hh:123
gem5::RiscvISA::AMO_ACCESS
@ AMO_ACCESS
Definition: faults.hh:78
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:188
gem5::RiscvISA::InstFault::_inst
const ExtMachInst _inst
Definition: faults.hh:169
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84
gem5::RiscvISA::INST_ADDR_MISALIGNED
@ INST_ADDR_MISALIGNED
Definition: faults.hh:69

Generated on Sun Jul 30 2023 01:56:47 for gem5 by doxygen 1.8.17