Finally I think I have the function radix mapping across all applications correctly. I still need to clean up the code a bit so it is easier to understand.

This commit is contained in:
Ross Thompson 2021-03-10 11:00:51 -06:00
parent a3759f585d
commit 7b7cacbaf0
6 changed files with 8211 additions and 83 deletions

View File

@ -1,9 +1,14 @@
#!/bin/bash #!/bin/bash
allProgramRadixFile="FunctionRadix" allProgramRadixFile="FunctionRadix"
programToIndexMap="ProgramMap.txt"
index=0 index=0
# clear the files
rm -rf $allProgramRadixFile.addr $allProgramRadixFile.do $programToIndexMap
echo "radix define Functions {" > $allProgramRadixFile.do
for objDumpFile in "$@"; for objDumpFile in "$@";
do do
# get the lines with named labels from the obj files. # get the lines with named labels from the obj files.
@ -38,10 +43,27 @@ do
# now create the all in one version # now create the all in one version
# put the index at the begining of each line # put the index at the begining of each line
allAddresses=`paste -d'\0' <(printf "%04x" "$index") <(echo "$addresses")`
printf "%04x%s" "$index" "$addresses" >> $allProgramRadixFile.addr # 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
allAddressesTemp=`paste -d'\0' <(echo "$prefix") <(echo "$allAddresses") <(echo "$midfix") <(echo "$labels")`
printf "%s\n" "$allAddressesTemp" >> $allProgramRadixFile.do
testName=`echo "$objDumpFile" | sed -e "s/.*work\/\(.*\)\.elf\.objdump/\1/g"`
printf "$testName\n" >> $programToIndexMap
index=$(($index+1)) index=$(($index+1))
done done
# remove the last comma from the all radix
# '$ selects the last line
sed -i '$ s/,$//g' $allProgramRadixFile.do
echo "}" >> $allProgramRadixFile.do

View File

@ -30,8 +30,8 @@ vlib work
# default to config/rv64ic, but allow this to be overridden at the command line. For example: # default to config/rv64ic, but allow this to be overridden at the command line. For example:
# do wally-pipelined.do ../config/rv32ic # do wally-pipelined.do ../config/rv32ic
switch $argc { switch $argc {
0 {vlog +incdir+../config/rv64ic ../testbench/testbench-imperas.sv ../src/*/*.sv -suppress 2583} 0 {vlog +incdir+../config/rv64ic ../testbench/testbench-imperas.sv ../testbench/function_radix.sv ../src/*/*.sv -suppress 2583}
1 {vlog +incdir+$1 ../testbench/testbench-imperas.sv ../src/*/*.sv -suppress 2583} 1 {vlog +incdir+$1 ../testbench/testbench-imperas.sv ../testbench/function_radix.sv ../src/*/*.sv -suppress 2583}
} }
# start and run simulation # start and run simulation
# remove +acc flag for faster sim during regressions if there is no need to access internal signals # remove +acc flag for faster sim during regressions if there is no need to access internal signals
@ -51,5 +51,5 @@ add log -r /*
-- Run the Simulation -- Run the Simulation
#run 1000 #run 1000
run -all #run -all
#quit #quit

View File

@ -30,8 +30,8 @@ vlib work
# default to config/rv64ic, but allow this to be overridden at the command line. For example: # default to config/rv64ic, but allow this to be overridden at the command line. For example:
# do wally-pipelined.do ../config/rv32ic # do wally-pipelined.do ../config/rv32ic
switch $argc { switch $argc {
0 {vlog +incdir+../config/rv64ic ../testbench/testbench-imperas.sv ../src/*/*.sv -suppress 2583} 0 {vlog +incdir+../config/rv64ic ../testbench/testbench-imperas.sv ../testbench/function_radix.sv ../src/*/*.sv -suppress 2583}
1 {vlog +incdir+$1 ../testbench/testbench-imperas.sv ../src/*/*.sv -suppress 2583} 1 {vlog +incdir+$1 ../testbench/testbench-imperas.sv ../testbench/function_radix.sv ../src/*/*.sv -suppress 2583}
} }
# start and run simulation # start and run simulation
# remove +acc flag for faster sim during regressions if there is no need to access internal signals # remove +acc flag for faster sim during regressions if there is no need to access internal signals

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@
// Written: Ross Thompson // Written: Ross Thompson
// email: ross1728@gmail.com // email: ross1728@gmail.com
// Created: November 9, 2019 // Created: November 9, 2019
// Modified: March 04, 2021
// //
// Purpose: Finds the current function or global assembly label based on PCE. // Purpose: Finds the current function or global assembly label based on PCE.
// //
@ -26,27 +27,43 @@
`include "wally-config.vh" `include "wally-config.vh"
module function_radix(); module function_radix(reset, ProgramName);
parameter FunctionRadixFile, ProgramIndexFile;
parameter PRELOAD_FILE = "funct_addr.txt"; input logic reset;
/* -----\/----- EXCLUDED -----\/-----
input string FunctionRadixFile;
input string ProgramIndexFile;
-----/\----- EXCLUDED -----/\----- */
input string ProgramName;
integer memory_bank []; localparam TestSize = 16;
integer index; localparam TotalSize = `XLEN+TestSize;
logic [TotalSize-1:0] memory_bank [];
logic [TotalSize-1:0] index;
integer ProgramBank [string];
logic [`XLEN-1:0] pc; logic [`XLEN-1:0] pc;
logic [TestSize-1:0] TestNumber;
logic [TotalSize-1:0] TestAddr;
// *** I should look into the system verilog objects instead of signal spy.
initial begin initial begin
$init_signal_spy("/riscv_mram_tb/dut/pc", "/riscv_mram_tb/function_radix/pc"); $init_signal_spy("/testbench/dut/hart/PCE", "/testbench/function_radix/pc");
end end
task automatic bin_search_min; assign TestAddr = {TestNumber, pc};
input integer pc;
input integer length;
ref integer array [];
output integer minval;
integer left, right; task automatic bin_search_min;
integer mid; input logic [TotalSize-1:0] pc;
input logic [TotalSize-1:0] length;
ref logic [TotalSize-1:0] array [];
output logic [TotalSize-1:0] minval;
logic [TotalSize-1:0] left, right;
logic [TotalSize-1:0] mid;
begin begin
left = 0; left = 0;
@ -59,8 +76,12 @@ module function_radix();
end end
if (array[mid] < pc) begin if (array[mid] < pc) begin
left = mid + 1; left = mid + 1;
end else begin end else if( array[mid] > pc) begin
right = mid -1; right = mid -1;
end else begin
$display("Critical Error in function radix. PC, %x not found.", pc);
return;
//$stop();
end end
end // while (left <= right) end // while (left <= right)
// if the element pc is now found, right and left will be equal at this point. // if the element pc is now found, right and left will be equal at this point.
@ -75,33 +96,80 @@ module function_radix();
return; return;
end end
end 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 endtask
-----/\----- EXCLUDED -----/\----- */
// *** this is all wrong
integer fp, ProgramFP;
integer line_count, ProgramLineCount;
logic [TotalSize-1:0] line;
string ProgramLine;
// preload // preload
initial $readmemh(PRELOAD_FILE, memory_bank); //always @ (posedge reset) begin
// we need to count the number of lines in the file so we can set line_count.
integer fp;
integer line_count = 0;
logic [31:0] line;
initial begin initial begin
fp = $fopen(PRELOAD_FILE, "r"); $readmemh(FunctionRadixFile, memory_bank);
// we need to count the number of lines in the file so we can set line_count.
line_count = 0;
fp = $fopen(FunctionRadixFile, "r");
// read line by line to count lines // read line by line to count lines
if (fp) begin if (fp) begin
while (! $feof(fp)) begin while (! $feof(fp)) begin
$fscanf(fp, "%h\n", line); $fscanf(fp, "%h\n", line);
line_count = line_count + 1; line_count = line_count + 1;
end end
end else begin end else begin
$display("Cannot open file %s for reading.", PRELOAD_FILE); $display("Cannot open file %s for reading.", FunctionRadixFile);
$stop;
end end
$fclose(fp);
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
$display("Cannot open file %s for reading.", ProgramIndexFile);
end
$fclose(ProgramFP);
end end
always @(pc) begin always @(pc) begin
bin_search_min(pc, line_count, memory_bank, index); bin_search_min(TestAddr, line_count, memory_bank, index);
end
always @(ProgramName, reset) begin
//FindProgramIndex(ProgramName, ProgramBank, TestNumber);
TestNumber = ProgramBank[ProgramName];
//TestNumber = ProgramBank["rv64i/I-ADD-01"];
end end
endmodule // function_radix endmodule // function_radix

View File

@ -27,6 +27,9 @@
`include "wally-config.vh" `include "wally-config.vh"
module testbench(); module testbench();
parameter FunctionRadixFile = "../../imperas-riscv-tests/FunctionRadix.addr";
parameter ProgramIndexFile = "../../imperas-riscv-tests/ProgramMap.txt";
logic clk; logic clk;
logic reset; logic reset;
@ -305,6 +308,7 @@ string tests32i[] = {
}; };
string tests[]; string tests[];
string testName;
logic [`AHBW-1:0] HRDATAEXT; logic [`AHBW-1:0] HRDATAEXT;
logic HREADYEXT, HRESPEXT; logic HREADYEXT, HRESPEXT;
logic [31:0] HADDR; logic [31:0] HADDR;
@ -368,6 +372,7 @@ string tests32i[] = {
memfilename = {"../../imperas-riscv-tests/work/", tests[test], ".elf.memfile"}; memfilename = {"../../imperas-riscv-tests/work/", tests[test], ".elf.memfile"};
$readmemh(memfilename, dut.imem.RAM); $readmemh(memfilename, dut.imem.RAM);
$readmemh(memfilename, dut.uncore.dtim.RAM); $readmemh(memfilename, dut.uncore.dtim.RAM);
testName = tests[test];
reset = 1; # 42; reset = 0; reset = 1; # 42; reset = 0;
end end
@ -441,13 +446,17 @@ string tests32i[] = {
$readmemh(memfilename, dut.imem.RAM); $readmemh(memfilename, dut.imem.RAM);
$readmemh(memfilename, dut.uncore.dtim.RAM); $readmemh(memfilename, dut.uncore.dtim.RAM);
$display("Read memfile %s", memfilename); $display("Read memfile %s", memfilename);
testName = tests[test];
reset = 1; # 17; reset = 0; reset = 1; # 17; reset = 0;
end end
end end
end // always @ (negedge clk) end // always @ (negedge clk)
// track the current function or label // track the current function or global label
//function_rfunction_radix function_radix(); function_radix #(.FunctionRadixFile(FunctionRadixFile),
.ProgramIndexFile(ProgramIndexFile))
function_radix(.reset(reset),
.ProgramName(testName));
endmodule endmodule