Add abort() for benefit of benchmark code
[riscv-tests.git] / debug / programs / debug.c
index 2010eaa898a6c7ccbd272a99f942ea9c62608be1..3ba51bca9249cd768ee298515ac2456477eccdad 100644 (file)
@@ -1,10 +1,27 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
+#include <stdlib.h>
 
 unsigned int crc32a(uint8_t *message, unsigned int size);
 
-char __malloc_start[512];
+unsigned int fib(unsigned int n)
+{
+    if (n == 0) {
+        return 0;
+    }
+
+    unsigned int a = 0;
+    unsigned int b = 1;
+
+    for (unsigned int i = 1; i < n; i++) {
+        unsigned int next = a + b;
+        a = b;
+        b = next;
+    }
+
+    return b;
+}
 
 void rot13(char *buf)
 {
@@ -28,8 +45,12 @@ size_t strlen(const char *buf)
     return len;
 }
 
+extern void *__malloc_freelist;
+
 int main()
 {
+    __malloc_freelist = 0;
+
     volatile int i = 0;
     int j = 0;
     char *fox = "The quick brown fox jumps of the lazy dog.";