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
isa.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2016 RISC-V Foundation
3
* Copyright (c) 2016 The University of Virginia
4
* All rights reserved.
5
*
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.
16
*
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.
28
*
29
* Authors: Alec Roelke
30
*/
31
#include "
arch/riscv/isa.hh
"
32
33
#include <ctime>
34
#include <set>
35
#include <sstream>
36
37
#include "
arch/riscv/interrupts.hh
"
38
#include "
arch/riscv/registers.hh
"
39
#include "
base/bitfield.hh
"
40
#include "
cpu/base.hh
"
41
#include "debug/RiscvMisc.hh"
42
#include "params/RiscvISA.hh"
43
#include "
sim/core.hh
"
44
#include "
sim/pseudo_inst.hh
"
45
46
namespace
RiscvISA
47
{
48
49
ISA::ISA
(
Params
*
p
) :
BaseISA
(p)
50
{
51
miscRegFile
.resize(
NumMiscRegs
);
52
clear
();
53
}
54
55
const
RiscvISAParams *
56
ISA::params
()
const
57
{
58
return
dynamic_cast<
const
Params
*
>
(
_params
);
59
}
60
61
void
ISA::clear
()
62
{
63
std::fill
(
miscRegFile
.begin(),
miscRegFile
.end(), 0);
64
65
miscRegFile
[
MISCREG_PRV
] =
PRV_M
;
66
miscRegFile[
MISCREG_ISA
] = (2
ULL
<< MXL_OFFSET) | 0x14112D;
67
miscRegFile[
MISCREG_VENDORID
] = 0;
68
miscRegFile[
MISCREG_ARCHID
] = 0;
69
miscRegFile[
MISCREG_IMPID
] = 0;
70
miscRegFile[
MISCREG_STATUS
] = (2
ULL
<<
UXL_OFFSET
) | (2
ULL
<<
SXL_OFFSET
) |
71
(1
ULL
<<
FS_OFFSET
);
72
miscRegFile[
MISCREG_MCOUNTEREN
] = 0x7;
73
miscRegFile[
MISCREG_SCOUNTEREN
] = 0x7;
74
}
75
76
bool
77
ISA::hpmCounterEnabled
(
int
misc_reg)
const
78
{
79
int
hpmcounter = misc_reg -
MISCREG_CYCLE
;
80
if
(hpmcounter < 0 || hpmcounter > 31)
81
panic
(
"Illegal HPM counter %d\n"
, hpmcounter);
82
int
counteren;
83
switch
(
readMiscRegNoEffect
(
MISCREG_PRV
)) {
84
case
PRV_M
:
85
return
true
;
86
case
PRV_S
:
87
counteren =
MISCREG_MCOUNTEREN
;
88
break
;
89
case
PRV_U
:
90
counteren =
MISCREG_SCOUNTEREN
;
91
break
;
92
default
:
93
panic
(
"Unknown privilege level %d\n"
,
miscRegFile
[
MISCREG_PRV
]);
94
return
false
;
95
}
96
return
(
miscRegFile
[counteren] & (1
ULL
<< (hpmcounter))) > 0;
97
}
98
99
RegVal
100
ISA::readMiscRegNoEffect
(
int
misc_reg)
const
101
{
102
if
(misc_reg >
NumMiscRegs
|| misc_reg < 0) {
103
// Illegal CSR
104
panic
(
"Illegal CSR index %#x\n"
, misc_reg);
105
return
-1;
106
}
107
DPRINTF
(RiscvMisc,
"Reading MiscReg %d: %#llx.\n"
, misc_reg,
108
miscRegFile
[misc_reg]);
109
return
miscRegFile
[misc_reg];
110
}
111
112
RegVal
113
ISA::readMiscReg
(
int
misc_reg,
ThreadContext
*tc)
114
{
115
switch
(misc_reg) {
116
case
MISCREG_HARTID
:
117
return
tc->
contextId
();
118
case
MISCREG_CYCLE
:
119
if
(
hpmCounterEnabled
(
MISCREG_CYCLE
)) {
120
DPRINTF
(RiscvMisc,
"Cycle counter at: %llu.\n"
,
121
tc->
getCpuPtr
()->
curCycle
());
122
return
tc->
getCpuPtr
()->
curCycle
();
123
}
else
{
124
warn
(
"Cycle counter disabled.\n"
);
125
return
0;
126
}
127
case
MISCREG_TIME
:
128
if
(
hpmCounterEnabled
(
MISCREG_TIME
)) {
129
DPRINTF
(RiscvMisc,
"Wall-clock counter at: %llu.\n"
,
130
std::time(
nullptr
));
131
return
std::time(
nullptr
);
132
}
else
{
133
warn
(
"Wall clock disabled.\n"
);
134
return
0;
135
}
136
case
MISCREG_INSTRET
:
137
if
(
hpmCounterEnabled
(
MISCREG_INSTRET
)) {
138
DPRINTF
(RiscvMisc,
"Instruction counter at: %llu.\n"
,
139
tc->
getCpuPtr
()->
totalInsts
());
140
return
tc->
getCpuPtr
()->
totalInsts
();
141
}
else
{
142
warn
(
"Instruction counter disabled.\n"
);
143
return
0;
144
}
145
case
MISCREG_IP
:
146
{
147
auto
ic
=
dynamic_cast<
RiscvISA::Interrupts
*
>
(
148
tc->
getCpuPtr
()->
getInterruptController
(tc->
threadId
()));
149
return
ic
->readIP();
150
}
151
case
MISCREG_IE
:
152
{
153
auto
ic
=
dynamic_cast<
RiscvISA::Interrupts
*
>
(
154
tc->
getCpuPtr
()->
getInterruptController
(tc->
threadId
()));
155
return
ic
->readIE();
156
}
157
default
:
158
// Try reading HPM counters
159
// As a placeholder, all HPM counters are just cycle counters
160
if
(misc_reg >=
MISCREG_HPMCOUNTER03
&&
161
misc_reg <=
MISCREG_HPMCOUNTER31
) {
162
if
(
hpmCounterEnabled
(misc_reg)) {
163
DPRINTF
(RiscvMisc,
"HPM counter %d: %llu.\n"
,
164
misc_reg -
MISCREG_CYCLE
, tc->
getCpuPtr
()->
curCycle
());
165
return
tc->
getCpuPtr
()->
curCycle
();
166
}
else
{
167
warn
(
"HPM counter %d disabled.\n"
, misc_reg -
MISCREG_CYCLE
);
168
return
0;
169
}
170
}
171
return
readMiscRegNoEffect
(misc_reg);
172
}
173
}
174
175
void
176
ISA::setMiscRegNoEffect
(
int
misc_reg,
RegVal
val
)
177
{
178
if
(misc_reg >
NumMiscRegs
|| misc_reg < 0) {
179
// Illegal CSR
180
panic
(
"Illegal CSR index %#x\n"
, misc_reg);
181
}
182
DPRINTF
(RiscvMisc,
"Setting MiscReg %d to %#x.\n"
, misc_reg, val);
183
miscRegFile
[misc_reg] =
val
;
184
}
185
186
void
187
ISA::setMiscReg
(
int
misc_reg,
RegVal
val
,
ThreadContext
*tc)
188
{
189
if
(misc_reg >=
MISCREG_CYCLE
&& misc_reg <=
MISCREG_HPMCOUNTER31
) {
190
// Ignore writes to HPM counters for now
191
warn
(
"Ignoring write to %s.\n"
,
CSRData
.at(misc_reg).name);
192
}
else
{
193
switch
(misc_reg) {
194
case
MISCREG_IP
:
195
{
196
auto
ic
=
dynamic_cast<
RiscvISA::Interrupts
*
>
(
197
tc->
getCpuPtr
()->
getInterruptController
(tc->
threadId
()));
198
ic
->setIP(val);
199
}
200
break
;
201
case
MISCREG_IE
:
202
{
203
auto
ic
=
dynamic_cast<
RiscvISA::Interrupts
*
>
(
204
tc->
getCpuPtr
()->
getInterruptController
(tc->
threadId
()));
205
ic
->setIE(val);
206
}
207
break
;
208
default
:
209
setMiscRegNoEffect
(misc_reg, val);
210
}
211
}
212
}
213
214
}
215
216
RiscvISA::ISA
*
217
RiscvISAParams::create()
218
{
219
return
new
RiscvISA::ISA
(
this
);
220
}
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition:
logging.hh:167
DPRINTF
#define DPRINTF(x,...)
Definition:
trace.hh:229
RiscvISA::MISCREG_CYCLE
Definition:
registers.hh:146
RiscvISA::PRV_M
Definition:
isa.hh:63
RiscvISA::ISA::hpmCounterEnabled
bool hpmCounterEnabled(int counter) const
Definition:
isa.cc:77
RiscvISA::MISCREG_SCOUNTEREN
Definition:
registers.hh:247
RiscvISA::MISCREG_HARTID
Definition:
registers.hh:142
RiscvISA::Interrupts
Definition:
interrupts.hh:55
RiscvISA::FS_OFFSET
const off_t FS_OFFSET
Definition:
registers.hh:652
RiscvISA::ISA::readMiscReg
RegVal readMiscReg(int misc_reg, ThreadContext *tc)
Definition:
isa.cc:113
RiscvISA::ISA::ISA
ISA(Params *p)
Definition:
isa.cc:49
RiscvISA::ISA::setMiscReg
void setMiscReg(int misc_reg, RegVal val, ThreadContext *tc)
Definition:
isa.cc:187
RiscvISA::MISCREG_VENDORID
Definition:
registers.hh:139
base.hh
RiscvISA::MISCREG_STATUS
Definition:
registers.hh:143
RegVal
uint64_t RegVal
Definition:
types.hh:168
ThreadContext::getCpuPtr
virtual BaseCPU * getCpuPtr()=0
isa.hh
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Definition:
thread_context.hh:93
RiscvISA::ISA::params
const Params * params() const
Definition:
isa.cc:56
RiscvISA::MISCREG_IMPID
Definition:
registers.hh:141
RiscvISA::p
Bitfield< 0 > p
Definition:
pra_constants.hh:325
X86ISA::val
Bitfield< 63 > val
Definition:
misc.hh:771
RiscvISA::MISCREG_PRV
Definition:
registers.hh:137
RiscvISA::NumMiscRegs
const int NumMiscRegs
Definition:
registers.hh:264
BaseCPU::totalInsts
virtual Counter totalInsts() const =0
RiscvISA::MISCREG_HPMCOUNTER03
Definition:
registers.hh:149
RiscvISA::CSRData
const std::map< int, CSRMetadata > CSRData
Definition:
registers.hh:438
RiscvISA::MISCREG_IP
Definition:
registers.hh:144
bitfield.hh
RiscvISA::MISCREG_MCOUNTEREN
Definition:
registers.hh:218
RiscvISA::PRV_S
Definition:
isa.hh:62
Clocked::curCycle
Cycles curCycle() const
Determine the current cycle, corresponding to a tick aligned to a clock edge.
Definition:
clocked_object.hh:198
RiscvISA::UXL_OFFSET
const off_t UXL_OFFSET
Definition:
registers.hh:651
registers.hh
core.hh
ULL
#define ULL(N)
uint64_t constant
Definition:
types.hh:50
RiscvISA::ISA
Definition:
isa.hh:66
RiscvISA::ISA::readMiscRegNoEffect
RegVal readMiscRegNoEffect(int misc_reg) const
Definition:
isa.cc:100
RiscvISA::SXL_OFFSET
const off_t SXL_OFFSET
Definition:
registers.hh:650
MipsISA::fill
fill
Definition:
pra_constants.hh:56
RiscvISA::PRV_U
Definition:
isa.hh:61
RiscvISA::MISCREG_TIME
Definition:
registers.hh:147
ThreadContext::threadId
virtual int threadId() const =0
SimObject::_params
const SimObjectParams * _params
Cached copy of the object parameters.
Definition:
sim_object.hh:110
ThreadContext::contextId
virtual ContextID contextId() const =0
RiscvISA::MISCREG_ARCHID
Definition:
registers.hh:140
pseudo_inst.hh
BaseCPU::getInterruptController
BaseInterrupts * getInterruptController(ThreadID tid)
Definition:
base.hh:226
RiscvISA::ISA::Params
RiscvISAParams Params
Definition:
isa.hh:74
RiscvISA::MISCREG_HPMCOUNTER31
Definition:
registers.hh:177
BaseISA
Definition:
isa.hh:35
warn
#define warn(...)
Definition:
logging.hh:212
interrupts.hh
RiscvISA::ISA::clear
void clear()
Definition:
isa.cc:61
RiscvISA::ISA::miscRegFile
std::vector< RegVal > miscRegFile
Definition:
isa.hh:69
RiscvISA::MISCREG_ISA
Definition:
registers.hh:138
RiscvISA::ISA::setMiscRegNoEffect
void setMiscRegNoEffect(int misc_reg, RegVal val)
Definition:
isa.cc:176
RiscvISA::MISCREG_INSTRET
Definition:
registers.hh:148
RiscvISA
Definition:
decoder.cc:37
iGbReg::TxdOp::ic
bool ic(TxDesc *d)
Definition:
i8254xGBe_defs.hh:252
RiscvISA::MISCREG_IE
Definition:
registers.hh:145
Generated on Fri Feb 28 2020 16:26:56 for gem5 by
doxygen
1.8.13