Add mt-helloworld example
This commit is contained in:
@@ -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 $<
|
||||
|
||||
1
tests/encoding.h
Symbolic link
1
tests/encoding.h
Symbolic link
@@ -0,0 +1 @@
|
||||
../toolchains/riscv-tools/riscv-tests/env/encoding.h
|
||||
@@ -1,6 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
17
tests/marchid.h
Normal file
17
tests/marchid.h
Normal file
@@ -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
|
||||
48
tests/mt-hello.c
Normal file
48
tests/mt-hello.c
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "encoding.h"
|
||||
#include <stdio.h>
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user