Merge pull request #17 from timsifive/debug
[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 void rot13(char *buf)
9 {
10 while (*buf) {
11 if ((*buf >= 'a' && *buf <= 'm') ||
12 (*buf >= 'A' && *buf <= 'M')) {
13 *buf += 13;
14 } else if ((*buf >= 'n' && *buf <= 'z') ||
15 (*buf >= 'N' && *buf <= 'Z')) {
16 *buf -= 13;
17 }
18 buf++;
19 }
20 }
21
22 size_t strlen(const char *buf)
23 {
24 int len = 0;
25 while (buf[len])
26 len++;
27 return len;
28 }
29
30 extern void *__malloc_freelist;
31
32 int main()
33 {
34 __malloc_freelist = 0;
35
36 volatile int i = 0;
37 int j = 0;
38 char *fox = "The quick brown fox jumps of the lazy dog.";
39 unsigned int checksum = 0;
40
41 start:
42 while (i)
43 j++;
44
45 rot13(fox);
46 checksum ^= crc32a(fox, strlen(fox));
47 rot13(fox);
48 checksum ^= crc32a(fox, strlen(fox));
49
50 return checksum;
51 }