From ab9247d625783d4a92af36d6cd6d0b3dc68fd5fa Mon Sep 17 00:00:00 2001 From: Noah Boorstin Date: Fri, 26 Feb 2021 20:26:54 +0000 Subject: [PATCH] busybear: add main ram loading, better instr checking also --- wally-pipelined/regression/wally-busybear.do | 4 ++- .../testbench/testbench-busybear.sv | 34 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/wally-pipelined/regression/wally-busybear.do b/wally-pipelined/regression/wally-busybear.do index cc8fa8cd..bf3d9d07 100644 --- a/wally-pipelined/regression/wally-busybear.do +++ b/wally-pipelined/regression/wally-busybear.do @@ -35,6 +35,8 @@ vopt +acc work.testbench_busybear -o workopt vsim workopt -suppress 8852,12070 mem load -startaddress 0 -endaddress 1024 -filltype value -fillradix hex -filldata 0 /testbench_busybear/bootram mem load -startaddress 0 -i "/courses/e190ax/busybear_boot/bootmem.txt" -format hex /testbench_busybear/bootram +mem load -startaddress 0 -endaddress 16777216 -filltype value -fillradix hex -filldata 0 /testbench_busybear/RAM +mem load -startaddress 0 -i "/courses/e190ax/busybear_boot/ram.txt" -format hex /testbench_busybear/RAM view wave @@ -51,7 +53,7 @@ add wave /testbench_busybear/lastInstrF add wave /testbench_busybear/speculative add wave /testbench_busybear/lastPC2 add wave -divider -add wave -hex /testbench_busybear/readPC +add wave -hex /testbench_busybear/readInstrF add wave -hex /testbench_busybear/readRAM #add wave -hex /testbench_busybear/dut/hart/priv/csr/MTVEC_REG #add wave -hex /testbench_busybear/dut/hart/priv/csr/MSTATUS_REG diff --git a/wally-pipelined/testbench/testbench-busybear.sv b/wally-pipelined/testbench/testbench-busybear.sv index 195ef6f7..5dc7a8c2 100644 --- a/wally-pipelined/testbench/testbench-busybear.sv +++ b/wally-pipelined/testbench/testbench-busybear.sv @@ -178,7 +178,7 @@ module testbench_busybear(); logic [`XLEN-1:0] RAM[('h8000000 >> 3):0]; logic [`XLEN-1:0] bootram[('h2000 >> 3):0]; logic [`XLEN-1:0] readRAM; - logic [31:0] readPC; + logic [31:0] readInstrF; integer RAMAdr, RAMPC; assign RAMAdr = (HADDR - (HADDR > 'h2fff ? 'h80000000 : 'h1000)) >> 3; assign RAMPC = (PCF - (PCF > 'h2fff ? 'h80000000 : 'h1000)) >> 3; @@ -361,14 +361,22 @@ module testbench_busybear(); initial begin instrs = 0; end + logic [31:0] InstrMask; + logic forcedInstr; always @(PCF) begin if (PCF >= 'h80000000 && PCF <= 'h87FFFFFF) begin - readPC = RAM[RAMPC] >> PCF[2] * 32; + readInstrF = RAM[RAMPC] >> PCF[2:1] * 16; + if (PCF[2:1] == 2'b11) begin + readInstrF |= RAM[RAMPC+1] << 16; + end end if (PCF >= 'h1000 && PCF <= 'h2FFF) begin - readPC = bootram[RAMPC] >> PCF[2] * 32; + readInstrF = bootram[RAMPC] >> PCF[2:1] * 16; + if (PCF[2:1] == 2'b11) begin + readInstrF |= bootram[RAMPC+1] << 16; + end end lastInstrF = InstrF; @@ -392,11 +400,18 @@ module testbench_busybear(); InstrF = 32'b0010011; $display("warning: NOPing out %s at PC=%0x", PCtext, PCF); warningCount += 1; + forcedInstr = 1; end - if(InstrF[28:27] != 2'b11 && InstrF[6:0] == 7'b0101111) begin //for now, replace non-SC A instrs with LD - InstrF = {12'b0, InstrF[19:7], 7'b0000011}; - $display("warning: replacing AMO instr %s at PC=%0x with ld", PCtext, PCF); - warningCount += 1; + else begin + if(InstrF[28:27] != 2'b11 && InstrF[6:0] == 7'b0101111) begin //for now, replace non-SC A instrs with LD + InstrF = {12'b0, InstrF[19:7], 7'b0000011}; + $display("warning: replacing AMO instr %s at PC=%0x with ld", PCtext, PCF); + warningCount += 1; + forcedInstr = 1; + end + else begin + forcedInstr = 0; + end end // then expected PC value scan_file_PC = $fscanf(data_file_PC, "%x\n", pcExpected); @@ -432,8 +447,9 @@ module testbench_busybear(); $display("%0t ps, instr %0d: PC does not equal PC expected: %x, %x", $time, instrs, PCF, pcExpected); `ERROR end - if ((~speculative) && (readPC != InstrF)) begin - $display("%0t ps, instr %0d: readPC does not equal InstrF: %x, %x", $time, instrs, readPC, InstrF); + InstrMask = InstrF[1:0] == 2'b11 ? 32'hFFFFFFFF : 32'h0000FFFF; + if ((~forcedInstr) && (~speculative) && ((InstrMask & readInstrF) != (InstrMask & InstrF))) begin + $display("%0t ps, instr %0d: readInstrF does not equal InstrF: %x, %x, PC: %x", $time, instrs, readInstrF, InstrF, PCF); warningCount += 1; end end