`include "wally-config.vh" module testbench_busybear(); logic clk, reset; logic [31:0] GPIOPinsIn; logic [31:0] GPIOPinsOut, GPIOPinsEn; // instantiate device to be tested logic [`XLEN-1:0] PCF; logic [31:0] InstrF; logic InstrAccessFaultF, DataAccessFaultM; logic TimerIntM = 0, SwIntM = 0; // from CLINT logic ExtIntM = 0; // not yet connected logic [`AHBW-1:0] HRDATA; logic HREADY, HRESP; logic [31:0] HADDR; logic [`AHBW-1:0] HWDATA; logic HWRITE; logic [2:0] HSIZE; logic [2:0] HBURST; logic [3:0] HPROT; logic [1:0] HTRANS; logic HMASTLOCK; logic HCLK, HRESETn; assign GPIOPinsIn = 0; assign UARTSin = 1; assign HREADY = 1; assign HRESP = 0; assign HRDATA = 0; // for now, seem to need these to be zero until we get a better idea assign InstrAccessFaultF = 0; assign DataAccessFaultM = 0; // instantiate processor and memories wallypipelinedhart dut(.*); // initialize test initial begin reset <= 1; # 22; reset <= 0; end // read pc trace file integer data_file_PC, scan_file_PC; initial begin data_file_PC = $fopen("../busybear-testgen/parsedPC.txt", "r"); if (data_file_PC == 0) begin $display("file couldn't be opened"); $stop; end end integer data_file_PCW, scan_file_PCW; initial begin data_file_PCW = $fopen("../busybear-testgen/parsedPC.txt", "r"); if (data_file_PCW == 0) begin $display("file couldn't be opened"); $stop; end end // read register trace file integer data_file_rf, scan_file_rf; initial begin data_file_rf = $fopen("../busybear-testgen/parsedRegs.txt", "r"); if (data_file_rf == 0) begin $display("file couldn't be opened"); $stop; end end // read CSR trace file integer data_file_csr, scan_file_csr; initial begin data_file_csr = $fopen("../busybear-testgen/parsedCSRs.txt", "r"); if (data_file_csr == 0) begin $display("file couldn't be opened"); $stop; end end // read memreads trace file integer data_file_memR, scan_file_memR; initial begin data_file_memR = $fopen("../busybear-testgen/parsedMemRead.txt", "r"); if (data_file_memR == 0) begin $display("file couldn't be opened"); $stop; end end // read memwrite trace file integer data_file_memW, scan_file_memW; initial begin data_file_memW = $fopen("../busybear-testgen/parsedMemWrite.txt", "r"); if (data_file_memW == 0) begin $display("file couldn't be opened"); $stop; end end logic [63:0] pcExpected; logic [63:0] regExpected; integer regNumExpected; genvar i; generate for(i=1; i<32; i++) begin always @(dut.ieu.dp.regf.rf[i]) begin if ($time == 0) begin scan_file_rf = $fscanf(data_file_rf, "%x\n", regExpected); if (dut.ieu.dp.regf.rf[i] != regExpected) begin $display("%t ps, instr %0d: rf[%0d] does not equal rf expected: %x, %x", $time, instrs, i, dut.ieu.dp.regf.rf[i], regExpected); end end else begin scan_file_rf = $fscanf(data_file_rf, "%d\n", regNumExpected); scan_file_rf = $fscanf(data_file_rf, "%x\n", regExpected); if (i != regNumExpected) begin $display("%t ps, instr %0d: wrong register changed: %0d, %0d expected", $time, instrs, i, regNumExpected); end if (dut.ieu.dp.regf.rf[i] != regExpected) begin $display("%t ps, instr %0d: rf[%0d] does not equal rf expected: %x, %x", $time, instrs, i, dut.ieu.dp.regf.rf[i], regExpected); end end end end endgenerate logic [`XLEN-1:0] readAdrExpected; // this might need to change always @(dut.MemRWM[1] or HADDR) begin if (dut.MemRWM[1]) begin if($feof(data_file_memR)) begin $display("no more memR data to read"); $stop; end scan_file_memR = $fscanf(data_file_memR, "%x\n", readAdrExpected); scan_file_memR = $fscanf(data_file_memR, "%x\n", HRDATA); #1; if (HADDR != readAdrExpected) begin $display("%t ps, instr %0d: HADDR does not equal readAdrExpected: %x, %x", $time, instrs, HADDR, readAdrExpected); end end end logic [`XLEN-1:0] writeDataExpected, writeAdrExpected; // this might need to change always @(HWDATA or HADDR or HSIZE) begin #1; if (HWRITE) begin if($feof(data_file_memW)) begin $display("no more memW data to read"); $stop; end scan_file_memW = $fscanf(data_file_memW, "%x\n", writeDataExpected); scan_file_memW = $fscanf(data_file_memW, "%x\n", writeAdrExpected); if (writeDataExpected != HWDATA) begin $display("%t ps, instr %0d: HWDATA does not equal writeDataExpected: %x, %x", $time, instrs, HWDATA, writeDataExpected); end if (writeAdrExpected != HADDR) begin $display("%t ps, instr %0d: HADDR does not equal writeAdrExpected: %x, %x", $time, instrs, HADDR, writeAdrExpected); end end end integer totalCSR = 0; logic [99:0] StartCSRexpected[63:0]; string StartCSRname[99:0]; initial begin while(1) begin scan_file_csr = $fscanf(data_file_csr, "%s\n", StartCSRname[totalCSR]); if(StartCSRname[totalCSR] == "---") begin break; end scan_file_csr = $fscanf(data_file_csr, "%x\n", StartCSRexpected[totalCSR]); totalCSR = totalCSR + 1; end end `define CHECK_CSR2(CSR, PATH) \ string CSR; \ logic [63:0] expected``CSR``; \ //CSR checking \ always @(``PATH``.``CSR``_REGW) begin \ if ($time > 1) begin \ scan_file_csr = $fscanf(data_file_csr, "%s\n", CSR); \ scan_file_csr = $fscanf(data_file_csr, "%x\n", expected``CSR``); \ if(CSR.icompare(`"CSR`")) begin \ $display("%t ps, instr %0d: %s changed, expected %s", $time, instrs, `"CSR`", CSR); \ end \ if(``PATH``.``CSR``_REGW != ``expected``CSR) begin \ $display("%t ps, instr %0d: %s does not equal %s expected: %x, %x", $time, instrs, `"CSR`", CSR, ``PATH``.``CSR``_REGW, ``expected``CSR); \ end \ end else begin \ for(integer j=0; j