I finally think I got the function radix debugger working across both 32 and 64 bit applications.

This commit is contained in:
Ross Thompson 2021-03-10 14:43:44 -06:00
parent 50a92247b3
commit dcae90e3ad
5 changed files with 131 additions and 8100 deletions

View File

@ -1,40 +1,77 @@
#!/bin/bash
allProgramRadixFile="FunctionRadix"
programToIndexMap="ProgramMap.txt"
index=0
######################
# extractFunctionRadix.sh
#
# Written: Ross Thompson
# email: ross1728@gmail.com
# Created: March 1, 2021
# Modified: March 10, 2021
#
# Purpose: Processes all compiled object files into 4 files which assist in debuging applications.
# File 1: FunctionRadix.do: a custom modelsim radix which provides a human readable (string) name for each function
# When a the PCE is greater than or equal to the function's starting address, the label will be associated with this address.
# File 2 and 3: FunctionRadix_32.addr and FunctionRadix_64.addr: These files contain the shorted starting addresses for each
# function or global assmelby label. There are multiple applications so the adddress is program's compile index (16 bit)
# concatenated with the instruction address. The 32 bit version is for 32 bit programs while the 64 bit version is for 64 bit
# programs.
# File 4: ProgramMap.txt: This is a list of all programs in the order in which they are compiled (32 or 64 bit). In modelsim this is used as
# an associate array to find the compile index.
#
# A component of the Wally configurable RISC-V project.
#
# Copyright (C) 2021 Harvey Mudd College & Oklahoma State University
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
# is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
######################
# clear the files
rm -rf $allProgramRadixFile.addr $allProgramRadixFile.do $programToIndexMap
echo "radix define Functions {" > $allProgramRadixFile.do
function processProgram {
local objDumpFile=$1
#local size=$2
#local numBits=$(($size*4))
local numBits=$2
local size=$(($numBits/4))
local index=$3
for objDumpFile in "$@";
do
# get the lines with named labels from the obj files.
# 64 bit addresses
listOfAddr16=`egrep -i '^[0-9]{16} <[0-9a-zA-Z_]+>' $objDumpFile`
# 32 bit addresses
listOfAddr8=`egrep -i '^[0-9]{8} <[0-9a-zA-Z_]+>' $objDumpFile`
listOfAddr=`echo "$listOfAddr16" "$listOfAddr8"`
# when size = 16 => 64 bit
# when size = 8 => 32 bit
local listOfAddr=`egrep -i "^[0-9]{$size} <[0-9a-zA-Z_]+>" $objDumpFile`
#echo "$objDumpFile, $size, $index, $listOfAddr"
# skip if the wrong bit width.
if [ -z "$listOfAddr" ]; then
return 0
fi
# parse out the addresses and the labels
addresses=`echo "$listOfAddr" | awk '{print $1}'`
labels=`echo "$listOfAddr" | awk '{print "\""$2"\"", "-color \"SpringGreen\","}' | tr -d '<>:'`
local addresses=`echo "$listOfAddr" | awk '{print $1}'`
local labels=`echo "$listOfAddr" | awk '{print "\""$2"\"", "-color \"SpringGreen\","}' | tr -d '<>:'`
# output per program function address list
echo "$addresses" > $objDumpFile.addr
# need to add some formatting to each line
numLines=`echo "$listOfAddr" | wc -l`
prefix=`yes " 16#" | head -n $numLines`
midfix=`yes "# " | head -n $numLines`
local numLines=`echo "$listOfAddr" | wc -l`
local prefix=`yes " 16#" | head -n $numLines`
local midfix=`yes "# " | head -n $numLines`
# paste echos each of the 4 parts on a per line basis.
#-d'\0' sets no delimiter
temp=`paste -d'\0' <(echo "$prefix") <(echo "$addresses") <(echo "$midfix") <(echo "$labels")`
local temp=`paste -d'\0' <(echo "$prefix") <(echo "$addresses") <(echo "$midfix") <(echo "$labels")`
# remove the last comma
temp2=${temp::-1}
local temp2=${temp::-1}
echo "radix define Functions {" > $objDumpFile.do
echo "$temp2" >> $objDumpFile.do
@ -47,23 +84,47 @@ do
# first convert the index to a string, 16 bits length
# then duplicate the index numlines times
# concat the index with the address
indexStr=`printf "%04x" "$index"`
copyIndex=`yes "$indexStr" | head -n $numLines`
allAddresses=`paste -d'\0' <(printf "%s" "$copyIndex") <(echo "$addresses")`
printf "%s\n" "$allAddresses" >> $allProgramRadixFile.addr
local indexStr=`printf "%04x" "$index"`
local copyIndex=`yes "$indexStr" | head -n $numLines`
local allAddresses=`paste -d'\0' <(printf "%s" "$copyIndex") <(echo "$addresses")`
printf "%s\n" "$allAddresses" >> ${allProgramRadixFile}_$numBits.addr
allAddressesTemp=`paste -d'\0' <(echo "$prefix") <(echo "$allAddresses") <(echo "$midfix") <(echo "$labels")`
local allAddressesTemp=`paste -d'\0' <(echo "$prefix") <(echo "$allAddresses") <(echo "$midfix") <(echo "$labels")`
printf "%s\n" "$allAddressesTemp" >> $allProgramRadixFile.do
return 0
}
allProgramRadixFile="FunctionRadix"
programToIndexMap="ProgramMap.txt"
index=0
# clear the files
rm -rf ${allProgramRadixFile}_32.addr ${allProgramRadixFile}_64.addr $allProgramRadixFile.do $programToIndexMap
echo "radix define Functions {" > $allProgramRadixFile.do
for objDumpFile in "$@";
do
# record the file names into a table so modelsim can know which application is running.
testName=`echo "$objDumpFile" | sed -e "s/.*work\/\(.*\)\.elf\.objdump/\1/g"`
printf "$testName\n" >> $programToIndexMap
processProgram "$objDumpFile" 32 "$index"
processProgram "$objDumpFile" 64 "$index"
index=$(($index+1))
done
# remove the last comma from the all radix
# '$ selects the last line
sed -i '$ s/,$//g' $allProgramRadixFile.do
echo "}" >> $allProgramRadixFile.do
exit 0

View File

@ -27,17 +27,20 @@ vlib work$2
# suppress spurious warnngs about
# "Extra checking for conflicts with always_comb done at vopt time"
# because vsim will run vopt
vlog +incdir+$1 ../testbench/testbench-imperas.sv ../src/*/*.sv -suppress 2583
#vlog +incdir+$1 ../testbench/testbench-imperas.sv ../src/*/*.sv -suppress 2583 -work work$2
# start and run simulation
# remove +acc flag for faster sim during regressions if there is no need to access internal signals
vopt work.testbench -o workopt
vsim workopt
#vopt +acc=+/testbench/dut/hart/ifu/bpred/DirPredictor/memory/memory +acc=+/testbench/dut/hart/ifu/bpred/TargetPredictor/memory/memory work$2.testbench -o workopt$2
#vsim workopt$2
# load the branch predictors with known data. The value of the data is not important for function, but
# is important for perventing pessimistic x propagation.
mem load -infile twoBitPredictor.txt -format bin testbench/dut/hart/ifu/bpred/DirPredictor/memory/memory
mem load -infile BTBPredictor.txt -format bin testbench/dut/hart/ifu/bpred/TargetPredictor/memory/memory
#mem load -infile twoBitPredictor.txt -format bin testbench/dut/hart/ifu/bpred/DirPredictor/memory/memory
#switch $argc {
# 0 {mem load -infile ../config/rv64ic/BTBPredictor.txt -format bin testbench/dut/hart/ifu/bpred/TargetPredictor/memory/memory}
# 1 {mem load -infile ../config/$1/BTBPredictor.txt -format bin testbench/dut/hart/ifu/bpred/TargetPredictor/memory/memory}
#}
run -all
quit
#run -all
#quit

File diff suppressed because it is too large Load Diff

View File

@ -51,7 +51,7 @@ module function_radix(reset, ProgramName);
// *** I should look into the system verilog objects instead of signal spy.
initial begin
$init_signal_spy("/testbench/dut/hart/PCE", "/testbench/function_radix/pc");
$init_signal_spy("/testbench/dut/hart/PCE", "/testbench/functionRadix/function_radix/pc");
end
assign TestAddr = {TestNumber, pc};
@ -98,24 +98,6 @@ module function_radix(reset, ProgramName);
end
endtask // bin_search_min
/* -----\/----- EXCLUDED -----\/-----
task automatic FindProgramIndex;
input string ProgramName;
ref integer array [string];
output integer ProgramIndex;
string line;
begin
ProgramIndex = array[ProgramName];
return;
end
endtask
-----/\----- EXCLUDED -----/\----- */
// *** this is all wrong
integer fp, ProgramFP;
integer line_count, ProgramLineCount;
logic [TotalSize-1:0] line;
@ -141,18 +123,19 @@ module function_radix(reset, ProgramName);
$display("Cannot open file %s for reading.", FunctionRadixFile);
end
$fclose(fp);
// ProgramIndexFile maps the program name to the compile index.
// The compile index is then used to inditify the application
// in the custom radix.
// Build an associative array to convert the name to an index.
ProgramLineCount = 0;
ProgramFP = $fopen(ProgramIndexFile, "r");
// read line by line to count lines
if (ProgramFP) begin
while (! $feof(ProgramFP)) begin
$fscanf(ProgramFP, "%s\n", ProgramLine);
// *** missing the memory update
ProgramBank[ProgramLine] = ProgramLineCount;
//$display("Program name is %s", ProgramLine);
ProgramLineCount = ProgramLineCount + 1;
end
end else begin
@ -166,10 +149,9 @@ module function_radix(reset, ProgramName);
bin_search_min(TestAddr, line_count, memory_bank, index);
end
always @(ProgramName, reset) begin
//FindProgramIndex(ProgramName, ProgramBank, TestNumber);
// Each time there is a new program update the test number
always @(ProgramName) begin
TestNumber = ProgramBank[ProgramName];
//TestNumber = ProgramBank["rv64i/I-ADD-01"];
end
endmodule // function_radix

View File

@ -27,7 +27,8 @@
`include "wally-config.vh"
module testbench();
parameter FunctionRadixFile = "../../imperas-riscv-tests/FunctionRadix.addr";
parameter FunctionRadixFile32 = "../../imperas-riscv-tests/FunctionRadix_32.addr";
parameter FunctionRadixFile64 = "../../imperas-riscv-tests/FunctionRadix_64.addr";
parameter ProgramIndexFile = "../../imperas-riscv-tests/ProgramMap.txt";
logic clk;
@ -453,11 +454,20 @@ string tests32i[] = {
end // always @ (negedge clk)
// track the current function or global label
function_radix #(.FunctionRadixFile(FunctionRadixFile),
.ProgramIndexFile(ProgramIndexFile))
function_radix(.reset(reset),
.ProgramName(testName));
generate
if (`XLEN == 32) begin : functionRadix
function_radix #(.FunctionRadixFile(FunctionRadixFile32),
.ProgramIndexFile(ProgramIndexFile))
function_radix(.reset(reset),
.ProgramName(testName));
end else begin : functionRadix
function_radix #(.FunctionRadixFile(FunctionRadixFile64),
.ProgramIndexFile(ProgramIndexFile))
function_radix(.reset(reset),
.ProgramName(testName));
end
endgenerate
endmodule
/* verilator lint_on STMTDLY */