Add csrtool to view and change CSR registers

This commit is contained in:
Rodrigo Arias 2024-07-08 19:02:01 +02:00
parent bef5a6eac5
commit 5b34b3b97b
4 changed files with 61 additions and 0 deletions

View File

@ -885,3 +885,8 @@ Continues to hang just after those perl messages:
May be a long shot, but if we are experiencing the same page fault loop as in May be a long shot, but if we are experiencing the same page fault loop as in
cincoranch we may as well try. cincoranch we may as well try.
### QUESTION: Maybe we can try without out-of-order?
I made a small tool in C to view and change the CSR register that controls the
in-order/out-of-order. Maybe we can try with the "in-order" setting.

34
csrtool.c Normal file
View 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;
}

View File

@ -81,6 +81,12 @@
compressor = "gzip"; compressor = "gzip";
kernelModules = [ ]; kernelModules = [ ];
# Add the csrtool to the initrd so we can change the
# in-order/out-of-order.
extraUtilsCommands = ''
cp -a ${pkgs.csrtool}/bin/csrtool $out/bin
'';
# Write a counter to the DMA region, so we can check the kernel is not # Write a counter to the DMA region, so we can check the kernel is not
# dead. Monitor from the host with: # dead. Monitor from the host with:
# while [ 1 ]; do xxd -s $((0x1bfff0000 - 0x60000000)) \ # while [ 1 ]; do xxd -s $((0x1bfff0000 - 0x60000000)) \

View File

@ -37,6 +37,22 @@ final: prev:
''; '';
}; };
csrtool = prev.pkgsStatic.stdenv.mkDerivation {
name = "csrtool";
src = ./csrtool.c;
unpackPhase = ''
cp ${./csrtool.c} csrtool.c
'';
dontConfigure = true;
buildPhase = ''
$CC -static csrtool.c -o csrtool
'';
installPhase = ''
mkdir -p $out/bin
cp csrtool $out/bin/
'';
};
bitstreams = builtins.fetchGit { bitstreams = builtins.fetchGit {
url = "git@bscpm03.bsc.es:rarias/bitstreams.git"; url = "git@bscpm03.bsc.es:rarias/bitstreams.git";
rev = "ad901b0c21ffbdb310ff1dfb269f169f6ac6bde6"; rev = "ad901b0c21ffbdb310ff1dfb269f169f6ac6bde6";