38#ifndef __ARCH_GENERIC_SEMIHOSTING_HH__
39#define __ARCH_GENERIC_SEMIHOSTING_HH__
59struct BaseSemihostingParams;
88 template <
typename Arg,
class BaseSemihostingImpl>
123 Arg arg = BaseSemihostingImpl::portProxyImpl(tc)
149 return proxy.
read<uint64_t>(
addr, endian);
151 return proxy.
read<uint32_t>(
addr, endian);
153 panic(
"Unexpected semihosting argument size %d.",
size);
166 panic(
"Unexpected semihosting argument size %d.",
size);
221 const std::string &fname,
const char *
mode);
283 virtual int64_t
read(uint8_t *buffer, uint64_t size);
290 virtual int64_t
write(
const uint8_t *buffer, uint64_t size);
298 virtual int64_t
seek(uint64_t pos);
305 virtual int64_t
flen();
325 int64_t
read(uint8_t *buffer, uint64_t size)
override;
326 int64_t
seek(uint64_t
pos)
override;
327 int64_t
flen()
override;
347 int64_t
close()
override;
348 bool isTTY()
const override;
349 int64_t
read(uint8_t *buffer, uint64_t size)
override;
350 int64_t
write(
const uint8_t *buffer, uint64_t size)
override;
351 int64_t
seek(uint64_t pos)
override;
352 int64_t
flen()
override;
377 return msb > 31 ? msb - 31 : 0;
384 void semiExit(uint64_t code, uint64_t subcode);
412 template <
typename Semihosting,
typename Abi32,
typename Abi64>
419 template <
typename Impl,
typename... Args>
425 template <
typename SemiImpl,
typename... Args>
430 return (
sh->*
impl)(tc, args...);
449 template <
typename Abi,
typename SemiImpl,
typename... Args>
461 template <
typename Abi,
typename SemiImpl,
typename... Args>
472 template <
typename SemiImpl,
typename... Args>
482 template <
typename SemiImpl,
typename... Args32,
typename... Args64>
512 Addr to_addr,
size_t to_size);
532 template <
typename Abi>
542 static FILE *
getSTDIO(
const char *stream_name,
const std::string &
name,
546 static const std::map<uint64_t, const char *>
exitCodes;
548 static const std::map<const std::string, FILE *>
stdioMap;
Arg get(ThreadContext *tc)
StateBase(const ThreadContext *tc, Addr arg_pointer, std::function< ByteOrder(const ThreadContext *tc)> getByteOrder)
Internal state for open files.
virtual int64_t write(const uint8_t *buffer, uint64_t size)
Write data to file.
virtual int64_t close()
Close the file.
void serialize(CheckpointOut &cp) const override
Serialize an object.
virtual int64_t seek(uint64_t pos)
Seek to an absolute position in the file.
virtual int64_t read(uint8_t *buffer, uint64_t size)
Read data from file.
static std::unique_ptr< FileBase > create(BaseSemihosting &parent, const std::string &fname, const char *mode)
virtual bool isTTY() const
Check if a file corresponds to a TTY device.
FileBase(BaseSemihosting &_parent, const char *name, const char *_mode)
const std::string & fileName()
virtual int64_t flen()
Get the length of a file in bytes.
FileBase(FileBase &)=delete
void unserialize(CheckpointIn &cp) override
Unserialize an object.
virtual int64_t open()
Open the the file.
Implementation of the ':semihosting-features' magic file.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
int64_t seek(uint64_t pos) override
Seek to an absolute position in the file.
FileFeatures(BaseSemihosting &_parent, const char *name, const char *mode)
int64_t flen() override
Get the length of a file in bytes.
int64_t read(uint8_t *buffer, uint64_t size) override
Read data from file.
void serialize(CheckpointOut &cp) const override
Serialize an object.
bool isTTY() const override
Check if a file corresponds to a TTY device.
int64_t close() override
Close the file.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
int64_t open() override
Open the the file.
File(BaseSemihosting &_parent, const char *name, const char *mode)
void serialize(CheckpointOut &cp) const override
Serialize an object.
int64_t read(uint8_t *buffer, uint64_t size) override
Read data from file.
int64_t flen() override
Get the length of a file in bytes.
int64_t seek(uint64_t pos) override
Seek to an absolute position in the file.
int64_t openImpl(bool unserialize)
int64_t write(const uint8_t *buffer, uint64_t size) override
Write data to file.
Semihosting for AArch32, AArch64, RISCV-32 and RISCV-64: https://github.com/ARM-software/abi-aa/blob/...
RetErrno callReadC(ThreadContext *tc)
unsigned calcTickShift() const
RetErrno callElapsed32(ThreadContext *tc, InPlaceArg low, InPlaceArg high)
RetErrno callExit64(ThreadContext *tc, uint64_t code, uint64_t subcode)
static const std::map< uint64_t, const char * > exitCodes
RetErrno callFLen(ThreadContext *tc, Handle handle)
const std::string cmdLine
static const std::array< uint8_t, 5 > features
void unrecognizedCall(ThreadContext *tc, const char *format, uint64_t op)
const unsigned tickShift
Number of bits to right shift gem5 ticks to fit in a uint32_t.
static FILE * getSTDIO(const char *stream_name, const std::string &name, const char *mode)
RetErrno callTickFreq(ThreadContext *tc)
std::pair< uint64_t, SemiErrno > RetErrno
virtual ByteOrder byteOrder(ThreadContext *tc) const =0
static const std::map< const std::string, FILE * > stdioMap
RetErrno callRename(ThreadContext *tc, Addr from_addr, size_t from_size, Addr to_addr, size_t to_size)
RetErrno callExitExtended(ThreadContext *tc, uint64_t code, uint64_t subcode)
RetErrno callTmpNam(ThreadContext *tc, Addr buffer, uint64_t id, size_t size)
RetErrno callSeek(ThreadContext *tc, Handle handle, uint64_t pos)
std::vector< std::unique_ptr< FileBase > > files
static const std::vector< const char * > fmodes
RetErrno callSystem(ThreadContext *tc, Addr cmd_addr, size_t cmd_size)
BaseSemihosting(const BaseSemihostingParams &p)
void unserialize(CheckpointIn &cp) override
Unserialize an object.
RetErrno callWrite(ThreadContext *tc, Handle handle, Addr buffer, size_t size)
RetErrno callOpen(ThreadContext *tc, const Addr name_base, int fmode, size_t name_size)
static RetErrno retError(SemiErrno e)
RetErrno callIsError(ThreadContext *tc, int64_t status)
void semiExit(uint64_t code, uint64_t subcode)
RetErrno callElapsed64(ThreadContext *tc, InPlaceArg ticks)
RetErrno callRead(ThreadContext *tc, Handle handle, Addr buffer, size_t size)
const time_t timeBase
Base time when the simulation started.
RetErrno callExit32(ThreadContext *tc, InPlaceArg code)
void serialize(CheckpointOut &cp) const override
Serialize an object.
virtual PortProxy & portProxy(ThreadContext *tc) const =0
static RetErrno retOK(uint64_t r)
void gatherHeapInfo(ThreadContext *tc, bool aarch64, Addr &heap_base, Addr &heap_limit, Addr &stack_base, Addr &stack_limit)
RetErrno callGetCmdLine(ThreadContext *tc, Addr addr, InPlaceArg size_arg)
RetErrno callHeapInfo32(ThreadContext *tc, Addr block_addr)
RetErrno callClock(ThreadContext *tc)
std::optional< std::string > readString(ThreadContext *tc, Addr ptr, size_t len)
RetErrno callRemove(ThreadContext *tc, Addr name_base, size_t name_size)
RetErrno callHeapInfo64(ThreadContext *tc, Addr block_addr)
uint64_t semiTick(Tick tick) const
RetErrno callIsTTY(ThreadContext *tc, Handle handle)
RetErrno callWriteC(ThreadContext *tc, InPlaceArg c)
RetErrno callErrno(ThreadContext *tc)
RetErrno callTime(ThreadContext *tc)
RetErrno callWrite0(ThreadContext *tc, InPlaceArg str)
RetErrno callClose(ThreadContext *tc, Handle handle)
virtual std::string name() const
This object is a proxy for a port or other object which implements the functional response protocol,...
T read(Addr address) const
Read sizeof(T) bytes from address and return as object T.
void write(Addr address, const T &data) const
Write object T to address.
Basic support for object serialization.
Abstract superclass for simulation objects.
ThreadContext is the external interface to all thread state for anything outside of the CPU.
constexpr int findMsbSet(uint64_t val)
Returns the bit position of the MSB that is set in the input.
#define panic(...)
This implements a cprintf based panic() function.
Bitfield< 31, 29 > format
Tick Frequency
The simulated frequency of curTick(). (In ticks per second)
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
std::string dumpSimcall(std::string name, ThreadContext *tc, std::function< Ret(ThreadContext *, Args...)> target=std::function< Ret(ThreadContext *, Args...)>())
std::ostream CheckpointOut
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
uint64_t Tick
Tick count type.
Ret invokeSimcall(ThreadContext *tc, std::function< Ret(ThreadContext *, Args...)> target)
static std::ostream & operator<<(std::ostream &os, const DummyMatRegContainer &d)
PortProxy Object Declaration.
InPlaceArg(Addr _addr, size_t _size)
void write(ThreadContext *tc, PortProxy &proxy, uint64_t val, ByteOrder endian)
uint64_t read(ThreadContext *tc, PortProxy &proxy, ByteOrder endian)
Semihosting call information structure.
std::function< RetErrno(Semihosting *sh, ThreadContext *tc)> Dispatcher
static Dispatcher buildDispatcher(Implementation< SemiImpl, Args... > impl)
static std::function< RetErrno(ThreadContext *tc, Args... args)> wrapImpl(SemiImpl *sh, Implementation< SemiImpl, Args... > impl)
const char * name
Call name.
RetErrno(Impl::*)( ThreadContext *tc, Args... args) Implementation
SemiCallBase(const char *_name, Implementation< SemiImpl, Args32... > impl32, Implementation< SemiImpl, Args64... > impl64)
std::function< std::string(ThreadContext *tc)> Dumper
static Dumper buildDumper(const char *name, Implementation< SemiImpl, Args... > impl)
SemiCallBase(const char *_name, Implementation< SemiImpl, Args... > common)