Add syscalls for cycles elapsed and current time
MODIFY
src/isainfo.h
src/isainfo.h
@@ -128,6 +128,8 @@ public:
Exit = 10,
PrintChar = 11,
GetCWD = 17,
+ TimeMs = 30,
+ Cycles = 31,
PrintIntHex = 34,
PrintIntBinary = 35,
PrintIntUnsigned = 36,

MODIFY
src/syscall/riscv_syscall.h
src/syscall/riscv_syscall.h
#include "control.h"
#include "file.h"
#include "print.h"
+#include "syscall_time.h"
namespace Ripes {
@@ -58,6 +59,10 @@ public:
emplace<WriteSyscall<RISCVSyscall>>(ISAInfo<ISA::RV32IM>::Write);
emplace<GetCWDSyscall<RISCVSyscall>>(ISAInfo<ISA::RV32IM>::GetCWD);
emplace<FStatSyscall<RISCVSyscall>>(ISAInfo<ISA::RV32IM>::FStat);
+
+ // Time syscalls
+ emplace<CyclesSyscall<RISCVSyscall>>(ISAInfo<ISA::RV32IM>::Cycles);
+ emplace<TimeMsSyscall<RISCVSyscall>>(ISAInfo<ISA::RV32IM>::TimeMs);
}
};

ADD
src/syscall/syscall_time.h
+#pragma once
+
+#include <type_traits>
+
+#include "processorhandler.h"
+#include "ripes_syscall.h"
+#include "systemio.h"
+
+#include <QDateTime>
+
+namespace Ripes {
+template <typename BaseSyscall>
+class CyclesSyscall : public BaseSyscall {
+ static_assert(std::is_base_of<Syscall, BaseSyscall>::value);
+
+public:
+ CyclesSyscall()
+ : BaseSyscall("Cycles", "Get number of cycles elapsed since program start", {},
+ {{0, "low 32 bits of cycles elapsed"}, {1, "high 32 bits of cycles elapsed"}}) {}
+ void execute() {
+ static long long cycleCount = ProcessorHandler::get()->getProcessor()->getCycleCount();
+ BaseSyscall::setRet(0, cycleCount & 0xFFFFFFFF);
+ BaseSyscall::setRet(1, (cycleCount >> 32) & 0xFFFFFFFF);
+ }
+};
+
+template <typename BaseSyscall>
+class TimeMsSyscall : public BaseSyscall {
+ static_assert(std::is_base_of<Syscall, BaseSyscall>::value);
+
+public:
+ TimeMsSyscall()
+ : BaseSyscall(
+ "Time_msec", "Get the current time since epoch (milliseconds since 1 January 1970)", {},
+ {{0, "low 32 bits of milliseconds since epoch"}, {1, "high 32 bits of milliseconds since epoch"}}) {}
+ void execute() {
+ static long long ms = QDateTime::currentMSecsSinceEpoch();
+ BaseSyscall::setRet(0, ms & 0xFFFFFFFF);
+ BaseSyscall::setRet(1, (ms >> 32) & 0xFFFFFFFF);
+ }
+};
+
+} // namespace Ripes

Add syscalls for cycles elapsed and current time