diff options
author | Palmer Dabbelt <palmer@dabbelt.com> | 2017-06-14 08:59:41 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-14 08:59:41 -0700 |
commit | 61d6152830d752cd81c34368ecc24a5a2a107061 (patch) | |
tree | 58c5b8c05ae24b8c6b035545634200eb3742c064 /software/smp/smp.c | |
parent | 809711e87af06ca5c151a2fac568382330f2feb6 (diff) | |
parent | 99a8e6a697a340a5f44db82e68ab8ab9be604131 (diff) |
Merge pull request #64 from sifive/multicore-scratchpad
Add support for multicore systems and scratchpad-only systems
Diffstat (limited to 'software/smp/smp.c')
-rw-r--r-- | software/smp/smp.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/software/smp/smp.c b/software/smp/smp.c new file mode 100644 index 0000000..36c9db9 --- /dev/null +++ b/software/smp/smp.c @@ -0,0 +1,40 @@ +#include <stdio.h> +#include <unistd.h> +#include "atomic.h" +void write_hex(int, unsigned long); + +atomic_t tty_lock = ATOMIC_INIT(0); + +void get_lock(atomic_t *lock) +{ + while (atomic_xchg(lock, 1) == 1); + mb(); +} + +void put_lock(atomic_t *lock) +{ + mb(); + atomic_xchg(lock, 0); +} + +int secondary_main(int hartid) +{ + volatile int counter; + + while (1) { + get_lock(&tty_lock); + write(1, "hello world from hart ", 22); + char s[] = {'0', '\n', '\0'}; + s[0] += hartid; + write(1, s, 2); + put_lock(&tty_lock); + + for (counter = 0; counter < 10000 + 100*hartid; ++counter) + mb(); + } +} + +int main() +{ + return secondary_main(0); +} |