gem5
v24.1.0.1
Loading...
Searching...
No Matches
arch
arm
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_ARM_SEMIHOSTING_HH__
39
#define __ARCH_ARM_SEMIHOSTING_HH__
40
41
#include <cstdio>
42
#include <functional>
43
#include <map>
44
#include <memory>
45
#include <utility>
46
#include <vector>
47
48
#include "
arch/arm/regs/int.hh
"
49
#include "
arch/arm/utility.hh
"
50
#include "
arch/generic/semihosting.hh
"
51
#include "
cpu/thread_context.hh
"
52
#include "
mem/port_proxy.hh
"
53
#include "
sim/core.hh
"
54
#include "
sim/guest_abi.hh
"
55
#include "
sim/pseudo_inst.hh
"
56
#include "
sim/sim_object.hh
"
57
58
namespace
gem5
59
{
60
61
struct
ArmSemihostingParams;
62
class
SerialDevice;
63
65
class
ArmSemihosting
:
public
BaseSemihosting
66
{
67
public
:
68
enum
69
{
70
// Standard ARM immediate values which trigger semihosting.
71
T32Imm
= 0xAB,
72
A32Imm
= 0x123456,
73
A64Imm
= 0xF000,
74
75
// The immediate value which enables gem5 semihosting calls. Use the
76
// standard value for thumb.
77
Gem5Imm
= 0x5D57
78
};
79
80
static
PortProxy
&
portProxyImpl
(
ThreadContext
*tc);
81
PortProxy
&
portProxy
(
ThreadContext
*tc)
const override
82
{
83
return
portProxyImpl
(tc);
84
}
85
ByteOrder
byteOrder
(
ThreadContext
*tc)
const override
86
{
87
return
ArmISA::byteOrder
(tc);
88
}
89
90
struct
Abi64
:
public
AbiBase
91
{
92
using
UintPtr
= uint64_t;
93
94
class
State
:
public
StateBase
<Abi64::UintPtr, ArmSemihosting>
95
{
96
public
:
97
// For 64 bit semihosting, the params are pointer to by X1.
98
explicit
99
State
(
const
ThreadContext
*tc) :
100
StateBase
<
Abi64
::
UintPtr
,
ArmSemihosting
>(tc,
101
tc->getReg(ArmISA::int_reg::X1), &ArmISA::
byteOrder
)
102
{}
103
};
104
};
105
106
struct
Abi32
:
public
AbiBase
107
{
108
using
UintPtr
= uint32_t;
109
110
class
State
:
public
StateBase
<Abi32::UintPtr, ArmSemihosting>
111
{
112
public
:
113
// For 32 bit semihosting, the params are pointer to by R1.
114
explicit
115
State
(
const
ThreadContext
*tc) :
116
StateBase
<
Abi32
::
UintPtr
,
ArmSemihosting
>(tc,
117
tc->getReg(ArmISA::int_reg::R1), &ArmISA::
byteOrder
)
118
{}
119
};
120
};
121
122
enum
Operation
123
{
124
SYS_OPEN
= 0x01,
125
SYS_CLOSE
= 0x02,
126
SYS_WRITEC
= 0x03,
127
SYS_WRITE0
= 0x04,
128
SYS_WRITE
= 0x05,
129
SYS_READ
= 0x06,
130
SYS_READC
= 0x07,
131
SYS_ISERROR
= 0x08,
132
SYS_ISTTY
= 0x09,
133
SYS_SEEK
= 0x0A,
134
SYS_FLEN
= 0x0C,
135
SYS_TMPNAM
= 0x0D,
136
SYS_REMOVE
= 0x0E,
137
SYS_RENAME
= 0x0F,
138
SYS_CLOCK
= 0x10,
139
SYS_TIME
= 0x11,
140
SYS_SYSTEM
= 0x12,
141
SYS_ERRNO
= 0x13,
142
SYS_GET_CMDLINE
= 0x15,
143
SYS_HEAPINFO
= 0x16,
144
SYS_EXIT
= 0x18,
145
SYS_EXIT_EXTENDED
= 0x20,
146
SYS_ELAPSED
= 0x30,
147
SYS_TICKFREQ
= 0x31,
148
149
MaxStandardOp
= 0xFF,
150
151
SYS_GEM5_PSEUDO_OP
= 0x100
152
};
153
154
using
SemiCall
=
SemiCallBase<ArmSemihosting, Abi32, Abi64>
;
155
156
explicit
ArmSemihosting
(
const
ArmSemihostingParams &
p
);
157
159
bool
call64
(
ThreadContext
*tc,
bool
gem5_ops);
161
bool
call32
(
ThreadContext
*tc,
bool
gem5_ops);
162
163
protected
:
164
RetErrno
callGem5PseudoOp32
(
ThreadContext
*tc, uint32_t encoded_func);
165
RetErrno
callGem5PseudoOp64
(
ThreadContext
*tc, uint64_t encoded_func);
166
167
static
const
std::map<uint32_t, SemiCall>
calls
;
168
};
169
170
namespace
guest_abi
171
{
172
173
template
<
typename
Arg>
174
struct
Argument
<
ArmSemihosting
::Abi64, Arg,
175
typename std::enable_if_t<
176
(std::is_integral_v<Arg> ||
177
std::is_same<Arg,pseudo_inst::GuestAddr>::value)>>
178
{
179
static
Arg
180
get
(
ThreadContext
*tc,
ArmSemihosting::Abi64::State
&
state
)
181
{
182
return
(Arg)
state
.get(tc);
183
}
184
};
185
186
template
<
typename
Arg>
187
struct
Argument
<
ArmSemihosting
::Abi32, Arg,
188
typename std::enable_if_t<
189
(std::is_integral_v<Arg> ||
190
std::is_same<Arg,pseudo_inst::GuestAddr>::value)>>
191
{
192
static
Arg
193
get
(
ThreadContext
*tc,
ArmSemihosting::Abi32::State
&
state
)
194
{
195
if
(std::is_signed_v<Arg>) {
196
return
(Arg)sext<32>(
state
.get(tc));
197
}
198
else
{
199
return
(Arg)
state
.get(tc);
200
}
201
}
202
};
203
204
template
<
typename
Abi>
205
struct
Argument
<Abi,
ArmSemihosting
::InPlaceArg, typename std::enable_if_t<
206
std::is_base_of_v<ArmSemihosting::AbiBase, Abi>>>
207
{
208
static
ArmSemihosting::InPlaceArg
209
get
(
ThreadContext
*tc,
typename
Abi::State &
state
)
210
{
211
return
ArmSemihosting::InPlaceArg
(
212
state
.getAddr(),
sizeof
(
typename
Abi::State::ArgType));
213
}
214
};
215
216
template
<>
217
struct
Result
<
ArmSemihosting
::Abi32,
ArmSemihosting::RetErrno
>
218
{
219
static
void
220
store
(
ThreadContext
*tc,
const
ArmSemihosting::RetErrno
&
err
)
221
{
222
tc->
setReg
(
ArmISA::int_reg::R0
,
err
.first);
223
}
224
};
225
226
template
<>
227
struct
Result
<
ArmSemihosting
::Abi64,
ArmSemihosting::RetErrno
>
228
{
229
static
void
230
store
(
ThreadContext
*tc,
const
ArmSemihosting::RetErrno
&
err
)
231
{
232
tc->
setReg
(
ArmISA::int_reg::X0
,
err
.first);
233
}
234
};
235
236
}
// namespace guest_abi
237
}
// namespace gem5
238
239
#endif
// __ARCH_ARM_SEMIHOSTING_HH__
int.hh
utility.hh
gem5::ArmSemihosting::Abi32::State
Definition
semihosting.hh:111
gem5::ArmSemihosting::Abi32::State::State
State(const ThreadContext *tc)
Definition
semihosting.hh:115
gem5::ArmSemihosting::Abi64::State
Definition
semihosting.hh:95
gem5::ArmSemihosting::Abi64::State::State
State(const ThreadContext *tc)
Definition
semihosting.hh:99
gem5::ArmSemihosting
Semihosting for AArch32 and AArch64.
Definition
semihosting.hh:66
gem5::ArmSemihosting::calls
static const std::map< uint32_t, SemiCall > calls
Definition
semihosting.hh:167
gem5::ArmSemihosting::call32
bool call32(ThreadContext *tc, bool gem5_ops)
Perform an Arm Semihosting call from aarch32 code.
Definition
semihosting.cc:129
gem5::ArmSemihosting::byteOrder
ByteOrder byteOrder(ThreadContext *tc) const override
Definition
semihosting.hh:85
gem5::ArmSemihosting::portProxyImpl
static PortProxy & portProxyImpl(ThreadContext *tc)
Definition
semihosting.cc:155
gem5::ArmSemihosting::call64
bool call64(ThreadContext *tc, bool gem5_ops)
Perform an Arm Semihosting call from aarch64 code.
Definition
semihosting.cc:103
gem5::ArmSemihosting::Operation
Operation
Definition
semihosting.hh:123
gem5::ArmSemihosting::SYS_ELAPSED
@ SYS_ELAPSED
Definition
semihosting.hh:146
gem5::ArmSemihosting::SYS_SYSTEM
@ SYS_SYSTEM
Definition
semihosting.hh:140
gem5::ArmSemihosting::SYS_HEAPINFO
@ SYS_HEAPINFO
Definition
semihosting.hh:143
gem5::ArmSemihosting::SYS_READC
@ SYS_READC
Definition
semihosting.hh:130
gem5::ArmSemihosting::SYS_WRITE0
@ SYS_WRITE0
Definition
semihosting.hh:127
gem5::ArmSemihosting::SYS_EXIT
@ SYS_EXIT
Definition
semihosting.hh:144
gem5::ArmSemihosting::SYS_CLOSE
@ SYS_CLOSE
Definition
semihosting.hh:125
gem5::ArmSemihosting::SYS_ISERROR
@ SYS_ISERROR
Definition
semihosting.hh:131
gem5::ArmSemihosting::SYS_TICKFREQ
@ SYS_TICKFREQ
Definition
semihosting.hh:147
gem5::ArmSemihosting::SYS_CLOCK
@ SYS_CLOCK
Definition
semihosting.hh:138
gem5::ArmSemihosting::SYS_ERRNO
@ SYS_ERRNO
Definition
semihosting.hh:141
gem5::ArmSemihosting::SYS_RENAME
@ SYS_RENAME
Definition
semihosting.hh:137
gem5::ArmSemihosting::SYS_REMOVE
@ SYS_REMOVE
Definition
semihosting.hh:136
gem5::ArmSemihosting::SYS_EXIT_EXTENDED
@ SYS_EXIT_EXTENDED
Definition
semihosting.hh:145
gem5::ArmSemihosting::SYS_WRITEC
@ SYS_WRITEC
Definition
semihosting.hh:126
gem5::ArmSemihosting::SYS_TIME
@ SYS_TIME
Definition
semihosting.hh:139
gem5::ArmSemihosting::SYS_FLEN
@ SYS_FLEN
Definition
semihosting.hh:134
gem5::ArmSemihosting::SYS_TMPNAM
@ SYS_TMPNAM
Definition
semihosting.hh:135
gem5::ArmSemihosting::SYS_READ
@ SYS_READ
Definition
semihosting.hh:129
gem5::ArmSemihosting::SYS_OPEN
@ SYS_OPEN
Definition
semihosting.hh:124
gem5::ArmSemihosting::SYS_GEM5_PSEUDO_OP
@ SYS_GEM5_PSEUDO_OP
Definition
semihosting.hh:151
gem5::ArmSemihosting::MaxStandardOp
@ MaxStandardOp
Definition
semihosting.hh:149
gem5::ArmSemihosting::SYS_GET_CMDLINE
@ SYS_GET_CMDLINE
Definition
semihosting.hh:142
gem5::ArmSemihosting::SYS_ISTTY
@ SYS_ISTTY
Definition
semihosting.hh:132
gem5::ArmSemihosting::SYS_WRITE
@ SYS_WRITE
Definition
semihosting.hh:128
gem5::ArmSemihosting::SYS_SEEK
@ SYS_SEEK
Definition
semihosting.hh:133
gem5::ArmSemihosting::callGem5PseudoOp32
RetErrno callGem5PseudoOp32(ThreadContext *tc, uint32_t encoded_func)
Definition
semihosting.cc:232
gem5::ArmSemihosting::callGem5PseudoOp64
RetErrno callGem5PseudoOp64(ThreadContext *tc, uint64_t encoded_func)
Definition
semihosting.cc:245
gem5::ArmSemihosting::portProxy
PortProxy & portProxy(ThreadContext *tc) const override
Definition
semihosting.hh:81
gem5::ArmSemihosting::Gem5Imm
@ Gem5Imm
Definition
semihosting.hh:77
gem5::ArmSemihosting::T32Imm
@ T32Imm
Definition
semihosting.hh:71
gem5::ArmSemihosting::A64Imm
@ A64Imm
Definition
semihosting.hh:73
gem5::ArmSemihosting::A32Imm
@ A32Imm
Definition
semihosting.hh:72
gem5::BaseSemihosting::AbiBase::StateBase
Definition
semihosting.hh:90
gem5::BaseSemihosting
Semihosting for AArch32, AArch64, RISCV-32 and RISCV-64: https://github.com/ARM-software/abi-aa/blob/...
Definition
semihosting.hh:81
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::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition
thread_context.hh:89
gem5::ThreadContext::setReg
virtual void setReg(const RegId ®, RegVal val)
Definition
thread_context.cc:188
std::pair
STL pair class.
Definition
stl.hh:58
core.hh
thread_context.hh
semihosting.hh
guest_abi.hh
state
atomic_var_t state
Definition
helpers.cc:211
gem5::ArmISA::int_reg::X0
constexpr RegId X0
Definition
int.hh:240
gem5::ArmISA::int_reg::R0
constexpr RegId R0
Definition
int.hh:186
gem5::ArmISA::byteOrder
ByteOrder byteOrder(const ThreadContext *tc)
Definition
utility.hh:359
gem5::ArmISA::err
Bitfield< 6 > err
Definition
misc_types.hh:924
gem5::MipsISA::p
Bitfield< 0 > p
Definition
pra_constants.hh:326
gem5
Copyright (c) 2024 Arm Limited All rights reserved.
Definition
binary32.hh:36
port_proxy.hh
PortProxy Object Declaration.
pseudo_inst.hh
sim_object.hh
gem5::ArmSemihosting::Abi32
Definition
semihosting.hh:107
gem5::ArmSemihosting::Abi32::UintPtr
uint32_t UintPtr
Definition
semihosting.hh:108
gem5::ArmSemihosting::Abi64
Definition
semihosting.hh:91
gem5::ArmSemihosting::Abi64::UintPtr
uint64_t UintPtr
Definition
semihosting.hh:92
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::guest_abi::Argument< Abi, ArmSemihosting::InPlaceArg, typename std::enable_if_t< std::is_base_of_v< ArmSemihosting::AbiBase, Abi > > >::get
static ArmSemihosting::InPlaceArg get(ThreadContext *tc, typename Abi::State &state)
Definition
semihosting.hh:209
gem5::guest_abi::Argument< ArmSemihosting::Abi32, Arg, typename std::enable_if_t<(std::is_integral_v< Arg >||std::is_same< Arg, pseudo_inst::GuestAddr >::value)> >::get
static Arg get(ThreadContext *tc, ArmSemihosting::Abi32::State &state)
Definition
semihosting.hh:193
gem5::guest_abi::Argument< ArmSemihosting::Abi64, Arg, typename std::enable_if_t<(std::is_integral_v< Arg >||std::is_same< Arg, pseudo_inst::GuestAddr >::value)> >::get
static Arg get(ThreadContext *tc, ArmSemihosting::Abi64::State &state)
Definition
semihosting.hh:180
gem5::guest_abi::Argument
Definition
definition.hh:99
gem5::guest_abi::Result< ArmSemihosting::Abi32, ArmSemihosting::RetErrno >::store
static void store(ThreadContext *tc, const ArmSemihosting::RetErrno &err)
Definition
semihosting.hh:220
gem5::guest_abi::Result< ArmSemihosting::Abi64, ArmSemihosting::RetErrno >::store
static void store(ThreadContext *tc, const ArmSemihosting::RetErrno &err)
Definition
semihosting.hh:230
gem5::guest_abi::Result
Definition
definition.hh:64
Generated on Mon Jan 13 2025 04:28:28 for gem5 by
doxygen
1.9.8