12 #define TICKER_FREQ 1000
15 const char *
SYS_OPEN_MODES_STRS[] = {
"r",
"rb",
"r+",
"r+b",
"w",
"wb",
"w+",
"w+b",
"a",
"ab",
"a+",
"a+b" };
16 #define SYS_OPEN_MODES_TOTAL 12
17 #define SYS_OPEN_MODES_IN_LIMIT 4
18 #define SYS_OPEN_MODES_OUT_LIMIT 8
20 #define PS_PER_CS 10000000000
23 #define CHECK_NEGATIVE_RETURN(var) \
26 semihostingErrno = errno; \
31 #define FIELD(fieldNo) semihostReadStructField(etissSystem, XLEN / 8, parameter, fieldNo);
45 return etiss::cfg().
get<
bool>(
"arch.enable_semihosting",
false);
67 else if (numBytes == 4)
73 else if (numBytes == 2)
79 else if (numBytes == 1)
82 etissSystem->
dbg_read(etissSystem->
handle, address + 1 * fieldNo, &field, 1);
93 std::vector<etiss_uint8> buffer;
102 etissSystem->
dbg_write(etissSystem->
handle, address, data.data(), data.size());
109 std::string
str(buffer.begin(), buffer.end());
121 return file == stdin || file == stdout || file == stderr;
131 static std::map<etiss_uint64, FILE *> openFiles;
139 switch (operationNumber)
151 if (openFiles.count(fd) == 0)
153 std::stringstream ss;
154 ss <<
"Semihosting: invalid file descriptor " << fd <<
" for semihosting call 0x" << std::hex
155 << std::setfill(
'0') << std::setw(2) << operationNumber;
157 semihostingErrno = EBADF;
160 auto file = openFiles[fd];
162 switch (operationNumber)
166 std::stringstream ss;
167 ss <<
"Semihosting: SYS_CLOSE fd " << fd;
181 std::stringstream ss;
182 ss <<
"Semihosting: SYS_WRITE fd " << fd;
187 size_t num_written = fwrite(buffer.data(), 1, count, file);
188 return count - num_written;
195 std::stringstream ss;
196 ss <<
"Semihosting: SYS_READ fd " << fd <<
" count " << count;
199 std::vector<etiss_uint8> buffer;
200 buffer.resize(count);
207 while (num_read < count)
209 char c = fgetc(file);
210 buffer[num_read] =
c;
218 num_read = fread(buffer.data(), 1, count, file);
221 buffer.resize(num_read);
228 std::stringstream ss;
229 ss <<
"Semihosting: SYS_ISTTY fd " << fd;
238 std::stringstream ss;
239 ss <<
"Semihosting: SYS_SEEK fd " << fd <<
": " << position;
242 int retval = fseek(file, position, SEEK_SET);
248 std::stringstream ss;
249 ss <<
"Semihosting: SYS_FLEN fd " << fd;
252 size_t currentPos = ftell(file);
254 fseek(file, 0, SEEK_END);
255 size_t length = ftell(file);
256 fseek(file, currentPos, SEEK_SET);
269 std::stringstream ss;
270 ss <<
"Semihosting: SYS_OPEN \"" << path_str <<
"\"";
276 semihostingErrno = EINVAL;
280 FILE *file =
nullptr;
281 if (path_str ==
":tt")
297 semihostingErrno = errno;
302 openFiles[fd] = file;
340 if (identifier > 255)
343 std::stringstream ss;
344 ss <<
"etiss-tmp/file-" << std::setfill(
'0') << std::setw(3) << identifier;
345 std::string filename = ss.str();
347 if (buffer_len <= filename.length() + 1)
360 std::stringstream ss;
361 ss <<
"Semihosting: SYS_REMOVE \"" << path_str <<
"\"";
364 if (remove(path_str.c_str()) < 0)
366 semihostingErrno = errno;
381 std::stringstream ss;
382 ss <<
"Semihosting: SYS_RENAME \"" << old_str <<
"\" to \"" << new_str <<
"\"";
385 return rename(old_str.c_str(), new_str.c_str());
396 return seconds_since_epoch;
400 std::stringstream ss;
401 ss <<
"Semihosting: SYS_ERRNO (" << semihostingErrno <<
")";
403 return semihostingErrno;
409 cpu->
exception = ETISS_RETURNCODE_CPUFINISHED;
426 std::stringstream ss;
427 ss <<
"Semihosting: operation not implemented: " << operationNumber;
433 std::stringstream ss;
434 ss <<
"Semihosting: unknown operation number: " << operationNumber;
Header file of the ETISS library.
__device__ __2f16 float c
static __inline__ uint32_t
static __inline__ uint64_t
static __inline__ uint8_t
#define SYS_EXIT_EXTENDED
T get(const std::string &key, T default_, bool *default_used=0)
template function to read the value of a configuration key.
Configuration & cfg(const std::string &cfgName)
Get reference of the global ETISS configuration object.
void log(Verbosity level, std::string msg)
write log message at the given level.
float __ovld __cnfn length(float p)
Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)
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
#define SYS_OPEN_MODES_TOTAL
uint8_t etiss_semihost_enabled()
Checks whether semihosting is enabled in the config.
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
bool is_std_in_out_err(FILE *file)
void semihostWriteString(ETISS_System *etissSystem, etiss_uint64 address, std::string str)
helper for writing a std::string to an etiss system
#define SYS_OPEN_MODES_OUT_LIMIT
#define SYS_OPEN_MODES_IN_LIMIT
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.
#define CHECK_NEGATIVE_RETURN(var)
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.
const char * SYS_OPEN_MODES_STRS[]
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
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.
basic cpu state structure needed for execution of any cpu architecture.
etiss_uint64 cpuTime_ps
simulation time of cpu
etiss_uint32 return_pending
memory access and time synchronization functions.
void * handle
custom handle that will be passed to the functions of this structure
etiss_int32(* dbg_write)(void *handle, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
direct debug write
etiss_int32(* dbg_read)(void *handle, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
direct debug read