#include "semihosting.h" #include #include #include // explanation of syscalls can be found at https://github.com/SpinalHDL/openocd_riscv/blob/riscv_spinal/src/target/semihosting_common.h template void semihosting_callback(iss::arch_if* arch_if_ptr, T call_number, T parameter) { switch(static_cast(call_number)) { case semihosting_syscalls::SYS_CLOCK: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_CLOSE: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_ELAPSED: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_ERRNO: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_EXIT: { throw std::runtime_error("ISS terminated by Semihost: SYS_EXIT"); break; } case semihosting_syscalls::SYS_EXIT_EXTENDED: { throw std::runtime_error("ISS terminated by Semihost: SYS_EXIT_EXTENDED"); break; } case semihosting_syscalls::SYS_FLEN: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_GET_CMDLINE: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_HEAPINFO: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_ISERROR: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_ISTTY: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_OPEN: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_READ: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_READC: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_REMOVE: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_RENAME: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_SEEK: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_SYSTEM: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_TICKFREQ: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_TIME: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_TMPNAM: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_WRITE: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::SYS_WRITEC: { uint8_t character; auto res = arch_if_ptr->read(iss::address_type::PHYSICAL, iss::access_type::DEBUG_READ, 0, parameter, 1, &character); if(res != iss::Ok) return; putchar(character); break; } case semihosting_syscalls::SYS_WRITE0: { uint8_t character; while(1) { auto res = arch_if_ptr->read(iss::address_type::PHYSICAL, iss::access_type::DEBUG_READ, 0, parameter, 1, &character); if(res != iss::Ok) return; if(character == 0) break; putchar(character); parameter++; } break; } case semihosting_syscalls::USER_CMD_0x100: { throw std::runtime_error("Semihosting Call not Implemented"); break; } case semihosting_syscalls::USER_CMD_0x1FF: { throw std::runtime_error("Semihosting Call not Implemented"); break; } default: throw std::runtime_error("Semihosting Call not Implemented"); break; } } template void semihosting_callback(iss::arch_if* arch_if_ptr, uint32_t call_number, uint32_t parameter); template void semihosting_callback(iss::arch_if* arch_if_ptr, uint64_t call_number, uint64_t parameter);