ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
Macros | Functions | Variables
semihost.cpp File Reference
#include <cstdio>
#include "etiss/ETISS.h"
#include "SemihostingCalls.h"
#include "libsemihost.h"
Include dependency graph for semihost.cpp:

Go to the source code of this file.

Macros

#define TICKER_FREQ   1000
 
#define SYS_OPEN_MODES_TOTAL   12
 
#define SYS_OPEN_MODES_IN_LIMIT   4
 
#define SYS_OPEN_MODES_OUT_LIMIT   8
 
#define PS_PER_CS   10000000000
 
#define CHECK_NEGATIVE_RETURN(var)
 
#define FIELD(fieldNo)   semihostReadStructField(etissSystem, XLEN / 8, parameter, fieldNo);
 

Functions

etiss_int64 semihostingCall (ETISS_CPU *const cpu, ETISS_System *const etissSystem, etiss_uint32 XLEN, etiss_uint64 operationNumber, etiss_uint64 parameter)
 Executes the semihosting call based on the operation number. More...
 
uint8_t etiss_semihost_enabled ()
 Checks whether semihosting is enabled in the config. More...
 
int64_t etiss_semihost (ETISS_CPU *const cpu, ETISS_System *const etissSystem, void *const *const _, uint32_t XLEN, uint64_t operation, uint64_t parameter)
 Executes the semihosting call based on the operation number. More...
 
etiss_uint64 semihostReadStructField (ETISS_System *etissSystem, etiss_uint32 numBytes, etiss_uint64 address, int fieldNo)
 Assumes there is an array of numBytes long integers at address. More...
 
std::vector< etiss_uint8semihostReadSystemMemory (ETISS_System *etissSystem, etiss_uint64 address, etiss_uint64 length)
 helper for reading a std::vector of bytes by address and length from an etiss system More...
 
void semihostWriteSystemMemory (ETISS_System *etissSystem, etiss_uint64 address, std::vector< etiss_uint8 > data)
 helper for writing a std::vector of bytes to an etiss system More...
 
std::string semihostReadString (ETISS_System *etissSystem, etiss_uint64 address, etiss_uint64 length)
 helper for reading a std::string by address and length from an etiss system More...
 
void semihostWriteString (ETISS_System *etissSystem, etiss_uint64 address, std::string str)
 helper for writing a std::string to an etiss system More...
 
bool is_std_in_out_err (FILE *file)
 

Variables

const char * SYS_OPEN_MODES_STRS [] = { "r", "rb", "r+", "r+b", "w", "wb", "w+", "w+b", "a", "ab", "a+", "a+b" }
 

Macro Definition Documentation

◆ CHECK_NEGATIVE_RETURN

#define CHECK_NEGATIVE_RETURN (   var)
Value:
if ((var) < 0) \
{ \
semihostingErrno = errno; \
return -1; \
}

Definition at line 23 of file semihost.cpp.

◆ FIELD

#define FIELD (   fieldNo)    semihostReadStructField(etissSystem, XLEN / 8, parameter, fieldNo);

Definition at line 31 of file semihost.cpp.

◆ PS_PER_CS

#define PS_PER_CS   10000000000

Definition at line 20 of file semihost.cpp.

◆ SYS_OPEN_MODES_IN_LIMIT

#define SYS_OPEN_MODES_IN_LIMIT   4

Definition at line 17 of file semihost.cpp.

◆ SYS_OPEN_MODES_OUT_LIMIT

#define SYS_OPEN_MODES_OUT_LIMIT   8

Definition at line 18 of file semihost.cpp.

◆ SYS_OPEN_MODES_TOTAL

#define SYS_OPEN_MODES_TOTAL   12

Definition at line 16 of file semihost.cpp.

◆ TICKER_FREQ

#define TICKER_FREQ   1000

Definition at line 12 of file semihost.cpp.

Function Documentation

◆ etiss_semihost()

int64_t etiss_semihost ( ETISS_CPU *const  cpu,
ETISS_System *const  etissSystem,
void *const *const  _,
uint32_t  XLEN,
uint64_t  operation,
uint64_t  parameter 
)

Executes the semihosting call based on the operation number.

For description of all semihosting calls see: https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst

Definition at line 48 of file semihost.cpp.

References semihostingCall().

Here is the call graph for this function:

◆ etiss_semihost_enabled()

uint8_t etiss_semihost_enabled ( )

Checks whether semihosting is enabled in the config.

Definition at line 43 of file semihost.cpp.

References etiss::cfg(), and etiss::Configuration::get().

Here is the call graph for this function:

◆ is_std_in_out_err()

bool is_std_in_out_err ( FILE *  file)

Definition at line 119 of file semihost.cpp.

Referenced by semihostingCall().

Here is the caller graph for this function:

◆ semihostingCall()

etiss_int64 semihostingCall ( ETISS_CPU *const  cpu,
ETISS_System *const  etissSystem,
etiss_uint32  XLEN,
etiss_uint64  operationNumber,
etiss_uint64  parameter 
)

Executes the semihosting call based on the operation number.

For description of all semihosting calls see: https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst

openFiles maps target file descriptors (uint) to host file descriptors (FILE *).

next target file descriptor to be allocated. starts at 0 for first target fd (stdin)

Local errno variable to set in semihosting functions and return using SYS_ERRNO

Definition at line 124 of file semihost.cpp.

References c, CHECK_NEGATIVE_RETURN, ETISS_CPU::cpuTime_ps, ETISS_CPU::exception, FIELD, etiss::INFO, is_std_in_out_err(), length(), etiss::log(), get_metrics::mode, PS_PER_CS, ETISS_CPU::return_pending, semihostReadString(), semihostReadStructField(), semihostReadSystemMemory(), semihostWriteString(), semihostWriteSystemMemory(), SYS_CLOCK, SYS_CLOSE, SYS_ELAPSED, SYS_ERRNO, SYS_EXIT, SYS_EXIT_EXTENDED, SYS_FLEN, SYS_GET_CMDLINE, SYS_HEAPINFO, SYS_ISERROR, SYS_ISTTY, SYS_OPEN, SYS_OPEN_MODES_IN_LIMIT, SYS_OPEN_MODES_OUT_LIMIT, SYS_OPEN_MODES_STRS, SYS_OPEN_MODES_TOTAL, SYS_READ, SYS_READC, SYS_REMOVE, SYS_RENAME, SYS_SEEK, SYS_SYSTEM, SYS_TICKFREQ, SYS_TIME, SYS_TMPNAM, SYS_WRITE, SYS_WRITE0, SYS_WRITEC, TICKER_FREQ, etiss::VERBOSE, and etiss::WARNING.

Referenced by etiss_semihost().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ semihostReadString()

std::string semihostReadString ( ETISS_System etissSystem,
etiss_uint64  address,
etiss_uint64  length 
)

helper for reading a std::string by address and length from an etiss system

Definition at line 106 of file semihost.cpp.

References length(), semihostReadSystemMemory(), and get_metrics::str.

Referenced by semihostingCall().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ semihostReadStructField()

etiss_uint64 semihostReadStructField ( ETISS_System etissSystem,
etiss_uint32  numBytes,
etiss_uint64  address,
int  fieldNo 
)

Assumes there is an array of numBytes long integers at address.

Reads the filedNo-th field of this array an returns it as a uint64 (0-indexed)

Definition at line 58 of file semihost.cpp.

References ETISS_System::dbg_read, etiss::ERROR, ETISS_System::handle, and etiss::log().

Referenced by semihostingCall().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ semihostReadSystemMemory()

std::vector<etiss_uint8> semihostReadSystemMemory ( ETISS_System etissSystem,
etiss_uint64  address,
etiss_uint64  length 
)

helper for reading a std::vector of bytes by address and length from an etiss system

Definition at line 91 of file semihost.cpp.

References ETISS_System::dbg_read, ETISS_System::handle, and length().

Referenced by semihostingCall(), and semihostReadString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ semihostWriteString()

void semihostWriteString ( ETISS_System etissSystem,
etiss_uint64  address,
std::string  str 
)

helper for writing a std::string to an etiss system

Definition at line 114 of file semihost.cpp.

References ETISS_System::dbg_write, ETISS_System::handle, and get_metrics::str.

Referenced by semihostingCall().

Here is the caller graph for this function:

◆ semihostWriteSystemMemory()

void semihostWriteSystemMemory ( ETISS_System etissSystem,
etiss_uint64  address,
std::vector< etiss_uint8 data 
)

helper for writing a std::vector of bytes to an etiss system

Definition at line 100 of file semihost.cpp.

References ETISS_System::dbg_write, and ETISS_System::handle.

Referenced by semihostingCall().

Here is the caller graph for this function:

Variable Documentation

◆ SYS_OPEN_MODES_STRS

const char* SYS_OPEN_MODES_STRS[] = { "r", "rb", "r+", "r+b", "w", "wb", "w+", "w+b", "a", "ab", "a+", "a+b" }

Definition at line 15 of file semihost.cpp.

Referenced by semihostingCall().