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