gem5 v24.0.0.0
Loading...
Searching...
No Matches
gem5::BaseSemihosting Class Referenceabstract

Semihosting for AArch32, AArch64, RISCV-32 and RISCV-64: https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst. More...

#include <semihosting.hh>

Inheritance diagram for gem5::BaseSemihosting:
gem5::SimObject gem5::EventManager gem5::Serializable gem5::Drainable gem5::statistics::Group gem5::Named gem5::ArmSemihosting gem5::RiscvSemihosting

Classes

struct  AbiBase
 
class  File
 
class  FileBase
 Internal state for open files. More...
 
class  FileFeatures
 Implementation of the ':semihosting-features' magic file. More...
 
struct  InPlaceArg
 
struct  SemiCallBase
 Semihosting call information structure. More...
 

Public Types

typedef std::pair< uint64_t, SemiErrnoRetErrno
 
- Public Types inherited from gem5::SimObject
typedef SimObjectParams Params
 

Public Member Functions

void serialize (CheckpointOut &cp) const override
 Serialize an object.
 
void unserialize (CheckpointIn &cp) override
 Unserialize an object.
 
RetErrno callOpen (ThreadContext *tc, const Addr name_base, int fmode, size_t name_size)
 
RetErrno callClose (ThreadContext *tc, Handle handle)
 
RetErrno callWriteC (ThreadContext *tc, InPlaceArg c)
 
RetErrno callWrite0 (ThreadContext *tc, InPlaceArg str)
 
RetErrno callWrite (ThreadContext *tc, Handle handle, Addr buffer, size_t size)
 
RetErrno callRead (ThreadContext *tc, Handle handle, Addr buffer, size_t size)
 
RetErrno callReadC (ThreadContext *tc)
 
RetErrno callIsError (ThreadContext *tc, int64_t status)
 
RetErrno callIsTTY (ThreadContext *tc, Handle handle)
 
RetErrno callSeek (ThreadContext *tc, Handle handle, uint64_t pos)
 
RetErrno callFLen (ThreadContext *tc, Handle handle)
 
RetErrno callTmpNam (ThreadContext *tc, Addr buffer, uint64_t id, size_t size)
 
RetErrno callRemove (ThreadContext *tc, Addr name_base, size_t name_size)
 
RetErrno callRename (ThreadContext *tc, Addr from_addr, size_t from_size, Addr to_addr, size_t to_size)
 
RetErrno callClock (ThreadContext *tc)
 
RetErrno callTime (ThreadContext *tc)
 
RetErrno callSystem (ThreadContext *tc, Addr cmd_addr, size_t cmd_size)
 
RetErrno callErrno (ThreadContext *tc)
 
RetErrno callGetCmdLine (ThreadContext *tc, Addr addr, InPlaceArg size_arg)
 
void gatherHeapInfo (ThreadContext *tc, bool aarch64, Addr &heap_base, Addr &heap_limit, Addr &stack_base, Addr &stack_limit)
 
RetErrno callHeapInfo32 (ThreadContext *tc, Addr block_addr)
 
RetErrno callHeapInfo64 (ThreadContext *tc, Addr block_addr)
 
RetErrno callExit32 (ThreadContext *tc, InPlaceArg code)
 
RetErrno callExit64 (ThreadContext *tc, uint64_t code, uint64_t subcode)
 
RetErrno callExitExtended (ThreadContext *tc, uint64_t code, uint64_t subcode)
 
RetErrno callElapsed32 (ThreadContext *tc, InPlaceArg low, InPlaceArg high)
 
RetErrno callElapsed64 (ThreadContext *tc, InPlaceArg ticks)
 
RetErrno callTickFreq (ThreadContext *tc)
 
template<typename Abi >
void unrecognizedCall (ThreadContext *tc, const char *format, uint64_t op)
 
- Public Member Functions inherited from gem5::SimObject
const Paramsparams () const
 
 SimObject (const Params &p)
 
virtual ~SimObject ()
 
virtual void init ()
 init() is called after all C++ SimObjects have been created and all ports are connected.
 
virtual void loadState (CheckpointIn &cp)
 loadState() is called on each SimObject when restoring from a checkpoint.
 
virtual void initState ()
 initState() is called on each SimObject when not restoring from a checkpoint.
 
virtual void regProbePoints ()
 Register probe points for this object.
 
virtual void regProbeListeners ()
 Register probe listeners for this object.
 
ProbeManagergetProbeManager ()
 Get the probe manager for this object.
 
virtual PortgetPort (const std::string &if_name, PortID idx=InvalidPortID)
 Get a port with a given name and index.
 
virtual void startup ()
 startup() is the final initialization call before simulation.
 
DrainState drain () override
 Provide a default implementation of the drain interface for objects that don't need draining.
 
virtual void memWriteback ()
 Write back dirty buffers to memory using functional writes.
 
virtual void memInvalidate ()
 Invalidate the contents of memory buffers.
 
void serialize (CheckpointOut &cp) const override
 Serialize an object.
 
void unserialize (CheckpointIn &cp) override
 Unserialize an object.
 
- Public Member Functions inherited from gem5::EventManager
EventQueueeventQueue () const
 
void schedule (Event &event, Tick when)
 
void deschedule (Event &event)
 
void reschedule (Event &event, Tick when, bool always=false)
 
void schedule (Event *event, Tick when)
 
void deschedule (Event *event)
 
void reschedule (Event *event, Tick when, bool always=false)
 
void wakeupEventQueue (Tick when=(Tick) -1)
 This function is not needed by the usual gem5 event loop but may be necessary in derived EventQueues which host gem5 on other schedulers.
 
void setCurTick (Tick newVal)
 
 EventManager (EventManager &em)
 Event manger manages events in the event queue.
 
 EventManager (EventManager *em)
 
 EventManager (EventQueue *eq)
 
- Public Member Functions inherited from gem5::Serializable
 Serializable ()
 
virtual ~Serializable ()
 
void serializeSection (CheckpointOut &cp, const char *name) const
 Serialize an object into a new section.
 
void serializeSection (CheckpointOut &cp, const std::string &name) const
 
void unserializeSection (CheckpointIn &cp, const char *name)
 Unserialize an a child object.
 
void unserializeSection (CheckpointIn &cp, const std::string &name)
 
- Public Member Functions inherited from gem5::Drainable
DrainState drainState () const
 Return the current drain state of an object.
 
virtual void notifyFork ()
 Notify a child process of a fork.
 
- Public Member Functions inherited from gem5::statistics::Group
 Group (Group *parent, const char *name=nullptr)
 Construct a new statistics group.
 
virtual ~Group ()
 
virtual void regStats ()
 Callback to set stat parameters.
 
virtual void resetStats ()
 Callback to reset stats.
 
virtual void preDumpStats ()
 Callback before stats are dumped.
 
void addStat (statistics::Info *info)
 Register a stat with this group.
 
const std::map< std::string, Group * > & getStatGroups () const
 Get all child groups associated with this object.
 
const std::vector< Info * > & getStats () const
 Get all stats associated with this object.
 
void addStatGroup (const char *name, Group *block)
 Add a stat block as a child of this block.
 
const InforesolveStat (std::string name) const
 Resolve a stat by its name within this group.
 
void mergeStatGroup (Group *block)
 Merge the contents (stats & children) of a block to this block.
 
 Group ()=delete
 
 Group (const Group &)=delete
 
Groupoperator= (const Group &)=delete
 
- Public Member Functions inherited from gem5::Named
 Named (const std::string &name_)
 
virtual ~Named ()=default
 
virtual std::string name () const
 

Static Public Member Functions

static FILE * getSTDIO (const char *stream_name, const std::string &name, const char *mode)
 
- Static Public Member Functions inherited from gem5::SimObject
static void serializeAll (const std::string &cpt_dir)
 Create a checkpoint by serializing all SimObjects in the system.
 
static SimObjectfind (const char *name)
 Find the SimObject with the given name and return a pointer to it.
 
static void setSimObjectResolver (SimObjectResolver *resolver)
 There is a single object name resolver, and it is only set when simulation is restoring from checkpoints.
 
static SimObjectResolvergetSimObjectResolver ()
 There is a single object name resolver, and it is only set when simulation is restoring from checkpoints.
 
- Static Public Member Functions inherited from gem5::Serializable
static const std::string & currentSection ()
 Gets the fully-qualified name of the active section.
 
static void generateCheckpointOut (const std::string &cpt_dir, std::ofstream &outstream)
 Generate a checkpoint file so that the serialization can be routed to it.
 

Public Attributes

uint16_t tmpNameIndex = 0
 

Static Public Attributes

static const std::vector< const char * > fmodes
 
static const std::map< uint64_t, const char * > exitCodes
 
static const std::array< uint8_t, 5 > features
 
static const std::map< const std::string, FILE * > stdioMap
 

Protected Types

typedef uint64_t SemiErrno
 
using Handle = size_t
 

Protected Member Functions

 BaseSemihosting (const BaseSemihostingParams &p)
 
unsigned calcTickShift () const
 
uint64_t semiTick (Tick tick) const
 
void semiExit (uint64_t code, uint64_t subcode)
 
std::optional< std::string > readString (ThreadContext *tc, Addr ptr, size_t len)
 
- Protected Member Functions inherited from gem5::Drainable
 Drainable ()
 
virtual ~Drainable ()
 
virtual void drainResume ()
 Resume execution after a successful drain.
 
void signalDrainDone () const
 Signal that an object is drained.
 

Static Protected Member Functions

static RetErrno retError (SemiErrno e)
 
static RetErrno retOK (uint64_t r)
 

Protected Attributes

const std::string cmdLine
 
const Addr memReserve
 
const Addr stackSize
 
const time_t timeBase
 Base time when the simulation started.
 
const unsigned tickShift
 Number of bits to right shift gem5 ticks to fit in a uint32_t.
 
SemiErrno semiErrno
 
std::string filesRootDir
 
std::vector< std::unique_ptr< FileBase > > files
 
FILE * stdin
 
FILE * stdout
 
FILE * stderr
 
- Protected Attributes inherited from gem5::SimObject
const SimObjectParams & _params
 Cached copy of the object parameters.
 
- Protected Attributes inherited from gem5::EventManager
EventQueueeventq
 A pointer to this object's event queue.
 

Private Member Functions

virtual PortProxyportProxy (ThreadContext *tc) const =0
 
virtual ByteOrder byteOrder (ThreadContext *tc) const =0
 

Detailed Description

Semihosting for AArch32, AArch64, RISCV-32 and RISCV-64: https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst.

This class implements the Arm semihosting interface. This interface allows baremetal code access service, such as IO, from the simulator. It is conceptually a simplified version of gem5's more general syscall emulation mode.

Note: The RISC-V semihosting specification reuses the Arm semihosting interfaces (https://github.com/riscv-non-isa/riscv-semihosting).

Exits calls (SYS_EXIT, SYS_EXIT_EXTENDED) from the guest get translated into simualtion exits. Well-known exit codes are translated to messages on the form 'semi:ADP_.*' while unknown codes are returned in hex ('semi:0x..'). The subcode is reported in the gem5 exit event.

Definition at line 80 of file semihosting.hh.

Member Typedef Documentation

◆ Handle

using gem5::BaseSemihosting::Handle = size_t
protected

Definition at line 367 of file semihosting.hh.

◆ RetErrno

Definition at line 390 of file semihosting.hh.

◆ SemiErrno

typedef uint64_t gem5::BaseSemihosting::SemiErrno
protected

Definition at line 192 of file semihosting.hh.

Constructor & Destructor Documentation

◆ BaseSemihosting()

gem5::BaseSemihosting::BaseSemihosting ( const BaseSemihostingParams & p)
explicitprotected

Member Function Documentation

◆ byteOrder()

virtual ByteOrder gem5::BaseSemihosting::byteOrder ( ThreadContext * tc) const
privatepure virtual

◆ calcTickShift()

unsigned gem5::BaseSemihosting::calcTickShift ( ) const
inlineprotected

Definition at line 374 of file semihosting.hh.

References gem5::findMsbSet(), and gem5::sim_clock::Frequency.

◆ callClock()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callClock ( ThreadContext * tc)

Definition at line 408 of file semihosting.cc.

References gem5::curTick(), retOK(), and gem5::sim_clock::as_int::s.

◆ callClose()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callClose ( ThreadContext * tc,
Handle handle )

Definition at line 213 of file semihosting.cc.

References DPRINTF, error, files, retError(), and retOK().

◆ callElapsed32()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callElapsed32 ( ThreadContext * tc,
InPlaceArg low,
InPlaceArg high )

◆ callElapsed64()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callElapsed64 ( ThreadContext * tc,
InPlaceArg ticks )

◆ callErrno()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callErrno ( ThreadContext * tc)

Definition at line 431 of file semihosting.cc.

References semiErrno.

◆ callExit32()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callExit32 ( ThreadContext * tc,
InPlaceArg code )

Definition at line 523 of file semihosting.cc.

References gem5::BaseSemihosting::InPlaceArg::addr, retOK(), and semiExit().

◆ callExit64()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callExit64 ( ThreadContext * tc,
uint64_t code,
uint64_t subcode )

Definition at line 530 of file semihosting.cc.

References retOK(), and semiExit().

◆ callExitExtended()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callExitExtended ( ThreadContext * tc,
uint64_t code,
uint64_t subcode )

Definition at line 537 of file semihosting.cc.

References retOK(), and semiExit().

◆ callFLen()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callFLen ( ThreadContext * tc,
Handle handle )

Definition at line 342 of file semihosting.cc.

References files, retError(), and retOK().

◆ callGetCmdLine()

◆ callHeapInfo32()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callHeapInfo32 ( ThreadContext * tc,
Addr block_addr )

◆ callHeapInfo64()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callHeapInfo64 ( ThreadContext * tc,
Addr block_addr )

◆ callIsError()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callIsError ( ThreadContext * tc,
int64_t status )

Definition at line 308 of file semihosting.cc.

References retOK(), and gem5::ArmISA::status.

◆ callIsTTY()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callIsTTY ( ThreadContext * tc,
Handle handle )

Definition at line 314 of file semihosting.cc.

References files, retError(), and retOK().

◆ callOpen()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callOpen ( ThreadContext * tc,
const Addr name_base,
int fmode,
size_t name_size )

◆ callRead()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callRead ( ThreadContext * tc,
Handle handle,
Addr buffer,
size_t size )

◆ callReadC()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callReadC ( ThreadContext * tc)

Definition at line 302 of file semihosting.cc.

References retOK().

◆ callRemove()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callRemove ( ThreadContext * tc,
Addr name_base,
size_t name_size )

Definition at line 378 of file semihosting.cc.

References readString(), retError(), and retOK().

◆ callRename()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callRename ( ThreadContext * tc,
Addr from_addr,
size_t from_size,
Addr to_addr,
size_t to_size )

Definition at line 393 of file semihosting.cc.

References readString(), retError(), retOK(), and gem5::PowerISA::to.

◆ callSeek()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callSeek ( ThreadContext * tc,
Handle handle,
uint64_t pos )

Definition at line 328 of file semihosting.cc.

References files, retError(), and retOK().

◆ callSystem()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callSystem ( ThreadContext * tc,
Addr cmd_addr,
size_t cmd_size )

Definition at line 420 of file semihosting.cc.

References readString(), retError(), and warn.

◆ callTickFreq()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callTickFreq ( ThreadContext * tc)

Definition at line 577 of file semihosting.cc.

References gem5::sim_clock::Frequency, retOK(), and semiTick().

◆ callTime()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callTime ( ThreadContext * tc)

Definition at line 414 of file semihosting.cc.

References gem5::curTick(), retOK(), gem5::sim_clock::as_float::s, and timeBase.

◆ callTmpNam()

◆ callWrite()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callWrite ( ThreadContext * tc,
Handle handle,
Addr buffer,
size_t size )

Definition at line 260 of file semihosting.cc.

References gem5::X86ISA::addr, files, portProxy(), and gem5::PortProxy::readBlob().

◆ callWrite0()

BaseSemihosting::RetErrno gem5::BaseSemihosting::callWrite0 ( ThreadContext * tc,
InPlaceArg str )

◆ callWriteC()

◆ gatherHeapInfo()

void gem5::BaseSemihosting::gatherHeapInfo ( ThreadContext * tc,
bool aarch64,
Addr & heap_base,
Addr & heap_limit,
Addr & stack_base,
Addr & stack_limit )

◆ getSTDIO()

FILE * gem5::BaseSemihosting::getSTDIO ( const char * stream_name,
const std::string & name,
const char * mode )
static

Definition at line 583 of file semihosting.cc.

References gem5::ArmISA::f, fatal, gem5::ArmISA::mode, gem5::Named::name(), and stdioMap.

◆ portProxy()

virtual PortProxy & gem5::BaseSemihosting::portProxy ( ThreadContext * tc) const
privatepure virtual

◆ readString()

std::optional< std::string > gem5::BaseSemihosting::readString ( ThreadContext * tc,
Addr ptr,
size_t len )
protected

◆ retError()

◆ retOK()

◆ semiExit()

void gem5::BaseSemihosting::semiExit ( uint64_t code,
uint64_t subcode )
protected

Definition at line 545 of file semihosting.cc.

References gem5::csprintf(), exitCodes, and gem5::exitSimLoop().

Referenced by callExit32(), callExit64(), and callExitExtended().

◆ semiTick()

uint64_t gem5::BaseSemihosting::semiTick ( Tick tick) const
inlineprotected

Definition at line 380 of file semihosting.hh.

References tickShift.

Referenced by callElapsed32(), callElapsed64(), and callTickFreq().

◆ serialize()

void gem5::BaseSemihosting::serialize ( CheckpointOut & cp) const
overridevirtual

Serialize an object.

Output an object's state into the current checkpoint section.

Parameters
cpCheckpoint state

Implements gem5::Serializable.

Definition at line 134 of file semihosting.cc.

References gem5::csprintf(), files, gem5::ArmISA::i, gem5::paramOut(), semiErrno, and SERIALIZE_SCALAR.

◆ unrecognizedCall()

template<typename Abi >
void gem5::BaseSemihosting::unrecognizedCall ( ThreadContext * tc,
const char * format,
uint64_t op )
inline

◆ unserialize()

void gem5::BaseSemihosting::unserialize ( CheckpointIn & cp)
overridevirtual

Unserialize an object.

Read an object's state from the current checkpoint section.

Parameters
cpCheckpoint state

Implements gem5::Serializable.

Definition at line 149 of file semihosting.cc.

References gem5::BaseSemihosting::FileBase::create(), gem5::csprintf(), files, gem5::ArmISA::i, gem5::paramIn(), semiErrno, and UNSERIALIZE_SCALAR.

Member Data Documentation

◆ cmdLine

const std::string gem5::BaseSemihosting::cmdLine
protected

Definition at line 178 of file semihosting.hh.

Referenced by callGetCmdLine().

◆ exitCodes

const std::map< uint64_t, const char * > gem5::BaseSemihosting::exitCodes
static
Initial value:
{
{0x20000, "semi:ADP_Stopped_BranchThroughZero"},
{0x20001, "semi:ADP_Stopped_UndefinedInstr"},
{0x20002, "semi:ADP_Stopped_SoftwareInterrupt"},
{0x20003, "semi:ADP_Stopped_PrefetchAbort"},
{0x20004, "semi:ADP_Stopped_DataAbort"},
{0x20005, "semi:ADP_Stopped_AddressException"},
{0x20006, "semi:ADP_Stopped_IRQ"},
{0x20007, "semi:ADP_Stopped_FIQ"},
{0x20020, "semi:ADP_Stopped_BreakPoint"},
{0x20021, "semi:ADP_Stopped_WatchPoint"},
{0x20022, "semi:ADP_Stopped_StepComplete"},
{0x20023, "semi:ADP_Stopped_RunTimeErrorUnknown"},
{0x20024, "semi:ADP_Stopped_InternalError"},
{0x20025, "semi:ADP_Stopped_UserInterruption"},
{0x20026, "semi:ADP_Stopped_ApplicationExit"},
{0x20027, "semi:ADP_Stopped_StackOverflow"},
{0x20028, "semi:ADP_Stopped_DivisionByZero"},
{0x20029, "semi:ADP_Stopped_DivisionByZero"},
}

Definition at line 546 of file semihosting.hh.

Referenced by semiExit().

◆ features

const std::array< uint8_t, 5 > gem5::BaseSemihosting::features
static
Initial value:
{
0x53, 0x48, 0x46, 0x42,
0x3,
}

Definition at line 547 of file semihosting.hh.

Referenced by gem5::BaseSemihosting::FileFeatures::flen(), gem5::BaseSemihosting::FileFeatures::read(), and gem5::BaseSemihosting::FileFeatures::seek().

◆ files

std::vector<std::unique_ptr<FileBase> > gem5::BaseSemihosting::files
protected

◆ filesRootDir

std::string gem5::BaseSemihosting::filesRootDir
protected

Definition at line 365 of file semihosting.hh.

Referenced by callOpen().

◆ fmodes

const std::vector< const char * > gem5::BaseSemihosting::fmodes
static
Initial value:
{
"r",
"rb",
"r+",
"r+b",
"w",
"wb",
"w+",
"w+b",
"a",
"ab",
"a+",
"a+b",
}

Definition at line 545 of file semihosting.hh.

Referenced by callOpen().

◆ memReserve

const Addr gem5::BaseSemihosting::memReserve
protected

Definition at line 179 of file semihosting.hh.

Referenced by gatherHeapInfo().

◆ semiErrno

◆ stackSize

const Addr gem5::BaseSemihosting::stackSize
protected

Definition at line 180 of file semihosting.hh.

Referenced by gatherHeapInfo().

◆ stderr

FILE* gem5::BaseSemihosting::stderr
protected

Definition at line 370 of file semihosting.hh.

◆ stdin

FILE* gem5::BaseSemihosting::stdin
protected

Definition at line 368 of file semihosting.hh.

◆ stdioMap

const std::map< const std::string, FILE * > gem5::BaseSemihosting::stdioMap
static
Initial value:
{
{"cin", ::stdin},
{"stdin", ::stdin},
{"cout", ::stdout},
{"stdout", ::stdout},
{"cerr", ::stderr},
{"stderr", ::stderr},
}

Definition at line 548 of file semihosting.hh.

Referenced by getSTDIO().

◆ stdout

FILE* gem5::BaseSemihosting::stdout
protected

Definition at line 369 of file semihosting.hh.

◆ tickShift

const unsigned gem5::BaseSemihosting::tickShift
protected

Number of bits to right shift gem5 ticks to fit in a uint32_t.

Definition at line 189 of file semihosting.hh.

Referenced by semiTick().

◆ timeBase

const time_t gem5::BaseSemihosting::timeBase
protected

Base time when the simulation started.

This is used to calculate the time of date when the guest call SYS_TIME.

Definition at line 186 of file semihosting.hh.

Referenced by callTime().

◆ tmpNameIndex

uint16_t gem5::BaseSemihosting::tmpNameIndex = 0

Definition at line 551 of file semihosting.hh.

Referenced by callTmpNam().


The documentation for this class was generated from the following files:

Generated on Tue Jun 18 2024 16:24:10 for gem5 by doxygen 1.11.0