gem5
v24.0.0.0
Loading...
Searching...
No Matches
arch
riscv
semihosting.hh
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2018, 2019 ARM Limited
3
* All rights reserved
4
*
5
* The license below extends only to copyright in the software and shall
6
* not be construed as granting a license to any other intellectual
7
* property including but not limited to intellectual property relating
8
* to a hardware implementation of the functionality of the software
9
* licensed hereunder. You may use the software subject to the license
10
* terms below provided that you ensure that this notice is replicated
11
* unmodified and in its entirety in all distributions of the software,
12
* modified or unmodified, in source code or in binary form.
13
*
14
* Redistribution and use in source and binary forms, with or without
15
* modification, are permitted provided that the following conditions are
16
* met: redistributions of source code must retain the above copyright
17
* notice, this list of conditions and the following disclaimer;
18
* redistributions in binary form must reproduce the above copyright
19
* notice, this list of conditions and the following disclaimer in the
20
* documentation and/or other materials provided with the distribution;
21
* neither the name of the copyright holders nor the names of its
22
* contributors may be used to endorse or promote products derived from
23
* this software without specific prior written permission.
24
*
25
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
*/
37
38
#ifndef __ARCH_RISCV_SEMIHOSTING_HH__
39
#define __ARCH_RISCV_SEMIHOSTING_HH__
40
41
#include "
arch/generic/semihosting.hh
"
42
#include "
arch/riscv/isa.hh
"
43
#include "
arch/riscv/regs/int.hh
"
44
#include "
cpu/thread_context.hh
"
45
#include "
sim/guest_abi.hh
"
46
#include "
sim/sim_object.hh
"
47
48
namespace
gem5
49
{
50
51
struct
RiscvSemihostingParams;
52
class
SerialDevice;
53
55
class
RiscvSemihosting
:
public
BaseSemihosting
56
{
57
public
:
58
enum class
Opcode
: uint32_t
59
{
60
// https://github.com/riscv-software-src/riscv-semihosting/blob/main/
61
// riscv-semihosting-spec.adoc#21-semihosting-trap-instruction-sequence
62
Prefix
= 0x01f01013,
// slli x0, x0, 0x1f Entry NOP
63
EBreak
= 0x00100073,
// ebreak Break to debugger
64
Suffix
= 0x40705013,
// srai x0, x0, 7 NOP encoding semihosting
65
};
66
static
PortProxy
&
portProxyImpl
(
ThreadContext
*tc);
67
PortProxy
&
68
portProxy
(
ThreadContext
*tc)
const override
69
{
70
return
portProxyImpl
(tc);
71
}
72
ByteOrder
73
byteOrder
(
ThreadContext
*tc)
const override
74
{
75
return
ByteOrder::little;
76
}
77
78
template
<
typename
ArgType>
79
struct
RiscvSemihostingAbi
:
public
AbiBase
80
{
81
using
UintPtr
= ArgType;
82
83
class
State
:
public
StateBase
<ArgType, RiscvSemihosting>
84
{
85
public
:
86
explicit
87
State
(
const
ThreadContext
*tc) :
88
StateBase
<
ArgType
,
RiscvSemihosting
>(tc,
89
tc->getReg(RiscvISA::
ArgumentRegs
[1]),
90
[](const
ThreadContext
*) {
91
return
ByteOrder::little;
92
})
93
{}
94
};
95
};
96
97
struct
Abi64
:
public
RiscvSemihostingAbi
<uint64_t>
98
{};
99
struct
Abi32
:
public
RiscvSemihostingAbi
<uint32_t>
100
{};
101
102
enum
Operation
103
{
104
SYS_OPEN
= 0x01,
105
SYS_CLOSE
= 0x02,
106
SYS_WRITEC
= 0x03,
107
SYS_WRITE0
= 0x04,
108
SYS_WRITE
= 0x05,
109
SYS_READ
= 0x06,
110
SYS_READC
= 0x07,
111
SYS_ISERROR
= 0x08,
112
SYS_ISTTY
= 0x09,
113
SYS_SEEK
= 0x0A,
114
SYS_FLEN
= 0x0C,
115
SYS_TMPNAM
= 0x0D,
116
SYS_REMOVE
= 0x0E,
117
SYS_RENAME
= 0x0F,
118
SYS_CLOCK
= 0x10,
119
SYS_TIME
= 0x11,
120
SYS_SYSTEM
= 0x12,
121
SYS_ERRNO
= 0x13,
122
SYS_GET_CMDLINE
= 0x15,
123
SYS_HEAPINFO
= 0x16,
124
SYS_EXIT
= 0x18,
125
SYS_EXIT_EXTENDED
= 0x20,
126
SYS_ELAPSED
= 0x30,
127
SYS_TICKFREQ
= 0x31,
128
129
MaxStandardOp
= 0xFF,
130
131
SYS_GEM5_PSEUDO_OP
= 0x100
132
};
133
134
using
SemiCall
=
SemiCallBase<RiscvSemihosting, Abi32, Abi64>
;
135
136
explicit
RiscvSemihosting
(
const
RiscvSemihostingParams &
p
);
137
139
bool
isSemihostingEBreak
(
ExecContext
*xc);
140
bool
call
(
ThreadContext
*tc);
141
protected
:
142
bool
call64
(
ThreadContext
*tc);
143
bool
call32
(
ThreadContext
*tc);
144
static
const
std::map<uint32_t, SemiCall>
calls
;
145
};
146
147
namespace
guest_abi
148
{
149
150
template
<
typename
Arg>
151
struct
Argument
<
RiscvSemihosting
::Abi64, Arg,
152
typename std::enable_if_t<std::is_integral_v<Arg>>>
153
{
154
static
Arg
155
get
(
ThreadContext
*tc, RiscvSemihosting::Abi64::State &
state
)
156
{
157
return
state
.get(tc);
158
}
159
};
160
161
template
<
typename
Arg>
162
struct
Argument
<
RiscvSemihosting
::Abi32, Arg,
163
typename std::enable_if_t<std::is_integral_v<Arg>>>
164
{
165
static
Arg
166
get
(
ThreadContext
*tc, RiscvSemihosting::Abi32::State &
state
)
167
{
168
if
(std::is_signed_v<Arg>)
169
return
sext<32>
(
state
.get(tc));
170
else
171
return
state
.get(tc);
172
}
173
};
174
175
template
<
typename
Abi>
176
struct
Argument
<Abi,
RiscvSemihosting
::InPlaceArg,
177
typename std::enable_if_t<
178
std::is_base_of_v<RiscvSemihosting::AbiBase, Abi>>>
179
{
180
static
RiscvSemihosting::InPlaceArg
181
get
(
ThreadContext
*tc,
typename
Abi::State &
state
)
182
{
183
return
RiscvSemihosting::InPlaceArg
(
184
state
.getAddr(),
sizeof
(
typename
Abi::State::ArgType));
185
}
186
};
187
188
template
<
typename
Abi>
189
struct
Result
<Abi,
RiscvSemihosting
::RetErrno>
190
{
191
static
void
192
store
(
ThreadContext
*tc,
const
RiscvSemihosting::RetErrno
&
err
)
193
{
194
tc->
setReg
(
RiscvISA::ReturnValueReg
,
err
.first);
195
}
196
};
197
198
}
// namespace guest_abi
199
}
// namespace gem5
200
201
#endif
// __ARCH_RISCV_SEMIHOSTING_HH__
gem5::BaseSemihosting::AbiBase::StateBase
Definition
semihosting.hh:90
gem5::BaseSemihosting::AbiBase::StateBase::ArgType
Arg ArgType
Definition
semihosting.hh:129
gem5::BaseSemihosting
Semihosting for AArch32, AArch64, RISCV-32 and RISCV-64: https://github.com/ARM-software/abi-aa/blob/...
Definition
semihosting.hh:81
gem5::ExecContext
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
Definition
exec_context.hh:72
gem5::PortProxy
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition
port_proxy.hh:87
gem5::RiscvSemihosting::RiscvSemihostingAbi::State
Definition
semihosting.hh:84
gem5::RiscvSemihosting::RiscvSemihostingAbi::State::State
State(const ThreadContext *tc)
Definition
semihosting.hh:87
gem5::RiscvSemihosting
Semihosting for RV32 and RV64.
Definition
semihosting.hh:56
gem5::RiscvSemihosting::call64
bool call64(ThreadContext *tc)
Definition
semihosting.cc:105
gem5::RiscvSemihosting::portProxyImpl
static PortProxy & portProxyImpl(ThreadContext *tc)
Definition
semihosting.cc:152
gem5::RiscvSemihosting::portProxy
PortProxy & portProxy(ThreadContext *tc) const override
Definition
semihosting.hh:68
gem5::RiscvSemihosting::RiscvSemihosting
RiscvSemihosting(const RiscvSemihostingParams &p)
Definition
semihosting.cc:101
gem5::RiscvSemihosting::calls
static const std::map< uint32_t, SemiCall > calls
Definition
semihosting.hh:144
gem5::RiscvSemihosting::SemiCall
SemiCallBase< RiscvSemihosting, Abi32, Abi64 > SemiCall
Definition
semihosting.hh:134
gem5::RiscvSemihosting::call
bool call(ThreadContext *tc)
Definition
semihosting.cc:144
gem5::RiscvSemihosting::byteOrder
ByteOrder byteOrder(ThreadContext *tc) const override
Definition
semihosting.hh:73
gem5::RiscvSemihosting::isSemihostingEBreak
bool isSemihostingEBreak(ExecContext *xc)
Perform a RISC-V Semihosting call.
Definition
semihosting.cc:162
gem5::RiscvSemihosting::call32
bool call32(ThreadContext *tc)
Definition
semihosting.cc:124
gem5::RiscvSemihosting::Opcode
Opcode
Definition
semihosting.hh:59
gem5::RiscvSemihosting::Opcode::Suffix
@ Suffix
gem5::RiscvSemihosting::Opcode::Prefix
@ Prefix
gem5::RiscvSemihosting::Opcode::EBreak
@ EBreak
gem5::RiscvSemihosting::Operation
Operation
Definition
semihosting.hh:103
gem5::RiscvSemihosting::SYS_REMOVE
@ SYS_REMOVE
Definition
semihosting.hh:116
gem5::RiscvSemihosting::SYS_ISTTY
@ SYS_ISTTY
Definition
semihosting.hh:112
gem5::RiscvSemihosting::SYS_TICKFREQ
@ SYS_TICKFREQ
Definition
semihosting.hh:127
gem5::RiscvSemihosting::SYS_EXIT
@ SYS_EXIT
Definition
semihosting.hh:124
gem5::RiscvSemihosting::SYS_CLOSE
@ SYS_CLOSE
Definition
semihosting.hh:105
gem5::RiscvSemihosting::SYS_ELAPSED
@ SYS_ELAPSED
Definition
semihosting.hh:126
gem5::RiscvSemihosting::SYS_GET_CMDLINE
@ SYS_GET_CMDLINE
Definition
semihosting.hh:122
gem5::RiscvSemihosting::SYS_SYSTEM
@ SYS_SYSTEM
Definition
semihosting.hh:120
gem5::RiscvSemihosting::SYS_WRITE0
@ SYS_WRITE0
Definition
semihosting.hh:107
gem5::RiscvSemihosting::SYS_TMPNAM
@ SYS_TMPNAM
Definition
semihosting.hh:115
gem5::RiscvSemihosting::SYS_WRITEC
@ SYS_WRITEC
Definition
semihosting.hh:106
gem5::RiscvSemihosting::SYS_ERRNO
@ SYS_ERRNO
Definition
semihosting.hh:121
gem5::RiscvSemihosting::SYS_TIME
@ SYS_TIME
Definition
semihosting.hh:119
gem5::RiscvSemihosting::SYS_HEAPINFO
@ SYS_HEAPINFO
Definition
semihosting.hh:123
gem5::RiscvSemihosting::SYS_READ
@ SYS_READ
Definition
semihosting.hh:109
gem5::RiscvSemihosting::SYS_OPEN
@ SYS_OPEN
Definition
semihosting.hh:104
gem5::RiscvSemihosting::SYS_ISERROR
@ SYS_ISERROR
Definition
semihosting.hh:111
gem5::RiscvSemihosting::SYS_CLOCK
@ SYS_CLOCK
Definition
semihosting.hh:118
gem5::RiscvSemihosting::SYS_READC
@ SYS_READC
Definition
semihosting.hh:110
gem5::RiscvSemihosting::SYS_EXIT_EXTENDED
@ SYS_EXIT_EXTENDED
Definition
semihosting.hh:125
gem5::RiscvSemihosting::SYS_WRITE
@ SYS_WRITE
Definition
semihosting.hh:108
gem5::RiscvSemihosting::SYS_SEEK
@ SYS_SEEK
Definition
semihosting.hh:113
gem5::RiscvSemihosting::SYS_GEM5_PSEUDO_OP
@ SYS_GEM5_PSEUDO_OP
Definition
semihosting.hh:131
gem5::RiscvSemihosting::SYS_FLEN
@ SYS_FLEN
Definition
semihosting.hh:114
gem5::RiscvSemihosting::MaxStandardOp
@ MaxStandardOp
Definition
semihosting.hh:129
gem5::RiscvSemihosting::SYS_RENAME
@ SYS_RENAME
Definition
semihosting.hh:117
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition
guest_abi.test.cc:41
gem5::ThreadContext::setReg
virtual void setReg(const RegId ®, RegVal val)
Definition
thread_context.cc:188
std::pair
STL pair class.
Definition
stl.hh:58
thread_context.hh
semihosting.hh
gem5::sext
constexpr uint64_t sext(uint64_t val)
Sign-extend an N-bit value to 64 bits.
Definition
bitfield.hh:129
guest_abi.hh
state
atomic_var_t state
Definition
helpers.cc:211
gem5::ArmISA::err
Bitfield< 6 > err
Definition
misc_types.hh:919
gem5::MipsISA::p
Bitfield< 0 > p
Definition
pra_constants.hh:326
gem5::RiscvISA::ArgumentRegs
constexpr RegId ArgumentRegs[]
Definition
int.hh:147
gem5::RiscvISA::ReturnValueReg
constexpr auto & ReturnValueReg
Definition
int.hh:143
gem5
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition
binary32.hh:36
isa.hh
int.hh
sim_object.hh
gem5::BaseSemihosting::AbiBase
Definition
semihosting.hh:87
gem5::BaseSemihosting::InPlaceArg
Definition
semihosting.hh:137
gem5::BaseSemihosting::SemiCallBase
Semihosting call information structure.
Definition
semihosting.hh:414
gem5::RiscvSemihosting::Abi32
Definition
semihosting.hh:100
gem5::RiscvSemihosting::Abi64
Definition
semihosting.hh:98
gem5::RiscvSemihosting::RiscvSemihostingAbi
Definition
semihosting.hh:80
gem5::RiscvSemihosting::RiscvSemihostingAbi::UintPtr
ArgType UintPtr
Definition
semihosting.hh:81
gem5::guest_abi::Argument< Abi, RiscvSemihosting::InPlaceArg, typename std::enable_if_t< std::is_base_of_v< RiscvSemihosting::AbiBase, Abi > > >::get
static RiscvSemihosting::InPlaceArg get(ThreadContext *tc, typename Abi::State &state)
Definition
semihosting.hh:181
gem5::guest_abi::Argument< RiscvSemihosting::Abi32, Arg, typename std::enable_if_t< std::is_integral_v< Arg > > >::get
static Arg get(ThreadContext *tc, RiscvSemihosting::Abi32::State &state)
Definition
semihosting.hh:166
gem5::guest_abi::Argument< RiscvSemihosting::Abi64, Arg, typename std::enable_if_t< std::is_integral_v< Arg > > >::get
static Arg get(ThreadContext *tc, RiscvSemihosting::Abi64::State &state)
Definition
semihosting.hh:155
gem5::guest_abi::Argument
Definition
definition.hh:99
gem5::guest_abi::Result< Abi, RiscvSemihosting::RetErrno >::store
static void store(ThreadContext *tc, const RiscvSemihosting::RetErrno &err)
Definition
semihosting.hh:192
gem5::guest_abi::Result
Definition
definition.hh:64
Generated on Tue Jun 18 2024 16:23:57 for gem5 by
doxygen
1.11.0