diff --git a/tests/Makefile b/tests/Makefile index 8756350d66..5bea4da401 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -7,7 +7,7 @@ include libgloss.mk PROGRAMS = pwm blkdev accum charcount nic-loopback big-blkdev pingd \ streaming-passthrough streaming-fir nvdla spiflashread spiflashwrite fft gcd \ - hello + hello mt-hello spiflash.img: spiflash.py python3 $< diff --git a/tests/encoding.h b/tests/encoding.h new file mode 120000 index 0000000000..f398b1630c --- /dev/null +++ b/tests/encoding.h @@ -0,0 +1 @@ +../toolchains/riscv-tools/riscv-tests/env/encoding.h \ No newline at end of file diff --git a/tests/hello.c b/tests/hello.c index 28d667e083..dbfbfe5693 100644 --- a/tests/hello.c +++ b/tests/hello.c @@ -1,6 +1,10 @@ #include +#include "encoding.h" +#include "marchid.h" int main(void) { - printf("Hello world\n"); + uint64_t marchid = read_csr(marchid); + const char* march = get_march(marchid); + printf("Hello world from core 0, a %s\n", march); return 0; } diff --git a/tests/marchid.h b/tests/marchid.h new file mode 100644 index 0000000000..5dfb2a3cc2 --- /dev/null +++ b/tests/marchid.h @@ -0,0 +1,17 @@ +#ifndef MARCHID_H +#define MARCHID_H + +const char* get_march(size_t marchid) { + switch (marchid) { + case 1: + return "rocket"; + case 2: + return "sonicboom"; + case 5: + return "spike"; + default: + return "unknown"; + } +} + +#endif diff --git a/tests/mt-hello.c b/tests/mt-hello.c new file mode 100644 index 0000000000..5ab47a562f --- /dev/null +++ b/tests/mt-hello.c @@ -0,0 +1,48 @@ +#include "encoding.h" +#include +#include "marchid.h" + +// EDIT THIS +static size_t n_cores = 4; + +static void __attribute__((noinline)) barrier() +{ + static volatile int sense; + static volatile int count; + static __thread int threadsense; + + __sync_synchronize(); + + threadsense = !threadsense; + if (__sync_fetch_and_add(&count, 1) == n_cores-1) + { + count = 0; + sense = threadsense; + } + else while(sense != threadsense) + ; + + __sync_synchronize(); +} + +void __main(void) { + size_t mhartid = read_csr(mhartid); + + if (mhartid >= n_cores) while (1); + + const char* march = get_march(read_csr(marchid)); + for (size_t i = 0; i < n_cores; i++) { + if (mhartid == i) { + printf("Hello world from core %lu, a %s\n", mhartid, march); + } + barrier(); + } + + // Spin if not core 0 + if (mhartid > 0) while (1); +} + +int main(void) { + __main(); + return 0; +}