summaryrefslogtreecommitdiff
path: root/software/dhrystone/dhry_stubs.c
diff options
context:
space:
mode:
Diffstat (limited to 'software/dhrystone/dhry_stubs.c')
-rw-r--r--software/dhrystone/dhry_stubs.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/software/dhrystone/dhry_stubs.c b/software/dhrystone/dhry_stubs.c
new file mode 100644
index 0000000..d384bf1
--- /dev/null
+++ b/software/dhrystone/dhry_stubs.c
@@ -0,0 +1,31 @@
+#include "platform.h"
+
+/* The functions in this file are only meant to support Dhrystone on an
+ * embedded RV32 system and are obviously incorrect in general. */
+
+// return the cycle counter as though it were the current time
+long time(void)
+{
+ long t;
+ asm volatile ("csrr %0, mcycle" : "=r" (t));
+ return t / (get_cpu_freq() / 1000);
+}
+
+// set the number of dhrystone iterations
+void scanf(const char* fmt, int* n)
+{
+ *n = 1500000;
+}
+
+// simple memory allocator
+void* malloc(unsigned long sz)
+{
+ extern void* sbrk(long);
+ void* res = sbrk(sz);
+ if ((long)res == -1)
+ return 0;
+ return res;
+}
+
+// simple memory deallocator
+void free(void* ptr) {}