Create TriggerTest.
[riscv-tests.git] / debug / programs / debug.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdint.h>
4 #include <stdlib.h>
5
6 unsigned int crc32a(uint8_t *message, unsigned int size);
7
8 unsigned int fib(unsigned int n)
9 {
10 if (n == 0) {
11 return 0;
12 }
13
14 unsigned int a = 0;
15 unsigned int b = 1;
16
17 for (unsigned int i = 1; i < n; i++) {
18 unsigned int next = a + b;
19 a = b;
20 b = next;
21 }
22
23 return b;
24 }
25
26 void rot13(char *buf)
27 {
28 while (*buf) {
29 if ((*buf >= 'a' && *buf <= 'm') ||
30 (*buf >= 'A' && *buf <= 'M')) {
31 *buf += 13;
32 } else if ((*buf >= 'n' && *buf <= 'z') ||
33 (*buf >= 'N' && *buf <= 'Z')) {
34 *buf -= 13;
35 }
36 buf++;
37 }
38 }
39
40 size_t strlen(const char *buf)
41 {
42 int len = 0;
43 while (buf[len])
44 len++;
45 return len;
46 }
47
48 extern void *__malloc_freelist;
49
50 int main()
51 {
52 __malloc_freelist = 0;
53
54 volatile int i = 0;
55 int j = 0;
56 char *fox = "The quick brown fox jumps of the lazy dog.";
57 unsigned int checksum = 0;
58
59 start:
60 while (i)
61 j++;
62
63 rot13(fox);
64 checksum ^= crc32a(fox, strlen(fox));
65 rot13(fox);
66 checksum ^= crc32a(fox, strlen(fox));
67
68 return checksum;
69 }