debug: Fixing the non-RTOS behavior for DownloadTest
[riscv-tests.git] / debug / programs / debug.c
index 7d0b8767c74140c64a685e5da24d9bed792bd158..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,14 +45,14 @@ size_t strlen(const char *buf)
     return len;
 }
 
-// TODO: These should be local to main, but if I make them global then gdb can
-// find them.
-static volatile int i;
-static int j;
+extern void *__malloc_freelist;
+
 int main()
 {
-    i = 0;
-    j = 0;
+    __malloc_freelist = 0;
+
+    volatile int i = 0;
+    int j = 0;
     char *fox = "The quick brown fox jumps of the lazy dog.";
     unsigned int checksum = 0;