forked from rarias/nixos-riscv
Move other tools to tools/
This commit is contained in:
34
tools/csrtool.c
Normal file
34
tools/csrtool.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
/* Print */
|
||||
if (argc > 1) {
|
||||
// Wait for all memory operations to finish
|
||||
__asm__ volatile ("fence");
|
||||
|
||||
if (strcmp(argv[1], "mem-in-order") == 0) {
|
||||
__asm__ volatile ("fence");
|
||||
__asm__ volatile ("csrwi 0x801, 2");
|
||||
} else if (strcmp(argv[1], "all-in-order") == 0) {
|
||||
__asm__ volatile ("fence");
|
||||
__asm__ volatile ("csrwi 0x801, 7");
|
||||
} else if (strcmp(argv[1], "all-out-of-order") == 0) {
|
||||
__asm__ volatile ("fence");
|
||||
__asm__ volatile ("csrwi 0x801, 0");
|
||||
} else {
|
||||
fprintf(stderr, "unknown '%s', use: mem-in-order, all-in-order or all-out-of-order\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for all memory operations to finish
|
||||
__asm__ volatile ("fence");
|
||||
unsigned result;
|
||||
asm("csrr %0, 0x801" : "=r"(result) : );
|
||||
printf("CSR 0x801 = %xu\n", result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user