#include #include #include 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; }