diff options
Diffstat (limited to 'tests/simple_fat_bfly/test.c')
| -rw-r--r-- | tests/simple_fat_bfly/test.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/simple_fat_bfly/test.c b/tests/simple_fat_bfly/test.c new file mode 100644 index 0000000..2e4a22c --- /dev/null +++ b/tests/simple_fat_bfly/test.c @@ -0,0 +1,52 @@ +__attribute__((always_inline)) +static inline char hex_char(unsigned x) +{ + if (x <= 9) + return x + '0'; + + return (x - 10) + 'a'; +} + +__attribute__((always_inline)) +static inline void print_int32(volatile char *uart, unsigned x) +{ + *uart = hex_char((x >> 28) & 0xf); + *uart = hex_char((x >> 24) & 0xf); + *uart = hex_char((x >> 20) & 0xf); + *uart = hex_char((x >> 16) & 0xf); + *uart = hex_char((x >> 12) & 0xf); + *uart = hex_char((x >> 8) & 0xf); + *uart = hex_char((x >> 4) & 0xf); + *uart = hex_char((x >> 0) & 0xf); +} + +__attribute__((always_inline)) +static inline void print_addr(volatile char *uart, unsigned x) +{ + *uart = '('; + print_int32(uart, x); + *uart = ')'; + *uart = '\n'; +} + +void _start(unsigned x, unsigned X) +{ + volatile char *uart = (char *)4096; + volatile unsigned *control = (unsigned *)(1ULL << 32); + + if (x == 2) { + goto do_work; + } else { + while (*control != x) {} + } + +do_work: + print_addr(uart, x); + *control = x + 1; + + if (x == X - 1) + asm("ebreak"); + + /* otherwise just loop */ + while (1) {} +} |
