gem5
v19.0.0.0
Main Page
Related Pages
Modules
+
Namespaces
Namespace List
+
Namespace Members
+
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Functions
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
+
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Typedefs
a
b
c
d
e
f
g
h
i
m
n
o
p
r
s
t
u
v
w
x
+
Enumerations
a
b
c
d
e
f
i
l
m
o
p
r
s
t
v
x
+
Enumerator
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
+
Classes
Class List
Class Index
Class Hierarchy
+
Class Members
+
All
:
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
+
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
+
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Typedefs
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
y
+
Enumerations
a
b
c
d
e
f
g
h
i
l
m
o
p
r
s
t
u
w
+
Enumerator
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
+
Related Functions
:
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
+
Files
File List
+
File Members
+
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
+
Functions
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
z
+
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
z
+
Typedefs
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
v
w
+
Enumerations
a
b
c
d
e
f
g
i
l
m
o
p
r
s
t
v
w
+
Enumerator
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
w
x
+
Macros
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
arch
riscv
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
* Authors: Alec Roelke
31
* Robert Scheffel
32
*/
33
34
#ifndef __ARCH_RISCV_FAULTS_HH__
35
#define __ARCH_RISCV_FAULTS_HH__
36
37
#include <string>
38
39
#include "
arch/riscv/isa.hh
"
40
#include "
arch/riscv/registers.hh
"
41
#include "
cpu/thread_context.hh
"
42
#include "
sim/faults.hh
"
43
44
namespace
RiscvISA
45
{
46
47
enum
FloatException
: uint64_t {
48
FloatInexact
= 0x1,
49
FloatUnderflow
= 0x2,
50
FloatOverflow
= 0x4,
51
FloatDivZero
= 0x8,
52
FloatInvalid
= 0x10
53
};
54
55
/*
56
* In RISC-V, exception and interrupt codes share some values. They can be
57
* differentiated by an 'Interrupt' flag that is enabled for interrupt faults
58
* but not exceptions. The full fault cause can be computed by placing the
59
* exception (or interrupt) code in the least significant bits of the CAUSE
60
* CSR and then setting the highest bit of CAUSE with the 'Interrupt' flag.
61
* For more details on exception causes, see Chapter 3.1.20 of the RISC-V
62
* privileged specification v 1.10. Codes are enumerated in Table 3.6.
63
*/
64
enum
ExceptionCode
: uint64_t {
65
INST_ADDR_MISALIGNED
= 0,
66
INST_ACCESS
= 1,
67
INST_ILLEGAL
= 2,
68
BREAKPOINT
= 3,
69
LOAD_ADDR_MISALIGNED
= 4,
70
LOAD_ACCESS
= 5,
71
STORE_ADDR_MISALIGNED
= 6,
72
AMO_ADDR_MISALIGNED
= 6,
73
STORE_ACCESS
= 7,
74
AMO_ACCESS
= 7,
75
ECALL_USER
= 8,
76
ECALL_SUPER
= 9,
77
ECALL_MACHINE
= 11,
78
INST_PAGE
= 12,
79
LOAD_PAGE
= 13,
80
STORE_PAGE
= 15,
81
AMO_PAGE
= 15,
82
83
INT_SOFTWARE_USER
= 0,
84
INT_SOFTWARE_SUPER
= 1,
85
INT_SOFTWARE_MACHINE
= 3,
86
INT_TIMER_USER
= 4,
87
INT_TIMER_SUPER
= 5,
88
INT_TIMER_MACHINE
= 7,
89
INT_EXT_USER
= 8,
90
INT_EXT_SUPER
= 9,
91
INT_EXT_MACHINE
= 11,
92
NumInterruptTypes
93
};
94
95
class
RiscvFault
:
public
FaultBase
96
{
97
protected
:
98
const
FaultName
_name
;
99
const
bool
_interrupt
;
100
ExceptionCode
_code
;
101
102
RiscvFault
(
FaultName
n
,
bool
i
,
ExceptionCode
c
)
103
: _name(n), _interrupt(i), _code(c)
104
{}
105
106
FaultName
name
()
const override
{
return
_name
; }
107
bool
isInterrupt
()
const
{
return
_interrupt
; }
108
ExceptionCode
exception
()
const
{
return
_code
; }
109
virtual
RegVal
trap_value
()
const
{
return
0; }
110
111
virtual
void
invokeSE
(
ThreadContext
*tc,
const
StaticInstPtr
&inst);
112
void
invoke
(
ThreadContext
*tc,
const
StaticInstPtr
&inst)
override
;
113
};
114
115
class
Reset
:
public
FaultBase
116
{
117
private
:
118
const
FaultName
_name
;
119
120
public
:
121
Reset
() : _name(
"reset"
) {}
122
FaultName
name
()
const override
{
return
_name
; }
123
124
void
invoke
(
ThreadContext
*tc,
const
StaticInstPtr
&inst =
125
StaticInst::nullStaticInstPtr
)
override
;
126
};
127
128
class
InterruptFault
:
public
RiscvFault
129
{
130
public
:
131
InterruptFault
(
ExceptionCode
c
) :
RiscvFault
(
"interrupt"
, true, c) {}
132
InterruptFault
(
int
c
) :
InterruptFault
(static_cast<
ExceptionCode
>(c)) {}
133
};
134
135
class
InstFault
:
public
RiscvFault
136
{
137
protected
:
138
const
ExtMachInst
_inst
;
139
140
public
:
141
InstFault
(
FaultName
n
,
const
ExtMachInst
inst)
142
:
RiscvFault
(n, false,
INST_ILLEGAL
), _inst(inst)
143
{}
144
145
RegVal
trap_value
()
const override
{
return
_inst; }
146
};
147
148
class
UnknownInstFault
:
public
InstFault
149
{
150
public
:
151
UnknownInstFault
(
const
ExtMachInst
inst)
152
:
InstFault
(
"Unknown instruction"
, inst)
153
{}
154
155
void
invokeSE
(
ThreadContext
*tc,
const
StaticInstPtr
&inst)
override
;
156
};
157
158
class
IllegalInstFault
:
public
InstFault
159
{
160
private
:
161
const
std::string
reason
;
162
163
public
:
164
IllegalInstFault
(std::string
r
,
const
ExtMachInst
inst)
165
:
InstFault
(
"Illegal instruction"
, inst)
166
{}
167
168
void
invokeSE
(
ThreadContext
*tc,
const
StaticInstPtr
&inst)
override
;
169
};
170
171
class
UnimplementedFault
:
public
InstFault
172
{
173
private
:
174
const
std::string
instName
;
175
176
public
:
177
UnimplementedFault
(std::string
name
,
const
ExtMachInst
inst)
178
:
InstFault
(
"Unimplemented instruction"
, inst),
179
instName(name)
180
{}
181
182
void
invokeSE
(
ThreadContext
*tc,
const
StaticInstPtr
&inst)
override
;
183
};
184
185
class
IllegalFrmFault
:
public
InstFault
186
{
187
private
:
188
const
uint8_t
frm
;
189
190
public
:
191
IllegalFrmFault
(uint8_t
r
,
const
ExtMachInst
inst)
192
:
InstFault
(
"Illegal floating-point rounding mode"
, inst),
193
frm(r)
194
{}
195
196
void
invokeSE
(
ThreadContext
*tc,
const
StaticInstPtr
&inst)
override
;
197
};
198
199
class
AddressFault
:
public
RiscvFault
200
{
201
private
:
202
const
Addr
_addr
;
203
204
public
:
205
AddressFault
(
const
Addr
addr
,
ExceptionCode
code)
206
:
RiscvFault
(
"Address"
, false, code), _addr(addr)
207
{}
208
209
RegVal
trap_value
()
const override
{
return
_addr; }
210
};
211
212
class
BreakpointFault
:
public
RiscvFault
213
{
214
private
:
215
const
PCState
pcState
;
216
217
public
:
218
BreakpointFault
(
const
PCState
&
pc
)
219
:
RiscvFault
(
"Breakpoint"
, false,
BREAKPOINT
), pcState(pc)
220
{}
221
222
RegVal
trap_value
()
const override
{
return
pcState.
pc
(); }
223
void
invokeSE
(
ThreadContext
*tc,
const
StaticInstPtr
&inst)
override
;
224
};
225
226
class
SyscallFault
:
public
RiscvFault
227
{
228
public
:
229
SyscallFault
(
PrivilegeMode
prv)
230
:
RiscvFault
(
"System call"
, false,
ECALL_USER
)
231
{
232
switch
(prv) {
233
case
PRV_U
:
234
_code
=
ECALL_USER
;
235
break
;
236
case
PRV_S
:
237
_code
=
ECALL_SUPER
;
238
break
;
239
case
PRV_M
:
240
_code
=
ECALL_MACHINE
;
241
break
;
242
default
:
243
panic
(
"Unknown privilege mode %d."
, prv);
244
break
;
245
}
246
}
247
248
void
invokeSE
(
ThreadContext
*tc,
const
StaticInstPtr
&inst)
override
;
249
};
250
251
}
// namespace RiscvISA
252
253
#endif // __ARCH_RISCV_FAULTS_HH__
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition:
logging.hh:167
RiscvISA::UnimplementedFault::UnimplementedFault
UnimplementedFault(std::string name, const ExtMachInst inst)
Definition:
faults.hh:177
RiscvISA::PRV_M
Definition:
isa.hh:63
RiscvISA::INT_TIMER_USER
Definition:
faults.hh:86
RiscvISA::PCState
Definition:
types.hh:57
RiscvISA::Reset::Reset
Reset()
Definition:
faults.hh:121
RiscvISA::RiscvFault::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst) override
Definition:
faults.cc:54
RiscvISA::ECALL_MACHINE
Definition:
faults.hh:77
RiscvISA::INT_EXT_MACHINE
Definition:
faults.hh:91
RiscvISA::RiscvFault::_code
ExceptionCode _code
Definition:
faults.hh:100
RiscvISA::INT_SOFTWARE_MACHINE
Definition:
faults.hh:85
RiscvISA::STORE_ACCESS
Definition:
faults.hh:73
RiscvISA::STORE_ADDR_MISALIGNED
Definition:
faults.hh:71
addr
ip6_addr_t addr
Definition:
inet.hh:335
RiscvISA::IllegalFrmFault::IllegalFrmFault
IllegalFrmFault(uint8_t r, const ExtMachInst inst)
Definition:
faults.hh:191
RiscvISA::UnknownInstFault
Definition:
faults.hh:148
RiscvISA::IllegalInstFault::reason
const std::string reason
Definition:
faults.hh:161
RiscvISA::r
r
Definition:
pra_constants.hh:97
RiscvISA::ExceptionCode
ExceptionCode
Definition:
faults.hh:64
RiscvISA::BreakpointFault
Definition:
faults.hh:212
RegVal
uint64_t RegVal
Definition:
types.hh:168
RiscvISA::InstFault::InstFault
InstFault(FaultName n, const ExtMachInst inst)
Definition:
faults.hh:141
RiscvISA::ExtMachInst
uint64_t ExtMachInst
Definition:
types.hh:55
RiscvISA::FloatUnderflow
Definition:
faults.hh:49
RiscvISA::INT_SOFTWARE_SUPER
Definition:
faults.hh:84
RiscvISA::IllegalFrmFault
Definition:
faults.hh:185
isa.hh
RiscvISA::RiscvFault::trap_value
virtual RegVal trap_value() const
Definition:
faults.hh:109
RefCountingPtr< StaticInst >
RiscvISA::INST_ADDR_MISALIGNED
Definition:
faults.hh:65
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Definition:
thread_context.hh:93
RiscvISA::UnimplementedFault
Definition:
faults.hh:171
RiscvISA::ECALL_SUPER
Definition:
faults.hh:76
RiscvISA::INT_TIMER_MACHINE
Definition:
faults.hh:88
RiscvISA::AddressFault::trap_value
RegVal trap_value() const override
Definition:
faults.hh:209
GenericISA::SimplePCState::pc
Addr pc() const
Definition:
types.hh:148
RiscvISA::Reset::name
FaultName name() const override
Definition:
faults.hh:122
ArmISA::n
Bitfield< 31 > n
Definition:
miscregs_types.hh:452
RiscvISA::NumInterruptTypes
Definition:
faults.hh:92
RiscvISA::InterruptFault::InterruptFault
InterruptFault(ExceptionCode c)
Definition:
faults.hh:131
RiscvISA::AMO_ACCESS
Definition:
faults.hh:74
RiscvISA::LOAD_PAGE
Definition:
faults.hh:79
RiscvISA::RiscvFault::invokeSE
virtual void invokeSE(ThreadContext *tc, const StaticInstPtr &inst)
Definition:
faults.cc:48
RiscvISA::InterruptFault
Definition:
faults.hh:128
RiscvISA::UnimplementedFault::instName
const std::string instName
Definition:
faults.hh:174
RiscvISA::pc
Bitfield< 4 > pc
Definition:
pra_constants.hh:242
RiscvISA::BreakpointFault::trap_value
RegVal trap_value() const override
Definition:
faults.hh:222
RiscvISA::BreakpointFault::pcState
const PCState pcState
Definition:
faults.hh:215
RiscvISA::AddressFault::_addr
const Addr _addr
Definition:
faults.hh:202
RiscvISA::LOAD_ADDR_MISALIGNED
Definition:
faults.hh:69
FaultName
const char * FaultName
Definition:
faults.hh:39
RiscvISA::SyscallFault
Definition:
faults.hh:226
RiscvISA::InstFault
Definition:
faults.hh:135
faults.hh
RiscvISA::i
Bitfield< 2 > i
Definition:
pra_constants.hh:278
RiscvISA::PRV_S
Definition:
isa.hh:62
RiscvISA::AMO_ADDR_MISALIGNED
Definition:
faults.hh:72
RiscvISA::INST_ILLEGAL
Definition:
faults.hh:67
RiscvISA::Reset
Definition:
faults.hh:115
RiscvISA::FloatOverflow
Definition:
faults.hh:50
RiscvISA::ECALL_USER
Definition:
faults.hh:75
RiscvISA::STORE_PAGE
Definition:
faults.hh:80
registers.hh
RiscvISA::IllegalFrmFault::frm
const uint8_t frm
Definition:
faults.hh:188
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition:
types.hh:142
RiscvISA::INT_SOFTWARE_USER
Definition:
faults.hh:83
RiscvISA::PrivilegeMode
PrivilegeMode
Definition:
isa.hh:60
RiscvISA::RiscvFault
Definition:
faults.hh:95
RiscvISA::INST_PAGE
Definition:
faults.hh:78
RiscvISA::InstFault::_inst
const ExtMachInst _inst
Definition:
faults.hh:138
RiscvISA::RiscvFault::isInterrupt
bool isInterrupt() const
Definition:
faults.hh:107
RiscvISA::RiscvFault::RiscvFault
RiscvFault(FaultName n, bool i, ExceptionCode c)
Definition:
faults.hh:102
RiscvISA::INST_ACCESS
Definition:
faults.hh:66
RiscvISA::IllegalInstFault::IllegalInstFault
IllegalInstFault(std::string r, const ExtMachInst inst)
Definition:
faults.hh:164
RiscvISA::InterruptFault::InterruptFault
InterruptFault(int c)
Definition:
faults.hh:132
RiscvISA::UnknownInstFault::UnknownInstFault
UnknownInstFault(const ExtMachInst inst)
Definition:
faults.hh:151
thread_context.hh
RiscvISA::SyscallFault::SyscallFault
SyscallFault(PrivilegeMode prv)
Definition:
faults.hh:229
RiscvISA::BreakpointFault::BreakpointFault
BreakpointFault(const PCState &pc)
Definition:
faults.hh:218
RiscvISA::RiscvFault::name
FaultName name() const override
Definition:
faults.hh:106
RiscvISA::AddressFault
Definition:
faults.hh:199
RiscvISA::PRV_U
Definition:
isa.hh:61
RiscvISA::AddressFault::AddressFault
AddressFault(const Addr addr, ExceptionCode code)
Definition:
faults.hh:205
RiscvISA::FloatInexact
Definition:
faults.hh:48
RiscvISA::BREAKPOINT
Definition:
faults.hh:68
RiscvISA::FloatInvalid
Definition:
faults.hh:52
RiscvISA::FloatDivZero
Definition:
faults.hh:51
RiscvISA::AMO_PAGE
Definition:
faults.hh:81
RiscvISA::INT_TIMER_SUPER
Definition:
faults.hh:87
RiscvISA::LOAD_ACCESS
Definition:
faults.hh:70
RiscvISA::INT_EXT_USER
Definition:
faults.hh:89
StaticInst::nullStaticInstPtr
static StaticInstPtr nullStaticInstPtr
Pointer to a statically allocated "null" instruction object.
Definition:
static_inst.hh:223
RiscvISA::RiscvFault::exception
ExceptionCode exception() const
Definition:
faults.hh:108
RiscvISA::FloatException
FloatException
Definition:
faults.hh:47
RiscvISA::c
Bitfield< 5, 3 > c
Definition:
pra_constants.hh:58
RiscvISA::IllegalInstFault
Definition:
faults.hh:158
RiscvISA::InstFault::trap_value
RegVal trap_value() const override
Definition:
faults.hh:145
RiscvISA::RiscvFault::_interrupt
const bool _interrupt
Definition:
faults.hh:99
RiscvISA::INT_EXT_SUPER
Definition:
faults.hh:90
RiscvISA
Definition:
decoder.cc:37
RiscvISA::RiscvFault::_name
const FaultName _name
Definition:
faults.hh:98
RiscvISA::Reset::_name
const FaultName _name
Definition:
faults.hh:118
FaultBase
Definition:
faults.hh:44
Generated on Fri Feb 28 2020 16:26:55 for gem5 by
doxygen
1.8.13