From 70ddc98d1915752b4942ce2c1398a15474277faf Mon Sep 17 00:00:00 2001 From: bbracker Date: Sun, 6 Mar 2022 12:48:53 -0800 Subject: [PATCH 01/27] Revert "fix "dirname: missing operand" bug from setup.sh" This reverts commit 60cbd1c9c13cedbdbf635b41a7745f98d726a01d. --- setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index de048ed60..925d87e83 100755 --- a/setup.sh +++ b/setup.sh @@ -7,7 +7,7 @@ echo "Executing Wally setup.sh" # Path to Wally repository -WALLY=$(dirname $0) +WALLY=$(dirname ${BASH_SOURCE}) export WALLY=$(cd "$WALLY" && pwd) echo \$WALLY set to ${WALLY} From b1120069a091a67493147362eeed06ff52720f81 Mon Sep 17 00:00:00 2001 From: bbracker Date: Sun, 6 Mar 2022 13:12:20 -0800 Subject: [PATCH 02/27] generate $WALLY in a way that works for bash and zsh --- setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index 925d87e83..0d990d9da 100755 --- a/setup.sh +++ b/setup.sh @@ -7,7 +7,7 @@ echo "Executing Wally setup.sh" # Path to Wally repository -WALLY=$(dirname ${BASH_SOURCE}) +WALLY=$(dirname ${BASH_SOURCE[0]:-$0}) export WALLY=$(cd "$WALLY" && pwd) echo \$WALLY set to ${WALLY} From efee8d3a22fd42f3c5458e23f795fe9141bc3d3f Mon Sep 17 00:00:00 2001 From: bbracker Date: Sun, 6 Mar 2022 13:18:53 -0800 Subject: [PATCH 03/27] change from clang to gcc when compiling testvector-generation executables --- linux/testvector-generation/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/testvector-generation/Makefile b/linux/testvector-generation/Makefile index 8f3441e5a..54f95f20e 100644 --- a/linux/testvector-generation/Makefile +++ b/linux/testvector-generation/Makefile @@ -1,7 +1,7 @@ SHELL = /bin/sh CFLAG = -Wall -g -CC = clang +CC = gcc all: fixBinMem silencePipe From e3f735cc1a3a5c4d22aea831c7ff602a52c286ec Mon Sep 17 00:00:00 2001 From: bbracker Date: Sun, 6 Mar 2022 13:30:19 -0800 Subject: [PATCH 04/27] recommend sudo commands without automatically executing them in genInitMem.sh --- linux/testvector-generation/genInitMem.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/linux/testvector-generation/genInitMem.sh b/linux/testvector-generation/genInitMem.sh index 3e0aef83a..d1e28fa33 100755 --- a/linux/testvector-generation/genInitMem.sh +++ b/linux/testvector-generation/genInitMem.sh @@ -22,13 +22,15 @@ if [[ $REPLY =~ ^[Yy]$ ]] then if [ ! -d "$tvDir" ]; then echo "Error: linux testvector directory $tvDir not found!">&2 - echo "Please create it.">&2 + echo "Please create it. For example:">&2 + echo " sudo mkdir -p $tvDir">&2 exit 1 fi test -w $RISCV/linux-testvectors if [ ! $? -eq 0 ]; then echo "Error: insuffcient write privileges for linux testvector directory $tvDir !">&2 - echo "Please chmod it.">&2 + echo "Please chmod it. For example:">&2 + echo " sudo chmod a+rw $tvDir">&2 exit 1 fi @@ -62,5 +64,8 @@ then ./fixBinMem "$rawUntrimmedBootmemFile" "$untrimmedBootmemFile" echo "genInitMem.sh completed!" - echo "You may consider restricting write access to $tvDir now." + echo "You may want to restrict write access to $tvDir now and give cad ownership of it." + echo "Run the following:" + echo " sudo chown -R cad:cad $tvDir" + echo " sudo chmod -R go-w $tvDir" fi From bb90644fb2e7e3757cf12813844d1dcb9c756705 Mon Sep 17 00:00:00 2001 From: bbracker Date: Sun, 6 Mar 2022 13:55:19 -0800 Subject: [PATCH 05/27] add path to Modelsim on vlsi --- setup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.sh b/setup.sh index 0d990d9da..c5ba9ebf3 100755 --- a/setup.sh +++ b/setup.sh @@ -27,6 +27,7 @@ export PATH=$WALLY/bin:$PATH export PATH=/usr/local/bin/verilator:$PATH # Change this for your path to Verilator # ModelSim/Questa (vsim) export PATH=/cad/mentor/questa_sim-2021.2_1/questasim/bin:$PATH # Change this for your path to Modelsim +export PATH=/cad/mentor/questa_sim-2022.1_1/questasim/bin:$PATH # Change this for your path to Modelsim export MGLS_LICENSE_FILE=1717@solidworks.eng.hmc.edu # Change this to your Siemens license server export PATH=/cad/synopsys/SYN/bin:$PATH # Change this for your path to Design Compiler export SNPSLMD_LICENSE_FILE=27020@134.173.38.214 From 742b9d884d4f7e16733f3cc9b4bac07ccf68f6d3 Mon Sep 17 00:00:00 2001 From: bbracker Date: Sun, 6 Mar 2022 14:04:30 -0800 Subject: [PATCH 06/27] remove checkpoint trace generation since that requires qemu hacking and because we are able to generate the whole trace on VLSI --- ...n-on-logging-mid-execution-using-GDB.patch | 53 ------------------- .../createGenCheckpointScript.py | 21 ++------ linux/testvector-generation/genCheckpoint.sh | 23 +++----- 3 files changed, 10 insertions(+), 87 deletions(-) delete mode 100644 linux/testvector-generation/0001-bens-hack-to-turn-on-logging-mid-execution-using-GDB.patch diff --git a/linux/testvector-generation/0001-bens-hack-to-turn-on-logging-mid-execution-using-GDB.patch b/linux/testvector-generation/0001-bens-hack-to-turn-on-logging-mid-execution-using-GDB.patch deleted file mode 100644 index 1b0e1d4aa..000000000 --- a/linux/testvector-generation/0001-bens-hack-to-turn-on-logging-mid-execution-using-GDB.patch +++ /dev/null @@ -1,53 +0,0 @@ -From f9882bd274bde82d8c38a9c31692b6ee33d8cd9a Mon Sep 17 00:00:00 2001 -From: root -Date: Mon, 28 Feb 2022 22:48:29 +0000 -Subject: [PATCH] bens hack to turn on logging mid-execution using GDB - ---- - gdbstub.c | 23 +++++++++++++++++++++++ - 1 file changed, 23 insertions(+) - -diff --git a/gdbstub.c b/gdbstub.c -index 141d7bc4ec..98ecce1b67 100644 ---- a/gdbstub.c -+++ b/gdbstub.c -@@ -2317,6 +2317,23 @@ static void handle_set_qemu_phy_mem_mode(GArray *params, void *user_ctx) - } - put_packet("OK"); - } -+ -+static void handle_set_qemu_logging(GArray *params, void *user_ctx) -+{ -+ if (!params->len) { -+ put_packet("E22"); -+ return; -+ } -+ -+ int log_mask; -+ if (!get_param(params, 0)->val_ul) { -+ log_mask = 0; -+ } else { -+ log_mask = CPU_LOG_TB_IN_ASM | CPU_LOG_INT | CPU_LOG_TB_CPU | CPU_LOG_TB_NOCHAIN; -+ } -+ qemu_set_log(log_mask); -+ put_packet("OK"); -+} - #endif - - static const GdbCmdParseEntry gdb_gen_query_set_common_table[] = { -@@ -2430,6 +2447,12 @@ static const GdbCmdParseEntry gdb_gen_set_table[] = { - .cmd_startswith = 1, - .schema = "l0" - }, -+ { -+ .handler = handle_set_qemu_logging, -+ .cmd = "qemu.Logging:", -+ .cmd_startswith = 1, -+ .schema = "l0" -+ }, - #endif - }; - --- -2.27.0 - diff --git a/linux/testvector-generation/createGenCheckpointScript.py b/linux/testvector-generation/createGenCheckpointScript.py index 02d1bcc76..264a2ee6e 100755 --- a/linux/testvector-generation/createGenCheckpointScript.py +++ b/linux/testvector-generation/createGenCheckpointScript.py @@ -1,7 +1,7 @@ #! /usr/bin/python3 import sys -if len(sys.argv) != 9: +if len(sys.argv) != 8: sys.exit("""Error createGenCheckpointScript.py expects 7 args: @@ -9,8 +9,7 @@ if len(sys.argv) != 9: - - """) + """) tcpPort=sys.argv[1] vmlinux=sys.argv[2] @@ -19,7 +18,6 @@ statePath=sys.argv[4] ramPath=sys.argv[5] checkPC=sys.argv[6] checkPCoccurences=sys.argv[7] -genTrace=sys.argv[8] GDBscript = f""" # GDB config @@ -56,20 +54,7 @@ set logging off # Log main memory to a file print "GDB storing RAM to {ramPath}\\n" dump binary memory {ramPath} 0x80000000 0xffffffff -""" -if (genTrace=="1"): - GDBscript+=\ -""" -# Generate Trace Until End -maintenance packet Qqemu.Logging:1 -# Do this by setting an impossible breakpoint -b *0x1000 -del 1 -c -""" -else: - GDBscript+=\ -""" + kill q """ diff --git a/linux/testvector-generation/genCheckpoint.sh b/linux/testvector-generation/genCheckpoint.sh index 834ef6bb6..87e295414 100755 --- a/linux/testvector-generation/genCheckpoint.sh +++ b/linux/testvector-generation/genCheckpoint.sh @@ -6,12 +6,11 @@ recordFile="$tvDir/all.qemu" traceFile="$tvDir/all.txt" # Parse Commandline Arg -if [ "$#" -ne 2 ]; then - echo "genCheckpoint requires 2 arguments: " >&2 +if [ "$#" -ne 1 ]; then + echo "genCheckpoint requires 1 argument: " >&2 exit 1 fi instrs=$1 -genTrace=$2 if ! [ "$instrs" -eq "$instrs" ] 2> /dev/null then echo "Error expected integer number of instructions, got $instrs" >&2 @@ -25,14 +24,8 @@ rawStateFile="$checkPtDir/stateGDB.txt" rawRamFile="$checkPtDir/ramGDB.bin" ramFile="$checkPtDir/ram.bin" -if [ $genTrace -eq "1" ]; then - read -p "This scripts is going to create a checkpoint at $instrs instrs. - AND it's going to start generating a trace at that checkpoint. - Is that what you wanted? (y/n) " -n 1 -r -else - read -p "This scripts is going to create a checkpoint at $instrs instrs. - Is that what you wanted? (y/n) " -n 1 -r -fi +read -p "This scripts is going to create a checkpoint at $instrs instrs. +Is that what you wanted? (y/n) " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]] then @@ -63,7 +56,7 @@ then echo "It occurs ${occurences} times before the ${instrs}th instr." # Create GDB script because GDB is terrible at handling arguments / variables - ./createGenCheckpointScript.py $tcpPort $imageDir/vmlinux $instrs $rawStateFile $rawRamFile $pc $occurences $genTrace + ./createGenCheckpointScript.py $tcpPort $imageDir/vmlinux $instrs $rawStateFile $rawRamFile $pc $occurences # GDB+QEMU echo "Starting QEMU in replay mode with attached GDB script at $(date +%H:%M:%S)" (qemu-system-riscv64 \ @@ -81,10 +74,8 @@ then echo "Changing Endianness at $(date +%H:%M:%S)" make fixBinMem ./fixBinMem "$rawRamFile" "$ramFile" - if [ $genTrace -ne "1" ]; then - echo "Copying over a truncated trace" - tail -n+$instrs $traceFile > $outTraceFile - fi + echo "Copying over a truncated trace" + tail -n+$instrs $traceFile > $outTraceFile read -p "Checkpoint completed at $(date +%H:%M:%S)" -n 1 -r # Cleanup From 91f327e1099df93fcac6a97eb922802d7e1deefc Mon Sep 17 00:00:00 2001 From: bbracker Date: Sun, 6 Mar 2022 14:16:23 -0800 Subject: [PATCH 07/27] small bugfix to suggested sudo commands for linux testvectors --- linux/testvector-generation/genInitMem.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/testvector-generation/genInitMem.sh b/linux/testvector-generation/genInitMem.sh index d1e28fa33..7917d725e 100755 --- a/linux/testvector-generation/genInitMem.sh +++ b/linux/testvector-generation/genInitMem.sh @@ -30,7 +30,7 @@ then if [ ! $? -eq 0 ]; then echo "Error: insuffcient write privileges for linux testvector directory $tvDir !">&2 echo "Please chmod it. For example:">&2 - echo " sudo chmod a+rw $tvDir">&2 + echo " sudo chmod -R a+rw $tvDir">&2 exit 1 fi From e57b5208dc5342fbafec8a12ef7206a93c2bbcfe Mon Sep 17 00:00:00 2001 From: bbracker Date: Sun, 6 Mar 2022 14:24:50 -0800 Subject: [PATCH 08/27] replace sudo's in genTrace.sh with suggested commands --- linux/testvector-generation/genTrace.sh | 38 ++++++++++++++----------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/linux/testvector-generation/genTrace.sh b/linux/testvector-generation/genTrace.sh index 6c3548be5..4c31ce6b6 100755 --- a/linux/testvector-generation/genTrace.sh +++ b/linux/testvector-generation/genTrace.sh @@ -13,32 +13,36 @@ Would you like to proceed? (y/n) " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]] then - # Create Output Directory - echo "Elevating permissions to create $traceFile, $interruptsFile" - sudo mkdir -p $tvDir - sudo chown cad $tvDir - sudo touch $traceFile - sudo touch $interruptsFile - sudo chmod a+rw $traceFile - sudo chmod a+rw $interruptsFile + if [ ! -d "$tvDir" ]; then + echo "Error: linux testvector directory $tvDir not found!">&2 + echo "Please create it. For example:">&2 + echo " sudo mkdir -p $tvDir">&2 + exit 1 + fi + test -w $RISCV/linux-testvectors + if [ ! $? -eq 0 ]; then + echo "Error: insuffcient write privileges for linux testvector directory $tvDir !">&2 + echo "Please chmod it. For example:">&2 + echo " sudo chmod -R a+rw $tvDir">&2 + exit 1 + fi - # Compile Devicetree from Source - dtc -I dts -O dtb ../devicetree/wally-virt.dts > ../devicetree/wally-virt.dtb + touch $traceFile + touch $interruptsFile # QEMU Simulation echo "Launching QEMU in replay mode!" (qemu-system-riscv64 \ - -M virt -dtb ../devicetree/wally-virt.dtb \ + -M virt -dtb $imageDir/wally-virt.dtb \ -nographic \ -bios $imageDir/fw_jump.elf -kernel $imageDir/Image -append "root=/dev/vda ro" -initrd $imageDir/rootfs.cpio \ -singlestep -rtc clock=vm -icount shift=0,align=off,sleep=on,rr=replay,rrfile=$recordFile \ -d nochain,cpu,in_asm,int \ 2>&1 >/dev/null | ./parseQEMUtoGDB.py | ./parseGDBtoTrace.py $interruptsFile | ./remove_dup.awk > $traceFile) - # Cleanup - echo "Elevating permissions to restrict write access to $traceFile, $interruptsFile" - sudo chown cad $traceFile - sudo chown cad $interruptsFile - sudo chmod o-w $traceFile - sudo chmod o-w $interruptsFile + echo "genTrace.sh completed!" + echo "You may want to restrict write access to $tvDir now and give cad ownership of it." + echo "Run the following:" + echo " sudo chown -R cad:cad $tvDir" + echo " sudo chmod -R go-w $tvDir" fi From 8f2e67984f547c657d1dd1c4f5c4a68c81338091 Mon Sep 17 00:00:00 2001 From: bbracker Date: Sun, 6 Mar 2022 14:31:55 -0800 Subject: [PATCH 09/27] replace sudo's with suggestions in genRecording.sh --- linux/testvector-generation/genRecording.sh | 36 ++++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/linux/testvector-generation/genRecording.sh b/linux/testvector-generation/genRecording.sh index d7319413a..f9538e145 100755 --- a/linux/testvector-generation/genRecording.sh +++ b/linux/testvector-generation/genRecording.sh @@ -8,26 +8,30 @@ Would you like to proceed? (y/n) " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]] then - # Create Output Directory - echo "Elevating permissions to create $recordFile" - sudo mkdir -p $tvDir - sudo chown cad $tvDir - sudo touch $recordFile - sudo chmod a+rw $recordFile + if [ ! -d "$tvDir" ]; then + echo "Error: linux testvector directory $tvDir not found!">&2 + echo "Please create it. For example:">&2 + echo " sudo mkdir -p $tvDir">&2 + exit 1 + fi + test -w $tvDir + if [ ! $? -eq 0 ]; then + echo "Error: insuffcient write privileges for linux testvector directory $tvDir !">&2 + echo "Please chmod it. For example:">&2 + echo " sudo chmod -R a+rw $tvDir">&2 + exit 1 + fi - # Compile Devicetree from Source - dtc -I dts -O dtb ../devicetree/wally-virt.dts > ../devicetree/wally-virt.dtb - - # QEMU Simulation - echo "Launching QEMU!" + echo "Launching QEMU in record mode!" qemu-system-riscv64 \ - -M virt -dtb ../devicetree/wally-virt.dtb \ + -M virt -dtb $imageDir/wally-virt.dtb \ -nographic \ -bios $imageDir/fw_jump.elf -kernel $imageDir/Image -append "root=/dev/vda ro" -initrd $imageDir/rootfs.cpio \ -singlestep -rtc clock=vm -icount shift=0,align=off,sleep=on,rr=record,rrfile=$recordFile - # Cleanup - echo "Elevating permissions to restrict write access to $recordFile" - sudo chown cad $recordFile - sudo chmod o-w $recordFile + echo "genRecording.sh completed!" + echo "You may want to restrict write access to $tvDir now and give cad ownership of it." + echo "Run the following:" + echo " sudo chown -R cad:cad $tvDir" + echo " sudo chmod -R go-w $tvDir" fi From 7182ec228fd24e47cbdaf2a34a6f5a73740a6fe6 Mon Sep 17 00:00:00 2001 From: bbracker Date: Sun, 6 Mar 2022 14:33:53 -0800 Subject: [PATCH 10/27] better to use $tvDir variable rather than abs path --- linux/testvector-generation/genInitMem.sh | 2 +- linux/testvector-generation/genTrace.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/linux/testvector-generation/genInitMem.sh b/linux/testvector-generation/genInitMem.sh index 7917d725e..27a3f004a 100755 --- a/linux/testvector-generation/genInitMem.sh +++ b/linux/testvector-generation/genInitMem.sh @@ -26,7 +26,7 @@ then echo " sudo mkdir -p $tvDir">&2 exit 1 fi - test -w $RISCV/linux-testvectors + test -w $tvDir if [ ! $? -eq 0 ]; then echo "Error: insuffcient write privileges for linux testvector directory $tvDir !">&2 echo "Please chmod it. For example:">&2 diff --git a/linux/testvector-generation/genTrace.sh b/linux/testvector-generation/genTrace.sh index 4c31ce6b6..91485e383 100755 --- a/linux/testvector-generation/genTrace.sh +++ b/linux/testvector-generation/genTrace.sh @@ -19,7 +19,7 @@ then echo " sudo mkdir -p $tvDir">&2 exit 1 fi - test -w $RISCV/linux-testvectors + test -w $tvDir if [ ! $? -eq 0 ]; then echo "Error: insuffcient write privileges for linux testvector directory $tvDir !">&2 echo "Please chmod it. For example:">&2 From f64b7776ede67d1dc8be142596daf28600ba59f7 Mon Sep 17 00:00:00 2001 From: bbracker Date: Sun, 6 Mar 2022 14:37:12 -0800 Subject: [PATCH 11/27] give genCheckpoint the same de-sudo'ing treatement --- linux/testvector-generation/genCheckpoint.sh | 39 +++++++++----------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/linux/testvector-generation/genCheckpoint.sh b/linux/testvector-generation/genCheckpoint.sh index 87e295414..748dab934 100755 --- a/linux/testvector-generation/genCheckpoint.sh +++ b/linux/testvector-generation/genCheckpoint.sh @@ -30,23 +30,20 @@ echo if [[ $REPLY =~ ^[Yy]$ ]] then echo "Creating checkpoint at $instrs instructions!" + if [ ! -d "$tvDir" ]; then + echo "Error: linux testvector directory $tvDir not found!">&2 + echo "Please create it. For example:">&2 + echo " sudo mkdir -p $tvDir">&2 + exit 1 + fi + test -w $tvDir + if [ ! $? -eq 0 ]; then + echo "Error: insuffcient write privileges for linux testvector directory $tvDir !">&2 + echo "Please chmod it. For example:">&2 + echo " sudo chmod -R a+rw $tvDir">&2 + exit 1 + fi - # Create Output Directory - echo "Elevating permissions to create $checkPtDir and stuff inside it" - sudo mkdir -p $checkPtDir - sudo chown -R cad:users $checkPtDir - sudo chmod -R a+rw $checkPtDir - sudo touch $outTraceFile - sudo chmod a+rw $outTraceFile - sudo touch $interruptsFile - sudo chmod a+rw $interruptsFile - sudo touch $rawStateFile - sudo chmod a+rw $rawStateFile - sudo touch $rawRamFile - sudo chmod a+rw $rawRamFile - sudo touch $ramFile - sudo chmod a+rw $ramFile - # Identify instruction in trace instr=$(sed "${instrs}q;d" "$traceFile") echo "Found ${instrs}th instr: ${instr}" @@ -76,11 +73,11 @@ then ./fixBinMem "$rawRamFile" "$ramFile" echo "Copying over a truncated trace" tail -n+$instrs $traceFile > $outTraceFile - read -p "Checkpoint completed at $(date +%H:%M:%S)" -n 1 -r - # Cleanup - echo "Elevating permissions to restrict write access to $checkPtDir" - sudo chown -R cad:users $checkPtDir - sudo chmod -R go-w $checkPtDir + echo "Checkpoint completed at $(date +%H:%M:%S)" + echo "You may want to restrict write access to $tvDir now and give cad ownership of it." + echo "Run the following:" + echo " sudo chown -R cad:cad $tvDir" + echo " sudo chmod -R go-w $tvDir" fi From d007208aa9c255c1868199a83a4777db3a5dfb8a Mon Sep 17 00:00:00 2001 From: bbracker Date: Sun, 6 Mar 2022 14:40:26 -0800 Subject: [PATCH 12/27] no longer use cythonization on python parser scripts because its a little complicated and has marginal benefit --- linux/testvector-generation/genCheckpoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/testvector-generation/genCheckpoint.sh b/linux/testvector-generation/genCheckpoint.sh index 748dab934..c845bc33c 100755 --- a/linux/testvector-generation/genCheckpoint.sh +++ b/linux/testvector-generation/genCheckpoint.sh @@ -62,7 +62,7 @@ then -bios $imageDir/fw_jump.elf -kernel $imageDir/Image -append "root=/dev/vda ro" -initrd $imageDir/rootfs.cpio \ -singlestep -rtc clock=vm -icount shift=0,align=off,sleep=on,rr=replay,rrfile=$recordFile \ -gdb tcp::$tcpPort -S \ - 2>&1 1>./qemu-serial | ./parseQEMUtoGDB/parseQEMUtoGDB_run.py | ./parseGDBtoTrace/parseGDBtoTrace_run.py $interruptsFile | ./remove_dup.awk > $outTraceFile) \ + 2>&1 1>./qemu-serial | ./parseQEMUtoGDB.py | ./parseGDBtoTrace.py $interruptsFile | ./remove_dup.awk > $outTraceFile) \ & riscv64-unknown-elf-gdb --quiet -ex "source genCheckpoint.gdb" echo "Completed GDB script at $(date +%H:%M:%S)" From 11e9bbf3e4ffe975452d54140be0693b153d8158 Mon Sep 17 00:00:00 2001 From: bbracker Date: Sun, 6 Mar 2022 14:51:25 -0800 Subject: [PATCH 13/27] needed to initialize checkpoint directory --- linux/testvector-generation/genCheckpoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/linux/testvector-generation/genCheckpoint.sh b/linux/testvector-generation/genCheckpoint.sh index c845bc33c..792925b7e 100755 --- a/linux/testvector-generation/genCheckpoint.sh +++ b/linux/testvector-generation/genCheckpoint.sh @@ -44,6 +44,8 @@ then exit 1 fi + mkdir -p $checkPtDir + # Identify instruction in trace instr=$(sed "${instrs}q;d" "$traceFile") echo "Found ${instrs}th instr: ${instr}" From bea2faeda6b933c834189888b61a97933d9daa2e Mon Sep 17 00:00:00 2001 From: bbracker Date: Sun, 6 Mar 2022 14:54:35 -0800 Subject: [PATCH 14/27] remove vestigial silencePipe mechanism --- linux/testvector-generation/Makefile | 6 +----- linux/testvector-generation/silencePipe.c | 21 --------------------- 2 files changed, 1 insertion(+), 26 deletions(-) delete mode 100644 linux/testvector-generation/silencePipe.c diff --git a/linux/testvector-generation/Makefile b/linux/testvector-generation/Makefile index 54f95f20e..c31aae39d 100644 --- a/linux/testvector-generation/Makefile +++ b/linux/testvector-generation/Makefile @@ -3,15 +3,11 @@ SHELL = /bin/sh CFLAG = -Wall -g CC = gcc -all: fixBinMem silencePipe +all: fixBinMem fixBinMem: fixBinMem.c ${CC} ${CFLAGS} fixBinMem.c -o fixBinMem chmod +x fixBinMem -silencePipe: silencePipe.c - ${CC} ${CFLAGS} silencePipe.c -o silencePipe - chmod +x silencePipe clean: -rm -f fixBinMem - -rm -f silencePipe diff --git a/linux/testvector-generation/silencePipe.c b/linux/testvector-generation/silencePipe.c deleted file mode 100644 index 3ffeb14b4..000000000 --- a/linux/testvector-generation/silencePipe.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include - -int main(void) -{ - char *line = NULL; - size_t len = 0; - while (1) { - FILE* controlFile = fopen("silencePipe.control", "r"); - char silenceChar = getc(controlFile); - fclose(controlFile); - ssize_t lineSize = getline(&line, &len, stdin); - if (silenceChar!='1') { - printf("%s",line); - } else { - fprintf(stderr,"%s",line); - } - } - free(line); - return 0; -} From 483aad2a059786c8c3cb981c22e9a445985e73eb Mon Sep 17 00:00:00 2001 From: bbracker Date: Sun, 6 Mar 2022 14:55:51 -0800 Subject: [PATCH 15/27] update checkpointSweep in accordance to having removed trace parsing feature --- linux/testvector-generation/checkpointSweep.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/testvector-generation/checkpointSweep.sh b/linux/testvector-generation/checkpointSweep.sh index 74ed9ecf5..c1543677c 100755 --- a/linux/testvector-generation/checkpointSweep.sh +++ b/linux/testvector-generation/checkpointSweep.sh @@ -1,5 +1,5 @@ for index in {450..500} do instrs=$(($index*1000000)) - echo "y" | nice -n 5 ./genCheckpoint.sh $instrs 0 + echo "y" | nice -n 5 ./genCheckpoint.sh $instrs done From a68c1c8cb195d3042a2b52fb218c8deb24b6bc98 Mon Sep 17 00:00:00 2001 From: Shreya Sanghai Date: Thu, 3 Mar 2022 00:22:14 +0000 Subject: [PATCH 16/27] modified makefile --- synthDC/Makefile | 8 ++++++-- synthDC/extractSummary.py | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) mode change 100644 => 100755 synthDC/extractSummary.py diff --git a/synthDC/Makefile b/synthDC/Makefile index b359046eb..9f380584b 100755 --- a/synthDC/Makefile +++ b/synthDC/Makefile @@ -1,6 +1,6 @@ # # Makefile for synthesis -# +# Shreya Sanghai (ssanghai@hmc.edu) 2/28/2022 NAME := synth # defaults @@ -26,6 +26,7 @@ CONFIGFILES ?= $(shell find $(CONFIGDIR) -name rv*_*) CONFIGFILESTRIM = $(notdir $(CONFIGFILES)) print: echo $(CONFIGFILESTRIM) + echo $(DIRS) default: @echo "Basic synthesis procedure for Wally:" @@ -38,10 +39,13 @@ rv%.log: rv% echo $< -DIRS = rv32e rv32gc rv64ic rv64gc rv32ic +DIRS = rv64gc #rv32e rv32gc rv64ic rv64gc rv32ic # DELDIRS = rv32e rv32gc rv64ic rv64gc rv32ic # CONFIGSUBDIRS = _FPUoff _noMulDiv _noVirtMem _PMP0 _PMP16 _orig +copy: + @$(foreach dir, $(DIRS), rm -rf $(CONFIGDIR)/$(dir)_orig;) + @$(foreach dir, $(DIRS), cp -r $(CONFIGDIR)/$(dir) $(CONFIGDIR)/$(dir)_orig;) del: @$(foreach dir, $(DIRS), rm -rf $(CONFIGDIR)/$(dir)_orig;) diff --git a/synthDC/extractSummary.py b/synthDC/extractSummary.py old mode 100644 new mode 100755 index e9fa69772..8462a2456 --- a/synthDC/extractSummary.py +++ b/synthDC/extractSummary.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3 +# Shreya Sanghai (ssanghai@hmc.edu) 2/28/2022 import glob import re import csv From bc049e804226c0cfe457a4317fe45994748028f1 Mon Sep 17 00:00:00 2001 From: Shreya Sanghai Date: Mon, 7 Mar 2022 00:08:47 +0000 Subject: [PATCH 17/27] updated makefile to speed up synth --- synthDC/Makefile | 20 ++++++-------------- synthDC/extractSummary.py | 6 ++++-- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/synthDC/Makefile b/synthDC/Makefile index 9f380584b..9bbb41c49 100755 --- a/synthDC/Makefile +++ b/synthDC/Makefile @@ -39,13 +39,16 @@ rv%.log: rv% echo $< -DIRS = rv64gc #rv32e rv32gc rv64ic rv64gc rv32ic +DIRS = rv32e rv32gc rv64ic rv64gc rv32ic # DELDIRS = rv32e rv32gc rv64ic rv64gc rv32ic # CONFIGSUBDIRS = _FPUoff _noMulDiv _noVirtMem _PMP0 _PMP16 _orig copy: @$(foreach dir, $(DIRS), rm -rf $(CONFIGDIR)/$(dir)_orig;) @$(foreach dir, $(DIRS), cp -r $(CONFIGDIR)/$(dir) $(CONFIGDIR)/$(dir)_orig;) + @$(foreach dir, $(DIRS), sed -i 's/WAYSIZEINBYTES.*/WAYSIZEINBYTES 512/g' $(CONFIGDIR)/$(dir)_orig/wally-config.vh;) + @$(foreach dir, $(DIRS), sed -i 's/NUMWAYS.*/NUMWAYS 1/g' $(CONFIGDIR)/$(dir)_orig/wally-config.vh;) + @$(foreach dir, $(DIRS), sed -i "s/RAM_RANGE.*/RAM_RANGE 34\'h01FF/g" $(CONFIGDIR)/$(dir)_orig/wally-config.vh ;) del: @$(foreach dir, $(DIRS), rm -rf $(CONFIGDIR)/$(dir)_orig;) @@ -59,39 +62,28 @@ configs: $(DIRS) $(DIRS): #turn off FPU rm -rf $(CONFIGDIR)/$@_FPUoff - cp -r $(CONFIGDIR)/$@ $(CONFIGDIR)/$@_FPUoff + cp -r $(CONFIGDIR)/$@_orig $(CONFIGDIR)/$@_FPUoff sed -i 's/1 *<< *3/0 << 3/' $(CONFIGDIR)/$@_FPUoff/wally-config.vh sed -i 's/1 *<< *5/0 << 5/' $(CONFIGDIR)/$@_FPUoff/wally-config.vh # PMP 16 rm -rf $(CONFIGDIR)/$@_PMP16 cp -r $(CONFIGDIR)/$@_FPUoff $(CONFIGDIR)/$@_PMP16 - # sed -i 's/1 *<< *3/0 << 3/' $(CONFIGDIR)/$@_PMP16/wally-config.vh - # sed -i 's/1 *<< *5/0 << 5/' $(CONFIGDIR)/$@_PMP16/wally-config.vh sed -i 's/PMP_ENTRIES \(64\|16\|0\)/PMP_ENTRIES 16/' $(CONFIGDIR)/$@_PMP16/wally-config.vh # PMP 0 rm -rf $(CONFIGDIR)/$@_PMP0 cp -r $(CONFIGDIR)/$@_FPUoff $(CONFIGDIR)/$@_PMP0 - # sed -i 's/1 *<< *3/0 << 3/' $(CONFIGDIR)/$@_PMP0/wally-config.vh - # sed -i 's/1 *<< *5/0 << 5/' $(CONFIGDIR)/$@_PMP0/wally-config.vh sed -i 's/PMP_ENTRIES \(64\|16\|0\)/PMP_ENTRIES 0/' $(CONFIGDIR)/$@_PMP0/wally-config.vh # No Virtual Memory rm -rf $(CONFIGDIR)/$@_noVirtMem - # cp -r $(CONFIGDIR)/$@ $(CONFIGDIR)/$@_noVirtMem - # sed -i 's/1 *<< *3/0 <_PMP0< 3/' $(CONFIGDIR)/$@_noVirtMem/wally-config.vh - # sed -i 's/1 *<< *5/0 << 5/' $(CONFIGDIR)/$@_noVirtMem/wally-config.vh - # sed -i 's/PMP_ENTRIES \(64\|16\|0\)/PMP_ENTRIES 0/' $(CONFIGDIR)/$@_noVirtMem/wally-config.vh + cp -r $(CONFIGDIR)/$@_PMP0 $(CONFIGDIR)/$@_noVirtMem sed -i 's/VIRTMEM_SUPPORTED 1/VIRTMEM_SUPPORTED 0/' $(CONFIGDIR)/$@_noVirtMem/wally-config.vh #no muldiv rm -rf $(CONFIGDIR)/$@_noMulDiv cp -r $(CONFIGDIR)/$@_noVirtMem $(CONFIGDIR)/$@_noMulDiv - # sed -i 's/1 *<< *3/0 << 3/' $(CONFIGDIR)/$@_noMulDiv/wally-config.vh - # sed -i 's/1 *<< *5/0 << 5/' $(CONFIGDIR)/$@_noMulDiv/wally-config.vh - # sed -i 's/PMP_ENTRIES \(64\|16\|0\)/PMP_ENTRIES 0/' $(CONFIGDIR)/$@_noMulDiv/wally-config.vh - # sed -i 's/VIRTMEM_SUPPORTED 1/VIRTMEM_SUPPORTED 0/' $(CONFIGDIR)/$@_noMulDiv/wally-config.vh sed -i 's/1 *<< *12/0 << 12/' $(CONFIGDIR)/$@_noMulDiv/wally-config.vh diff --git a/synthDC/extractSummary.py b/synthDC/extractSummary.py index 8462a2456..85ab99ec6 100755 --- a/synthDC/extractSummary.py +++ b/synthDC/extractSummary.py @@ -4,7 +4,7 @@ import glob import re import csv -field_names = [ 'Name', 'Critical Path Length', 'Cell Area'] +field_names = [ 'Name', 'Critical Path Length', 'Cell Area', 'Synth Time'] data = [] for name in glob.glob("/home/ssanghai/riscv-wally/synthDC/runs/*/reports/wallypipelinedcore_qor.rep"): f = open(name, 'r') @@ -15,7 +15,9 @@ for name in glob.glob("/home/ssanghai/riscv-wally/synthDC/runs/*/reports/wallypi pathLen = re.search("Length: *(.*?)\\n", line).group(1) if "Cell Area" in line: area = re.search("Area: *(.*?)\\n", line).group(1) - data += [{'Name' : trimName, 'Critical Path Length': pathLen, 'Cell Area' : area}] + if "Overall Compile Time" in line: + time = re.search("Time: *(.*?)\\n", line).group(1) + data += [{'Name' : trimName, 'Critical Path Length': pathLen, 'Cell Area' : area, 'Synth Time' :time}] with open('Summary.csv', 'w') as csvfile: writer = csv.DictWriter(csvfile, fieldnames=field_names) From 94a57fb6eb65be08b199e825d8e526eefacac3c3 Mon Sep 17 00:00:00 2001 From: Shreya Sanghai Date: Mon, 7 Mar 2022 17:12:43 +0000 Subject: [PATCH 18/27] modified synth script to take config from outputdir --- synthDC/Makefile | 2 +- synthDC/scripts/synth.tcl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/synthDC/Makefile b/synthDC/Makefile index 9bbb41c49..b6d066d2e 100755 --- a/synthDC/Makefile +++ b/synthDC/Makefile @@ -39,7 +39,7 @@ rv%.log: rv% echo $< -DIRS = rv32e rv32gc rv64ic rv64gc rv32ic +DIRS = rv32e #rv32gc rv64ic rv64gc rv32ic # DELDIRS = rv32e rv32gc rv64ic rv64gc rv32ic # CONFIGSUBDIRS = _FPUoff _noMulDiv _noVirtMem _PMP0 _PMP16 _orig diff --git a/synthDC/scripts/synth.tcl b/synthDC/scripts/synth.tcl index 3146e14ed..04366ed6c 100755 --- a/synthDC/scripts/synth.tcl +++ b/synthDC/scripts/synth.tcl @@ -22,7 +22,7 @@ set cfg "${hdl_src}/../config/${cfgName}/wally-config.vh" set saifpower $::env(SAIFPOWER) set maxopt $::env(MAXOPT) -eval file copy -force ${cfg} {hdl/} +# eval file copy -force ${cfg} {hdl/} eval file copy -force ${cfg} $outputDir eval file copy -force [glob ${hdl_src}/../config/shared/*.vh] {hdl/} eval file copy -force [glob ${hdl_src}/*/*.sv] {hdl/} @@ -34,7 +34,7 @@ if { $saifpower == 1 } { } # Verilog files -set my_verilog_files [glob hdl/*] +set my_verilog_files [glob hdl/* outputDir/wally-config.vh] # Set toplevel set my_toplevel $::env(DESIGN) From a218a3d9fac8093d05e74e9093ca861d709e5b39 Mon Sep 17 00:00:00 2001 From: Shreya Sanghai Date: Mon, 7 Mar 2022 17:32:08 +0000 Subject: [PATCH 19/27] undid changes to synth script --- synthDC/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/synthDC/Makefile b/synthDC/Makefile index b6d066d2e..b1452f0e2 100755 --- a/synthDC/Makefile +++ b/synthDC/Makefile @@ -90,8 +90,9 @@ $(DIRS): allsynth: $(CONFIGFILESTRIM) $(CONFIGFILESTRIM): - make synth DESIGN=wallypipelinedcore CONFIG=$@ TECH=sky90 FREQ=500 MAXCORES=1 --jobs + make synth DESIGN=wallypipelinedcore CONFIG=$@ TECH=sky90 FREQ=500 MAXCORES=1 + synth: @echo "DC Synthesis" @mkdir -p hdl/ From c15517d334c247e45a84fbe8a79beacc7b8501c8 Mon Sep 17 00:00:00 2001 From: Shreya Sanghai Date: Mon, 7 Mar 2022 17:36:05 +0000 Subject: [PATCH 20/27] removed reminant changes --- synthDC/scripts/synth.tcl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synthDC/scripts/synth.tcl b/synthDC/scripts/synth.tcl index 04366ed6c..3146e14ed 100755 --- a/synthDC/scripts/synth.tcl +++ b/synthDC/scripts/synth.tcl @@ -22,7 +22,7 @@ set cfg "${hdl_src}/../config/${cfgName}/wally-config.vh" set saifpower $::env(SAIFPOWER) set maxopt $::env(MAXOPT) -# eval file copy -force ${cfg} {hdl/} +eval file copy -force ${cfg} {hdl/} eval file copy -force ${cfg} $outputDir eval file copy -force [glob ${hdl_src}/../config/shared/*.vh] {hdl/} eval file copy -force [glob ${hdl_src}/*/*.sv] {hdl/} @@ -34,7 +34,7 @@ if { $saifpower == 1 } { } # Verilog files -set my_verilog_files [glob hdl/* outputDir/wally-config.vh] +set my_verilog_files [glob hdl/*] # Set toplevel set my_toplevel $::env(DESIGN) From 4bf95714eb0b0b2694035f7e0a69a2bbbd798d63 Mon Sep 17 00:00:00 2001 From: bbracker Date: Mon, 7 Mar 2022 19:52:19 +0000 Subject: [PATCH 21/27] add debug.sh --- linux/testvector-generation/debug.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 linux/testvector-generation/debug.sh diff --git a/linux/testvector-generation/debug.sh b/linux/testvector-generation/debug.sh new file mode 100755 index 000000000..c667429cf --- /dev/null +++ b/linux/testvector-generation/debug.sh @@ -0,0 +1,14 @@ +#!/bin/bash +imageDir=$RISCV/buildroot/output/images +tvDir=$RISCV/linux-testvectors +tcpPort=1239 + +# QEMU Simulation +(qemu-system-riscv64 \ +-M virt -dtb $imageDir/wally-virt.dtb \ +-nographic \ +-bios $imageDir/fw_jump.elf -kernel $imageDir/Image -append "root=/dev/vda ro" -initrd $imageDir/rootfs.cpio \ +-singlestep -rtc clock=vm -icount shift=0,align=off,sleep=on \ +> ./qemu-serial) # \ +#-gdb tcp::$tcpPort -S \ +#& riscv64-unknown-elf-gdb -quiet -x debug.gdb -ex "debug $tcpPort \"$imageDir/vmlinux\"" From 409dd4870672cdc5fffe4810c5922a2307f16cea Mon Sep 17 00:00:00 2001 From: bbracker Date: Mon, 7 Mar 2022 11:56:04 -0800 Subject: [PATCH 22/27] modify debug.sh to not rely on external GDB script --- linux/testvector-generation/debug.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/linux/testvector-generation/debug.sh b/linux/testvector-generation/debug.sh index c667429cf..748f6e023 100755 --- a/linux/testvector-generation/debug.sh +++ b/linux/testvector-generation/debug.sh @@ -9,6 +9,13 @@ tcpPort=1239 -nographic \ -bios $imageDir/fw_jump.elf -kernel $imageDir/Image -append "root=/dev/vda ro" -initrd $imageDir/rootfs.cpio \ -singlestep -rtc clock=vm -icount shift=0,align=off,sleep=on \ -> ./qemu-serial) # \ -#-gdb tcp::$tcpPort -S \ -#& riscv64-unknown-elf-gdb -quiet -x debug.gdb -ex "debug $tcpPort \"$imageDir/vmlinux\"" +> ./qemu-serial \ +-gdb tcp::$tcpPort -S) \ +& riscv64-unknown-elf-gdb -quiet \ +-ex "set pagination off" \ +-ex "set logging overwrite on" \ +-ex "set logging redirect on" \ +-ex "set confirm off" \ +-ex "target extended-remote :$tcpPort" \ +-ex "maintenance packet Qqemu.PhyMemMode:1" \ +-ex "file $imageDir/vmlinux" From 097301635a15f4a93fe29830dbe9fca7235600f1 Mon Sep 17 00:00:00 2001 From: bbracker Date: Mon, 7 Mar 2022 17:59:49 -0800 Subject: [PATCH 23/27] change checkpoint generation to integrate GDB scripting more cleanly and save UART and PLIC state --- .../createGenCheckpointScript.py | 63 -------------- linux/testvector-generation/genCheckpoint.sh | 55 +++++++++++- linux/testvector-generation/parsePlicState.py | 87 +++++++++++++++++++ linux/testvector-generation/parseState.py | 4 +- linux/testvector-generation/parseUartState.py | 53 +++++++++++ 5 files changed, 193 insertions(+), 69 deletions(-) delete mode 100755 linux/testvector-generation/createGenCheckpointScript.py create mode 100755 linux/testvector-generation/parsePlicState.py create mode 100755 linux/testvector-generation/parseUartState.py diff --git a/linux/testvector-generation/createGenCheckpointScript.py b/linux/testvector-generation/createGenCheckpointScript.py deleted file mode 100755 index 264a2ee6e..000000000 --- a/linux/testvector-generation/createGenCheckpointScript.py +++ /dev/null @@ -1,63 +0,0 @@ -#! /usr/bin/python3 -import sys - -if len(sys.argv) != 8: - sys.exit("""Error createGenCheckpointScript.py expects 7 args: - - - - - - - """) - -tcpPort=sys.argv[1] -vmlinux=sys.argv[2] -instrCount=sys.argv[3] -statePath=sys.argv[4] -ramPath=sys.argv[5] -checkPC=sys.argv[6] -checkPCoccurences=sys.argv[7] - -GDBscript = f""" -# GDB config -set pagination off -set logging overwrite on -set logging redirect on -set confirm off - -# Connect to QEMU session -target extended-remote :{tcpPort} - -# QEMU Config -maintenance packet Qqemu.PhyMemMode:1 - -# Symbol file -file {vmlinux} - -# Step over reset vector into actual code -stepi 100 -# Proceed to checkpoint -print "GDB proceeding to checkpoint at {instrCount} instrs, pc {checkPC}\\n" -b *0x{checkPC} -ignore 1 {checkPCoccurences} -c -print "Reached checkpoint at {instrCount} instrs\\n" - -# Log all registers to a file -printf "GDB storing state to {statePath}\\n" -set logging file {statePath} -set logging on -info all-registers -set logging off - -# Log main memory to a file -print "GDB storing RAM to {ramPath}\\n" -dump binary memory {ramPath} 0x80000000 0xffffffff - -kill -q -""" -GDBscriptFile = open("genCheckpoint.gdb",'w') -GDBscriptFile.write(GDBscript) -GDBscriptFile.close() diff --git a/linux/testvector-generation/genCheckpoint.sh b/linux/testvector-generation/genCheckpoint.sh index 792925b7e..1ca309be7 100755 --- a/linux/testvector-generation/genCheckpoint.sh +++ b/linux/testvector-generation/genCheckpoint.sh @@ -19,8 +19,11 @@ fi checkPtDir="$tvDir/checkpoint$instrs" outTraceFile="$checkPtDir/all.txt" -interruptsFile="$checkPtDir/interrupts.txt" rawStateFile="$checkPtDir/stateGDB.txt" +rawUartStateFile="$checkPtDir/uartStateGDB.txt" +uartStateFile="$checkPtDir/checkpoint-UART" +rawPlicStateFile="$checkPtDir/plicStateGDB.txt" +plicStateFile="$checkPtDir/checkpoint-PLIC" rawRamFile="$checkPtDir/ramGDB.bin" ramFile="$checkPtDir/ram.bin" @@ -55,7 +58,48 @@ then echo "It occurs ${occurences} times before the ${instrs}th instr." # Create GDB script because GDB is terrible at handling arguments / variables - ./createGenCheckpointScript.py $tcpPort $imageDir/vmlinux $instrs $rawStateFile $rawRamFile $pc $occurences + cat > genCheckpoint.gdb <<- end_of_script + set pagination off + set logging overwrite on + set logging redirect on + set confirm off + target extended-remote :$tcpPort + maintenance packet Qqemu.PhyMemMode:1 + file $imageDir/vmlinux + # Step over reset vector into actual code + stepi 100 + shell echo \"GDB proceeding to checkpoint at $instrs instrs, pc $pc\" + b *0x$pc + ignore 1 $occurences + c + shell echo \"Reached checkpoint at $instrs instrs\" + shell echo \"GDB storing CPU state to $rawStateFile\" + set logging file $rawStateFile + set logging on + info all-registers + set logging off + shell echo \"GDB storing UART state to $rawUartStateFile\" + set logging file $rawUartStateFile + set logging on + x/8xb 0x10000000 + set logging off + shell echo \"GDB storing PLIC state to $rawPlicStateFile\" + shell echo \"Note: this dumping assumes a maximum of 63 PLIC sources\" + set logging file $rawPlicStateFile + set logging on + # Priority Levels for sources 1 thru 63 + x/63xw 0x0C000004 + # Interrupt Enables + x/2xw 0x0C020000 + # Global Priority Threshold + x/1xw 0x0C200000 + set logging off + shell echo \"GDB storing RAM to $rawRamFile\" + dump binary memory $rawRamFile 0x80000000 0xffffffff + kill + q +end_of_script + # GDB+QEMU echo "Starting QEMU in replay mode with attached GDB script at $(date +%H:%M:%S)" (qemu-system-riscv64 \ @@ -64,12 +108,15 @@ then -bios $imageDir/fw_jump.elf -kernel $imageDir/Image -append "root=/dev/vda ro" -initrd $imageDir/rootfs.cpio \ -singlestep -rtc clock=vm -icount shift=0,align=off,sleep=on,rr=replay,rrfile=$recordFile \ -gdb tcp::$tcpPort -S \ - 2>&1 1>./qemu-serial | ./parseQEMUtoGDB.py | ./parseGDBtoTrace.py $interruptsFile | ./remove_dup.awk > $outTraceFile) \ - & riscv64-unknown-elf-gdb --quiet -ex "source genCheckpoint.gdb" + 1>./qemu-serial) \ + & riscv64-unknown-elf-gdb --quiet -x genCheckpoint.gdb + echo "Completed GDB script at $(date +%H:%M:%S)" # Post-Process GDB outputs ./parseState.py "$checkPtDir" + ./parseUartState.py "$rawUartStateFile" "$uartStateFile" + ./parsePlicState.py "$rawPlicStateFile" "$plicStateFile" echo "Changing Endianness at $(date +%H:%M:%S)" make fixBinMem ./fixBinMem "$rawRamFile" "$ramFile" diff --git a/linux/testvector-generation/parsePlicState.py b/linux/testvector-generation/parsePlicState.py new file mode 100755 index 000000000..8655409d1 --- /dev/null +++ b/linux/testvector-generation/parsePlicState.py @@ -0,0 +1,87 @@ +#! /usr/bin/python3 +import sys, os + +################ +# Helper Funcs # +################ + +def tokenize(string): + tokens = [] + token = '' + whitespace = 0 + prevWhitespace = 0 + for char in string: + prevWhitespace = whitespace + whitespace = char in ' \t\n' + if (whitespace): + if ((not prevWhitespace) and (token != '')): + tokens.append(token) + token = '' + else: + token = token + char + return tokens + +############# +# Main Code # +############# +print("Begin parsing PLIC state.") + +# Parse Args +if len(sys.argv) != 3: + sys.exit('Error parsePlicState.py expects 2 args: ') +rawPlicStateFile=sys.argv[1] +outPlicStateFile=sys.argv[2] +if not os.path.exists(rawPlicStateFile): + sys.exit('Error input file '+rawPlicStateFile+'not found') + +# Main Loop +with open(rawPlicStateFile, 'r') as rawPlicStateFile: + plicIntPriorityArray=[] + # 0x0C000004 thru 0x0C000010 + plicIntPriorityArray += tokenize(rawPlicStateFile.readline())[1:] + # 0x0C000014 thru 0x0C000020 + plicIntPriorityArray += tokenize(rawPlicStateFile.readline())[1:] + # 0x0C000024 thru 0x0C000030 + plicIntPriorityArray += tokenize(rawPlicStateFile.readline())[1:] + # 0x0C000034 thru 0x0C000040 + plicIntPriorityArray += tokenize(rawPlicStateFile.readline())[1:] + # 0x0C000044 thru 0x0C000050 + plicIntPriorityArray += tokenize(rawPlicStateFile.readline())[1:] + # 0x0C000054 thru 0x0C000060 + plicIntPriorityArray += tokenize(rawPlicStateFile.readline())[1:] + # 0x0C000064 thru 0x0C000070 + plicIntPriorityArray += tokenize(rawPlicStateFile.readline())[1:] + # 0x0C000074 thru 0x0C000080 + plicIntPriorityArray += tokenize(rawPlicStateFile.readline())[1:] + # 0x0C000084 thru 0x0C000090 + plicIntPriorityArray += tokenize(rawPlicStateFile.readline())[1:] + # 0x0C000094 thru 0x0C0000a0 + plicIntPriorityArray += tokenize(rawPlicStateFile.readline())[1:] + # 0x0C0000a4 thru 0x0C0000b0 + plicIntPriorityArray += tokenize(rawPlicStateFile.readline())[1:] + # 0x0C0000b4 thru 0x0C0000c0 + plicIntPriorityArray += tokenize(rawPlicStateFile.readline())[1:] + # 0x0C0000c4 thru 0x0C0000d0 + plicIntPriorityArray += tokenize(rawPlicStateFile.readline())[1:] + # 0x0C0000d4 thru 0x0C0000e0 + plicIntPriorityArray += tokenize(rawPlicStateFile.readline())[1:] + # 0x0C0000e4 thru 0x0C0000f0 + plicIntPriorityArray += tokenize(rawPlicStateFile.readline())[1:] + # 0x0C0000f4 thru 0x0C0000fc + plicIntPriorityArray += tokenize(rawPlicStateFile.readline())[1:] + + # 0x0C020000 thru 0x0C020004 + plicIntEnable = tokenize(rawPlicStateFile.readline())[1:] + + # 0x0C200000 + plicIntPriorityThreshold = tokenize(rawPlicStateFile.readline())[1:] + +with open(outPlicStateFile, 'w') as outPlicStateFile: + for word in plicIntPriorityArray: + outPlicStateFile.write(word[2:]+'\n') + for word in plicIntEnable: + outPlicStateFile.write(word[2:]+'\n') + for word in plicIntPriorityThreshold: + outPlicStateFile.write(word[2:]+'\n') + +print("Finished parsing PLIC state!") diff --git a/linux/testvector-generation/parseState.py b/linux/testvector-generation/parseState.py index 5275597c4..abc36fb2f 100755 --- a/linux/testvector-generation/parseState.py +++ b/linux/testvector-generation/parseState.py @@ -24,7 +24,7 @@ def tokenize(string): ############# # Main Code # ############# -print("Begin parsing state.") +print("Begin parsing CPU state.") # Parse Args if len(sys.argv) != 2: @@ -96,4 +96,4 @@ with open(stateGDBpath, 'r') as stateGDB: outFile.write(hex(byte)[2:]+'\n') outFile.close() -print("Finished parsing state!") +print("Finished parsing CPU state!") diff --git a/linux/testvector-generation/parseUartState.py b/linux/testvector-generation/parseUartState.py new file mode 100755 index 000000000..0b7d1cf7f --- /dev/null +++ b/linux/testvector-generation/parseUartState.py @@ -0,0 +1,53 @@ +#! /usr/bin/python3 +import sys, os + +################ +# Helper Funcs # +################ + +def tokenize(string): + tokens = [] + token = '' + whitespace = 0 + prevWhitespace = 0 + for char in string: + prevWhitespace = whitespace + whitespace = char in ' \t\n' + if (whitespace): + if ((not prevWhitespace) and (token != '')): + tokens.append(token) + token = '' + else: + token = token + char + return tokens + +############# +# Main Code # +############# +print("Begin parsing UART state.") + +# Parse Args +if len(sys.argv) != 3: + sys.exit('Error parseUartState.py expects 2 args: ') +rawUartStateFile=sys.argv[1] +outUartStateFile=sys.argv[2] +if not os.path.exists(rawUartStateFile): + sys.exit('Error input file '+rawUartStateFile+'not found') + +# Main Loop +with open(rawUartStateFile, 'r') as rawUartStateFile: + with open(outUartStateFile, 'w') as outUartStateFile: + uartBytes = tokenize(rawUartStateFile.readline())[1:] + # Stores + # 0: RBR / Divisor Latch Low + # 1: IER / Divisor Latch High + # 2: IIR + # 3: LCR + # 4: MCR + # 5: LSR + # 6: MSR + # 7: SCR + for uartByte in uartBytes: + outUartStateFile.write(uartByte[2:]+'\n') + +print("Finished parsing UART state!") From 92e1583db51be37d4cfe3c2360cf81efb5085bdf Mon Sep 17 00:00:00 2001 From: bbracker Date: Mon, 7 Mar 2022 20:04:08 -0800 Subject: [PATCH 24/27] change testbench-linux.sv to use new shared location of disassembly files --- pipelined/testbench/testbench-linux.sv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pipelined/testbench/testbench-linux.sv b/pipelined/testbench/testbench-linux.sv index 0c58f7b72..d9ab6ecde 100644 --- a/pipelined/testbench/testbench-linux.sv +++ b/pipelined/testbench/testbench-linux.sv @@ -314,8 +314,8 @@ module testbench; $sformat(checkpointDir,"%s/linux-testvectors/checkpoint%0d/",RISCV_DIR,CHECKPOINT); $readmemb(`TWO_BIT_PRELOAD, dut.core.ifu.bpred.bpred.Predictor.DirPredictor.PHT.mem); $readmemb(`BTB_PRELOAD, dut.core.ifu.bpred.bpred.TargetPredictor.memory.mem); - ProgramAddrMapFile = {linuxImageDir,"vmlinux.objdump.addr"}; - ProgramLabelMapFile = {linuxImageDir,"vmlinux.objdump.lab"}; + ProgramAddrMapFile = {linuxImageDir,"disassembly/vmlinux.objdump.addr"}; + ProgramLabelMapFile = {linuxImageDir,"disassembly/vmlinux.objdump.lab"}; // initialize bootrom memFile = $fopen({testvectorDir,"bootmem.bin"}, "rb"); readResult = $fread(dut.uncore.bootrom.bootrom.RAM,memFile); From bfaf49647387dea783e8215cf04cd3267647e6b5 Mon Sep 17 00:00:00 2001 From: bbracker Date: Mon, 7 Mar 2022 22:12:08 -0800 Subject: [PATCH 25/27] change UART state saving to temporarily modify LCR so that DLAB=0 when reading addresses 0 and 1 so that we get RBR and IER instead of divisor latch registers --- linux/testvector-generation/genCheckpoint.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/linux/testvector-generation/genCheckpoint.sh b/linux/testvector-generation/genCheckpoint.sh index 1ca309be7..8f4d0a111 100755 --- a/linux/testvector-generation/genCheckpoint.sh +++ b/linux/testvector-generation/genCheckpoint.sh @@ -79,9 +79,21 @@ then info all-registers set logging off shell echo \"GDB storing UART state to $rawUartStateFile\" + # Save value of LCR + set \$LCR=*0x10000003 & 0xff set logging file $rawUartStateFile set logging on - x/8xb 0x10000000 + # Change LCR to set DLAB=0 to be able to read RBR and IER + set {char}0x10000003 &= ~0x80 + x/1xb 0x10000000 + x/1xb 0x10000001 + x/1xb 0x10000002 + # But log original value of LCR + printf "0x10000003:\t0x%02x\n", \$LCR + x/1xb 0x10000004 + x/1xb 0x10000005 + x/1xb 0x10000006 + x/1xb 0x10000007 set logging off shell echo \"GDB storing PLIC state to $rawPlicStateFile\" shell echo \"Note: this dumping assumes a maximum of 63 PLIC sources\" @@ -115,8 +127,8 @@ end_of_script # Post-Process GDB outputs ./parseState.py "$checkPtDir" - ./parseUartState.py "$rawUartStateFile" "$uartStateFile" - ./parsePlicState.py "$rawPlicStateFile" "$plicStateFile" + ./parseUartState.py "$checkPtDir" + ./parsePlicState.py "$checkPtDir" echo "Changing Endianness at $(date +%H:%M:%S)" make fixBinMem ./fixBinMem "$rawRamFile" "$ramFile" From 742e8d98cd995bd7d4ff4bf96274439053818555 Mon Sep 17 00:00:00 2001 From: bbracker Date: Mon, 7 Mar 2022 23:48:47 -0800 Subject: [PATCH 26/27] fix up PLIC and UART checkpointing --- linux/testvector-generation/parsePlicState.py | 26 ++++++++++----- linux/testvector-generation/parseUartState.py | 33 +++++++++---------- pipelined/testbench/testbench-linux.sv | 26 +++++++++++++++ 3 files changed, 58 insertions(+), 27 deletions(-) diff --git a/linux/testvector-generation/parsePlicState.py b/linux/testvector-generation/parsePlicState.py index 8655409d1..a3c3787c8 100755 --- a/linux/testvector-generation/parsePlicState.py +++ b/linux/testvector-generation/parsePlicState.py @@ -21,20 +21,26 @@ def tokenize(string): token = token + char return tokens +def stripZeroes(num): + num = num.strip('0') + if num=='': + return '0' + else: + return num + ############# # Main Code # ############# print("Begin parsing PLIC state.") # Parse Args -if len(sys.argv) != 3: - sys.exit('Error parsePlicState.py expects 2 args: ') -rawPlicStateFile=sys.argv[1] -outPlicStateFile=sys.argv[2] +if len(sys.argv) != 2: + sys.exit('Error parsePlicState.py expects 1 arg: ') +outDir = sys.argv[1]+'/' +rawPlicStateFile = outDir+'plicStateGDB.txt' if not os.path.exists(rawPlicStateFile): sys.exit('Error input file '+rawPlicStateFile+'not found') -# Main Loop with open(rawPlicStateFile, 'r') as rawPlicStateFile: plicIntPriorityArray=[] # 0x0C000004 thru 0x0C000010 @@ -76,12 +82,14 @@ with open(rawPlicStateFile, 'r') as rawPlicStateFile: # 0x0C200000 plicIntPriorityThreshold = tokenize(rawPlicStateFile.readline())[1:] -with open(outPlicStateFile, 'w') as outPlicStateFile: +with open(outDir+'checkpoint-PLIC_INT_PRIORITY', 'w') as outFile: for word in plicIntPriorityArray: - outPlicStateFile.write(word[2:]+'\n') + outFile.write(stripZeroes(word[2:])+'\n') +with open(outDir+'checkpoint-PLIC_INT_ENABLE', 'w') as outFile: for word in plicIntEnable: - outPlicStateFile.write(word[2:]+'\n') + outFile.write(stripZeroes(word[2:])) +with open(outDir+'checkpoint-PLIC_THRESHOLD', 'w') as outFile: for word in plicIntPriorityThreshold: - outPlicStateFile.write(word[2:]+'\n') + outFile.write(stripZeroes(word[2:])+'\n') print("Finished parsing PLIC state!") diff --git a/linux/testvector-generation/parseUartState.py b/linux/testvector-generation/parseUartState.py index 0b7d1cf7f..611937054 100755 --- a/linux/testvector-generation/parseUartState.py +++ b/linux/testvector-generation/parseUartState.py @@ -27,27 +27,24 @@ def tokenize(string): print("Begin parsing UART state.") # Parse Args -if len(sys.argv) != 3: - sys.exit('Error parseUartState.py expects 2 args: ') -rawUartStateFile=sys.argv[1] -outUartStateFile=sys.argv[2] +if len(sys.argv) != 2: + sys.exit('Error parseUartState.py expects 1 arg: ') +outDir = sys.argv[1]+'/' +rawUartStateFile = outDir+'uartStateGDB.txt' if not os.path.exists(rawUartStateFile): sys.exit('Error input file '+rawUartStateFile+'not found') -# Main Loop with open(rawUartStateFile, 'r') as rawUartStateFile: - with open(outUartStateFile, 'w') as outUartStateFile: - uartBytes = tokenize(rawUartStateFile.readline())[1:] - # Stores - # 0: RBR / Divisor Latch Low - # 1: IER / Divisor Latch High - # 2: IIR - # 3: LCR - # 4: MCR - # 5: LSR - # 6: MSR - # 7: SCR - for uartByte in uartBytes: - outUartStateFile.write(uartByte[2:]+'\n') + uartBytes = [] + for i in range(0,8): + uartBytes += tokenize(rawUartStateFile.readline())[1:] +with open(outDir+'checkpoint-UART_IER', 'w') as outFile: + outFile.write(uartBytes[1][2:]) +with open(outDir+'checkpoint-UART_LCR', 'w') as outFile: + outFile.write(uartBytes[3][2:]) +with open(outDir+'checkpoint-UART_MCR', 'w') as outFile: + outFile.write(uartBytes[4][2:]) +with open(outDir+'checkpoint-UART_SCR', 'w') as outFile: + outFile.write(uartBytes[7][2:]) print("Finished parsing UART state!") diff --git a/pipelined/testbench/testbench-linux.sv b/pipelined/testbench/testbench-linux.sv index d9ab6ecde..8723d6b9c 100644 --- a/pipelined/testbench/testbench-linux.sv +++ b/pipelined/testbench/testbench-linux.sv @@ -214,6 +214,15 @@ module testbench; `define STATUS_UIE `CSR_BASE.csrsr.STATUS_UIE `define PRIV dut.core.priv.priv.privmodereg.q `define INSTRET dut.core.priv.priv.csr.counters.counters.HPMCOUNTER_REGW[2] + `define UART dut.uncore.uart.uart.u + `define UART_IER `UART.IER + `define UART_LCR `UART.LCR + `define UART_MCR `UART.MCR + `define UART_SCR `UART.SCR + `define PLIC dut.uncore.plic.plic + `define PLIC_INT_PRIORITY `PLIC.intPriority + `define PLIC_INT_ENABLE `PLIC.intEn + `define PLIC_THRESHOLD `PLIC.intThreshold // Common Macros `define checkCSR(CSR) \ begin \ @@ -301,6 +310,23 @@ module testbench; `INIT_CHECKPOINT_VAL(SATP, [`XLEN-1:0]); `INIT_CHECKPOINT_VAL(PRIV, [1:0]); `MAKE_CHECKPOINT_INIT_SIGNAL(MSTATUS, [`XLEN-1:0],0,0); + // Many UART registers are difficult to initialize because under the hood + // they are not simple registers. Instead some are generated by interesting + // combinational blocks such that they depend upon a variety of different + // underlying flops. See for example how RBR might be the actual RXBR + // register, but it could also just as well be 0 or the tail of the fifo + // array. + //`INIT_CHECKPOINT_VAL(UART_RBR, [7:0]); + `INIT_CHECKPOINT_VAL(UART_IER, [7:0]); + //`INIT_CHECKPOINT_VAL(UART_IIR, [7:0]); + `INIT_CHECKPOINT_VAL(UART_LCR, [7:0]); + `INIT_CHECKPOINT_VAL(UART_MCR, [4:0]); + //`INIT_CHECKPOINT_VAL(UART_LSR, [7:0]); + //`INIT_CHECKPOINT_VAL(UART_MSR, [7:0]); + `INIT_CHECKPOINT_VAL(UART_SCR, [7:0]); + `INIT_CHECKPOINT_SIMPLE_ARRAY(PLIC_INT_PRIORITY, [2:0],`PLIC_NUM_SRC,1); + `INIT_CHECKPOINT_VAL(PLIC_INT_ENABLE, [`PLIC_NUM_SRC:1]); + `INIT_CHECKPOINT_VAL(PLIC_THRESHOLD, [2:0]); integer memFile; integer readResult; From 099fc34c106577d5ead9c7bfdef287ba0aa2baab Mon Sep 17 00:00:00 2001 From: bbracker Date: Tue, 8 Mar 2022 09:52:17 -0800 Subject: [PATCH 27/27] change genTrace to dump UART output to file so we can see how far parsing got --- linux/testvector-generation/genTrace.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/testvector-generation/genTrace.sh b/linux/testvector-generation/genTrace.sh index 91485e383..5c79ee3d0 100755 --- a/linux/testvector-generation/genTrace.sh +++ b/linux/testvector-generation/genTrace.sh @@ -38,7 +38,7 @@ then -bios $imageDir/fw_jump.elf -kernel $imageDir/Image -append "root=/dev/vda ro" -initrd $imageDir/rootfs.cpio \ -singlestep -rtc clock=vm -icount shift=0,align=off,sleep=on,rr=replay,rrfile=$recordFile \ -d nochain,cpu,in_asm,int \ - 2>&1 >/dev/null | ./parseQEMUtoGDB.py | ./parseGDBtoTrace.py $interruptsFile | ./remove_dup.awk > $traceFile) + 2>&1 >./qemu-serial | ./parseQEMUtoGDB.py | ./parseGDBtoTrace.py $interruptsFile | ./remove_dup.awk > $traceFile) echo "genTrace.sh completed!" echo "You may want to restrict write access to $tvDir now and give cad ownership of it."