7d0b8767c74140c64a685e5da24d9bed792bd158
[riscv-tests.git] / debug / programs / debug.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdint.h>
4
5 unsigned int crc32a(uint8_t *message, unsigned int size);
6
7 char __malloc_start[512];
8
9 void rot13(char *buf)
10 {
11 while (*buf) {
12 if ((*buf >= 'a' && *buf <= 'm') ||
13 (*buf >= 'A' && *buf <= 'M')) {
14 *buf += 13;
15 } else if ((*buf >= 'n' && *buf <= 'z') ||
16 (*buf >= 'N' && *buf <= 'Z')) {
17 *buf -= 13;
18 }
19 buf++;
20 }
21 }
22
23 size_t strlen(const char *buf)
24 {
25 int len = 0;
26 while (buf[len])
27 len++;
28 return len;
29 }
30
31 // TODO: These should be local to main, but if I make them global then gdb can
32 // find them.
33 static volatile int i;
34 static int j;
35 int main()
36 {
37 i = 0;
38 j = 0;
39 char *fox = "The quick brown fox jumps of the lazy dog.";
40 unsigned int checksum = 0;
41
42 start:
43 while (i)
44 j++;
45
46 rot13(fox);
47 checksum ^= crc32a(fox, strlen(fox));
48 rot13(fox);
49 checksum ^= crc32a(fox, strlen(fox));
50
51 return checksum;
52 }