From 17e776f8535439b257373e3aadbed271ef932204 Mon Sep 17 00:00:00 2001 From: bbracker Date: Fri, 5 Nov 2021 22:37:05 -0700 Subject: [PATCH] checkpoints now use binary ram files --- .../testvector-generation/Makefile | 13 +++++++ .../testvector-generation/fixBinMem | Bin 0 -> 8784 bytes .../testvector-generation/fixBinMem.c | 33 ++++++++++++++++++ .../{fix_mem.py => fixTxtMem.py} | 0 .../testvector-generation/genCheckpoint.gdb | 7 ++-- .../testvector-generation/genCheckpoint.sh | 23 ++++++++---- .../testvector-generation/genInitMem.sh | 4 +-- .../testvector-generation/genSettings.sh | 2 +- wally-pipelined/testbench/testbench-linux.sv | 9 +++-- 9 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 tests/linux-testgen/testvector-generation/Makefile create mode 100755 tests/linux-testgen/testvector-generation/fixBinMem create mode 100644 tests/linux-testgen/testvector-generation/fixBinMem.c rename tests/linux-testgen/testvector-generation/{fix_mem.py => fixTxtMem.py} (100%) diff --git a/tests/linux-testgen/testvector-generation/Makefile b/tests/linux-testgen/testvector-generation/Makefile new file mode 100644 index 00000000..8f9bff4b --- /dev/null +++ b/tests/linux-testgen/testvector-generation/Makefile @@ -0,0 +1,13 @@ +SHELL = /bin/sh + +CFLAG = -Wall -g +CC = clang + +all: fixBinMem + +fixBinMem: fixBinMem.c + ${CC} ${CFLAGS} fixBinMem.c -o fixBinMem + chmod +x fixBinMem + +clean: + -rm -f fixBinMem diff --git a/tests/linux-testgen/testvector-generation/fixBinMem b/tests/linux-testgen/testvector-generation/fixBinMem new file mode 100755 index 0000000000000000000000000000000000000000..563ed988d78611241ac015f656c16c9483981703 GIT binary patch literal 8784 zcmeHMZ){W76~DI09|AZI&=O!YuN|oZQ;ZWr6ev(TiNj0hK$bsr(-vNw_&IUs*p~g= zgci1-6oi%1@?jsCrb&~gNlcoiPMS1SRU;Wy1KWqDovNX&9~gqwp+n7D#yqXyopawk zdCxD7R%x2F4_xcLbI%U4AC#?Fe6GHBE|ZQV~TL7pM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b8{qTDsKPk>7 zJZ1s;>m28*1+R}+z#puDSHZwl**7oUW0A30F28*L+=lYS?(K$?T1rcY!|q|Ye|xU2 zM+tQH_9+U3i#v5BlG4nZ}Oi!@k_*f#ULQv{% z-o0l}aUlghbP*+(Oa_lD5VIza!);)2OjRIY9Xk#xCQboKtxz;F(He<$sbk#9jvil^ zU-2Jq2QPJ(DPN!%VoLir4*R+~+d#@x!Y>>Fg73cKmlfTb+}^{KLxCf$zJPM1qodc~ zr}X(+1AeT5UsDdJ(!2@!C8pPFzMNFlP*4k!q;a8Xky21fzulxuP^(12{U>yGDz1zM zW1*Q7GjFh*VQI^SHHe3 zENAZ2@i8qp1XN4vbd+*%ud5~#%njEJs@vDvSr11Z!HvYy?xA!9?%yLJ=0Om7 z(D4}9)2Wu!OT@XUfKi|Qk)BZ98)PgX8$<|FFdcH zDCyHV*(3BRKBM}r?SDn+w*tjP@!p`&r}z-{vCpjfuK|XBp?{d@+`TCDDel!vm(QOJ z6qxnteC`qsCrD9HmxX@MqEF}eNuf{vk{K)iLyJCrpU(^Zo~6K9w?Oriy&qfjDK5Ar zDx$cUgCS zi@vq~Yfz4V6;n6S`I7!$waODu^aIeXH0e`(Q;kL;k(|yMJmG(a0-QfoKgB`Pf6ym; ze}N3nUDBs`iT?kdN8^xaep9_P4=zBNxqgbPa@Z(HB(HM@PxvQLVAfxXzeEKxDGEw@ zL~|B>ItR-_-#Xq_{vqh2Eowjh;e;t5^r@X3gcsFIyaSv^|2+f +#include +#include +int main(int argc, char *argv[]) { + if (argc < 3){ + fprintf(stderr, "Expected 2 arguments: \n"); + exit(1); + } + char* rawGDBfilePath = argv[1]; + FILE* rawGDBfile; + if ((rawGDBfile = fopen(rawGDBfilePath,"rb"))==NULL) { + fprintf(stderr, "File not found: %s\n",rawGDBfilePath); + exit(1); + } + char* outFilePath = argv[2]; + FILE* outFile = fopen(outFilePath,"w"); + uint64_t qemuWord; + uint64_t verilogWord; + int bytesReturned=0; + do { + bytesReturned=fread(&qemuWord, 8, 1, rawGDBfile); + verilogWord = (((qemuWord>>0 )&0xff)<<56 | + ((qemuWord>>8 )&0xff)<<48 | + ((qemuWord>>16)&0xff)<<40 | + ((qemuWord>>24)&0xff)<<32 | + ((qemuWord>>32)&0xff)<<24 | + ((qemuWord>>40)&0xff)<<16 | + ((qemuWord>>48)&0xff)<<8 | + ((qemuWord>>56)&0xff)<<0); + fwrite(&verilogWord, 8, 1, outFile); + } while(bytesReturned!=0); + return 0; +} diff --git a/tests/linux-testgen/testvector-generation/fix_mem.py b/tests/linux-testgen/testvector-generation/fixTxtMem.py similarity index 100% rename from tests/linux-testgen/testvector-generation/fix_mem.py rename to tests/linux-testgen/testvector-generation/fixTxtMem.py diff --git a/tests/linux-testgen/testvector-generation/genCheckpoint.gdb b/tests/linux-testgen/testvector-generation/genCheckpoint.gdb index 92630698..a7744139 100755 --- a/tests/linux-testgen/testvector-generation/genCheckpoint.gdb +++ b/tests/linux-testgen/testvector-generation/genCheckpoint.gdb @@ -13,7 +13,7 @@ define genCheckpoint set $checkPC=$arg3 set $checkPCoccurences=$arg4 eval "set $statePath = \"%s/stateGDB.txt\"", $statePath - eval "set $ramPath = \"%s/ramGDB.txt\"", $ramPath + eval "set $ramPath = \"%s/ramGDB.bin\"", $ramPath # Connect to QEMU session eval "target extended-remote :%d",$tcpPort @@ -46,10 +46,7 @@ define genCheckpoint # Log main memory to a file printf "GDB storing RAM to %s\n", $ramPath - eval "set logging file %s", $ramPath - set logging on - x/134217728xb 0x80000000 - set logging off + eval "dump binary memory %s 0x80000000 0xffffffff", $ramPath kill q diff --git a/tests/linux-testgen/testvector-generation/genCheckpoint.sh b/tests/linux-testgen/testvector-generation/genCheckpoint.sh index cca7486e..ca4bcf49 100755 --- a/tests/linux-testgen/testvector-generation/genCheckpoint.sh +++ b/tests/linux-testgen/testvector-generation/genCheckpoint.sh @@ -3,7 +3,7 @@ source genSettings.sh tcpPort=1236 -instrs=450000000 +instrs=8500000 checkOutDir="$outDir/checkpoint$instrs" checkIntermedDir="$checkOutDir/intermediate-outputs" @@ -15,24 +15,35 @@ if [[ $REPLY =~ ^[Yy]$ ]] then mkdir -p $checkOutDir mkdir -p $checkIntermedDir + + # Identify instruction in trace instr=$(sed "${instrs}q;d" "../linux-testvectors/all.txt") - echo "Found ${instrs}th instr: ${instr}." + echo "Found ${instrs}th instr: ${instr}" pc=$(echo $instr | cut -d " " -f1) asm=$(echo $instr | cut -d " " -f2) occurences=$(($(head -$instrs "../linux-testvectors/all.txt" | grep -c "${pc} ${asm}")-1)) echo "It occurs ${occurences} times before the ${instrs}th instr." - # Simulate QEMU, parse QEMU trace, run GDB script which logs a bunch of data at the checkpoint + + # GDB+QEMU + echo "Starting QEMU with attached GDB script at $(date +%H:%M:%S)" ($customQemu \ -M virt \ -nographic \ -bios $imageDir/fw_jump.elf -kernel $imageDir/Image -append "root=/dev/vda ro" -initrd $imageDir/rootfs.cpio \ -singlestep -rtc clock=vm -icount shift=1,align=off,sleep=on,rr=replay,rrfile="$intermedDir/$recordFile" \ -gdb tcp::$tcpPort -S) \ - & riscv64-unknown-elf-gdb -x genCheckpoint.gdb -ex "genCheckpoint $tcpPort $instrs \"$checkIntermedDir\" \"$pc\" $occurences" + & riscv64-unknown-elf-gdb --quiet \ + -x genCheckpoint.gdb -ex "genCheckpoint $tcpPort $instrs \"$checkIntermedDir\" \"$pc\" $occurences" + echo "Completed GDB script completed at $(date +%H:%M:%S)" + # Post-Process GDB outputs ./parseState.py "$checkOutDir" - ./fix_mem.py "$checkIntermedDir/ramGDB.txt" "$checkOutDir/ram.txt" - tail -n+$(($instrs+1)) "$outDir/$traceFile" > "$checkOutDir/$traceFile" + echo "Changing Endianness at $(date +%H:%M:%S)" + make + ./fixBinMem "$checkIntermedDir/ramGDB.bin" "$checkOutDir/ram.bin" + echo "Creating truncated trace at $(date +%H:%M:%S)" + tail -n+$instrs "$outDir/$traceFile" > "$checkOutDir/$traceFile" + echo "Checkpoint completed at $(date +%H:%M:%S)" else echo "You can change the number of instructions by editing the \"instrs\" variable in this script." echo "Have a nice day!" diff --git a/tests/linux-testgen/testvector-generation/genInitMem.sh b/tests/linux-testgen/testvector-generation/genInitMem.sh index 56b30a45..f82556f5 100755 --- a/tests/linux-testgen/testvector-generation/genInitMem.sh +++ b/tests/linux-testgen/testvector-generation/genInitMem.sh @@ -16,8 +16,8 @@ then & riscv64-unknown-elf-gdb -quiet -x genInitMem.gdb -ex "genInitMem $tcpPort \"$intermedDir\"" echo "Translating Mem from GDB to Questa format" - ./fix_mem.py "$intermedDir/bootmemGDB.txt" "$outDir/bootmem.txt" - ./fix_mem.py "$intermedDir/ramGDB.txt" "$outDir/ram.txt" + ./fixTxtMem.py "$intermedDir/bootmemGDB.txt" "$outDir/bootmem.txt" + ./fixTxtMem.py "$intermedDir/ramGDB.txt" "$outDir/ram.txt" echo "Done" echo "Creating debugging objdump of linux image" diff --git a/tests/linux-testgen/testvector-generation/genSettings.sh b/tests/linux-testgen/testvector-generation/genSettings.sh index 57bd7765..59490e35 100755 --- a/tests/linux-testgen/testvector-generation/genSettings.sh +++ b/tests/linux-testgen/testvector-generation/genSettings.sh @@ -4,7 +4,7 @@ # *** on the long term we'll want to include QEMU in the addins folder export customQemu="/courses/e190ax/qemu_sim/rv64_initrd/qemu_experimental/qemu/build/qemu-system-riscv64" export imageDir="../buildroot-image-output" -export outDir="../linux-testvectors-experimental" +export outDir="../linux-testvectors" export intermedDir="$outDir/intermediate-outputs" export traceFile="all.txt" export recordFile="all.qemu" diff --git a/wally-pipelined/testbench/testbench-linux.sv b/wally-pipelined/testbench/testbench-linux.sv index 72adf589..68bf64ad 100644 --- a/wally-pipelined/testbench/testbench-linux.sv +++ b/wally-pipelined/testbench/testbench-linux.sv @@ -280,7 +280,9 @@ module testbench(); `INIT_CHECKPOINT_VAL(SATP, [`XLEN-1:0]); `MAKE_CHECKPOINT_INIT_SIGNAL(MSTATUS, [`XLEN-1:0],0,0); - assign initPriv = (initPC[0][`XLEN-1]) ? 2'h2 : 2'h3; // *** a hacky way to detect initial privilege level + integer ramFile; + integer readResult; + assign initPriv = (initPC[0][`XLEN-1]) ? 2'h1 : 2'h3; // *** a hacky way to detect initial privilege level initial begin force dut.hart.priv.SwIntM = 0; force dut.hart.priv.TimerIntM = 0; @@ -297,7 +299,10 @@ module testbench(); end else begin // checkpoint $sformat(checkpointDir,"checkpoint%0d/",CHECKPOINT); checkpointDir = {`LINUX_TEST_VECTORS,checkpointDir}; - $readmemh({checkpointDir,"ram.txt"}, dut.uncore.dtim.RAM); + //$readmemh({checkpointDir,"ram.txt"}, dut.uncore.dtim.RAM); + ramFile = $fopen({checkpointDir,"ram.bin"}, "rb"); + readResult = $fread(dut.uncore.dtim.RAM,ramFile); + $fclose(ramFile); data_file_all = $fopen({checkpointDir,"all.txt"}, "r"); InstrCountW = CHECKPOINT; // manual checkpoint initializations that don't neatly fit into MACRO