diff --git a/Makefile b/Makefile index 29c1788..887cb7b 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC=riscv64-unknown-elf-gcc AS=riscv64-unknown-elf-as ASFLAGS=-g -mabi=ilp32e -march=rv32ec -CFLAGS=$(ASFLAGS) +CFLAGS=$(ASFLAGS) -Os -Wall -std=c99 LD=riscv64-unknown-elf-ld export JQ?=jaq export QEMU?=qemu-riscv32 @@ -57,7 +57,7 @@ tests/btohex.elf: mem.o hex.o debug.o tests/btohex.o tests/tohex.elf: hex.o tests/tohex.o $(LD) -m elf32lriscv -T link.ld $^ -o $@ -tests/harness.elf: tests/harness.o +tests/harness.elf: tests/harness.o tests/charness.o $(LD) -m elf32lriscv -T link.ld $^ -o $@ %.o : %.s diff --git a/calc.h b/calc.h new file mode 100644 index 0000000..eb78553 --- /dev/null +++ b/calc.h @@ -0,0 +1,11 @@ +#ifndef CALC_H +#define CALC_H + +typedef unsigned char bool; +#define true 1; +#define false 0; + +typedef unsigned char u8; +typedef unsigned int uint; + +#endif diff --git a/tests/charness.c b/tests/charness.c new file mode 100644 index 0000000..6dc0fea --- /dev/null +++ b/tests/charness.c @@ -0,0 +1,43 @@ +#include "../calc.h" + +#define BUF_SIZE 80 + +#define make_str(s) { sizeof(s), (const u8 *)s } +#define make_test(name) { make_str(#name), name } + +extern bool streq(const u8 *, uint, const u8 *, uint); +extern int read(u8 *, uint); // read from stdin + +// Tests +extern void count_digits(void); +extern void fmt_decimal(void); + +typedef struct { + u8 len; + const u8 *data; +} str; + +typedef void (*testfn)(void); + +typedef struct { + str name; + testfn fn; +} test; + +static str tests[2] = {make_test(count_digits), make_test(fmt_decimal)}; + +void _start(void) { + u8 buf[BUF_SIZE]; + int nread0 = read(buf, BUF_SIZE); + if (nread0 < 0) { + for(;;); // TODO: add abort function + } + uint nread = (uint)nread0; + + for(uint i = 0; i < sizeof(tests); i++) { + const str s = tests[i]; + if (streq(buf, nread, s.data, s.len)) { + + } + } +} diff --git a/tests/harness.s b/tests/harness.s index 37b709e..2c2f84e 100644 --- a/tests/harness.s +++ b/tests/harness.s @@ -3,7 +3,8 @@ .org 0 # Provide program starting address to linker -.global _start +.global read +.global streq # .extern fmt_decimal @@ -25,7 +26,7 @@ inbuf: .skip 80 .text -_start: +_start2: la a0, inbuf li a1, 80 jal read