added comments for RAM and bootram, removed trailing whitepace

This commit is contained in:
kaveh pezeshki 2021-02-23 21:28:33 -08:00
parent c8e9edcc43
commit b36a5614b4

View File

@ -7,7 +7,7 @@ module testbench_busybear();
logic [31:0] GPIOPinsOut, GPIOPinsEn; logic [31:0] GPIOPinsOut, GPIOPinsEn;
// instantiate device to be tested // instantiate device to be tested
logic [`XLEN-1:0] PCF; logic [`XLEN-1:0] PCF;
logic [31:0] InstrF; logic [31:0] InstrF;
logic [`AHBW-1:0] HRDATA; logic [`AHBW-1:0] HRDATA;
@ -26,7 +26,7 @@ module testbench_busybear();
assign GPIOPinsIn = 0; assign GPIOPinsIn = 0;
assign UARTSin = 1; assign UARTSin = 1;
// instantiate processor and memories // instantiate processor and memories
wallypipelinedsocbusybear dut(.*); wallypipelinedsocbusybear dut(.*);
@ -36,7 +36,7 @@ module testbench_busybear();
begin begin
reset <= 1; # 22; reset <= 0; reset <= 1; # 22; reset <= 0;
end end
// read pc trace file // read pc trace file
integer data_file_PC, scan_file_PC; integer data_file_PC, scan_file_PC;
initial begin initial begin
@ -44,7 +44,7 @@ module testbench_busybear();
if (data_file_PC == 0) begin if (data_file_PC == 0) begin
$display("file couldn't be opened"); $display("file couldn't be opened");
$stop; $stop;
end end
end end
integer data_file_PCW, scan_file_PCW; integer data_file_PCW, scan_file_PCW;
@ -53,7 +53,7 @@ module testbench_busybear();
if (data_file_PCW == 0) begin if (data_file_PCW == 0) begin
$display("file couldn't be opened"); $display("file couldn't be opened");
$stop; $stop;
end end
end end
// read register trace file // read register trace file
@ -63,7 +63,7 @@ module testbench_busybear();
if (data_file_rf == 0) begin if (data_file_rf == 0) begin
$display("file couldn't be opened"); $display("file couldn't be opened");
$stop; $stop;
end end
end end
// read CSR trace file // read CSR trace file
@ -73,7 +73,7 @@ module testbench_busybear();
if (data_file_csr == 0) begin if (data_file_csr == 0) begin
$display("file couldn't be opened"); $display("file couldn't be opened");
$stop; $stop;
end end
end end
// read memreads trace file // read memreads trace file
@ -83,9 +83,9 @@ module testbench_busybear();
if (data_file_memR == 0) begin if (data_file_memR == 0) begin
$display("file couldn't be opened"); $display("file couldn't be opened");
$stop; $stop;
end end
end end
// read memwrite trace file // read memwrite trace file
integer data_file_memW, scan_file_memW; integer data_file_memW, scan_file_memW;
initial begin initial begin
@ -93,7 +93,7 @@ module testbench_busybear();
if (data_file_memW == 0) begin if (data_file_memW == 0) begin
$display("file couldn't be opened"); $display("file couldn't be opened");
$stop; $stop;
end end
end end
integer warningCount = 0; integer warningCount = 0;
@ -163,7 +163,18 @@ module testbench_busybear();
end end
end end
endgenerate endgenerate
// RAM and bootram are addressed in 64-bit blocks - this logic handles R/W
// including subwords. Brief explanation on signals:
//
// readMask: bitmask of bits to read / write, left-shifted to align with
// nearest 64-bit boundary - examples
// HSIZE = 0 -> readMask = 11111111
// HSIZE = 1 -> readMask = 1111111111111111
//
// In the linux boot, the processor spends the first ~5 instructions in
// bootram, before jr jumps to main RAM
logic [`XLEN-1:0] RAM[('h8000000 >> 3):0]; logic [`XLEN-1:0] RAM[('h8000000 >> 3):0];
logic [`XLEN-1:0] bootram[('h2000 >> 3):0]; logic [`XLEN-1:0] bootram[('h2000 >> 3):0];
logic [`XLEN-1:0] readRAM, readPC; logic [`XLEN-1:0] readRAM, readPC;
@ -175,7 +186,7 @@ module testbench_busybear();
always @(HWDATA or HADDR or HSIZE or HWRITE or dut.hart.MemRWM[1]) begin always @(HWDATA or HADDR or HSIZE or HWRITE or dut.hart.MemRWM[1]) begin
if ((HWRITE || dut.hart.MemRWM[1]) && (HADDR >= 'h80000000 && HADDR <= 'h87FFFFFF)) begin if ((HWRITE || dut.hart.MemRWM[1]) && (HADDR >= 'h80000000 && HADDR <= 'h87FFFFFF)) begin
if (HWRITE) begin if (HWRITE) begin
RAM[RAMAdr] = (RAM[RAMAdr] & (~readMask)) | ((HWDATA << 8 * HADDR[2:0]) & readMask); RAM[RAMAdr] = (RAM[RAMAdr] & (~readMask)) | ((HWDATA << 8 * HADDR[2:0]) & readMask); // aligns write data for correct subword size
end else begin end else begin
readRAM = RAM[RAMAdr] & readMask; readRAM = RAM[RAMAdr] & readMask;
end end
@ -225,7 +236,7 @@ module testbench_busybear();
end end
end end
end end
logic [`XLEN-1:0] writeDataExpected, writeAdrExpected; logic [`XLEN-1:0] writeDataExpected, writeAdrExpected;
// this might need to change // this might need to change
always @(HWDATA or HADDR or HSIZE or HWRITE) begin always @(HWDATA or HADDR or HSIZE or HWRITE) begin
@ -253,7 +264,7 @@ module testbench_busybear();
string StartCSRname[99:0]; string StartCSRname[99:0];
initial begin initial begin
while(1) begin while(1) begin
scan_file_csr = $fscanf(data_file_csr, "%s\n", StartCSRname[totalCSR]); scan_file_csr = $fscanf(data_file_csr, "%s\n", StartCSRname[totalCSR]);
if(StartCSRname[totalCSR] == "---") begin if(StartCSRname[totalCSR] == "---") begin
break; break;
end end
@ -261,7 +272,7 @@ module testbench_busybear();
totalCSR = totalCSR + 1; totalCSR = totalCSR + 1;
end end
end end
`define CHECK_CSR2(CSR, PATH) \ `define CHECK_CSR2(CSR, PATH) \
string CSR; \ string CSR; \
logic [63:0] expected``CSR``; \ logic [63:0] expected``CSR``; \
@ -289,8 +300,8 @@ module testbench_busybear();
end \ end \
end end
`define CHECK_CSR(CSR) \ `define CHECK_CSR(CSR) \
`CHECK_CSR2(CSR, dut.hart.priv.csr) `CHECK_CSR2(CSR, dut.hart.priv.csr)
`define CSRM dut.hart.priv.csr.genblk1.csrm `define CSRM dut.hart.priv.csr.genblk1.csrm
`define CSRS dut.hart.priv.csr.genblk1.csrs.genblk1 `define CSRS dut.hart.priv.csr.genblk1.csrs.genblk1
//`CHECK_CSR(FCSR) //`CHECK_CSR(FCSR)
@ -357,7 +368,7 @@ module testbench_busybear();
integer instrs; integer instrs;
initial begin initial begin
instrs = 0; instrs = 0;
end end
always @(PCF) begin always @(PCF) begin
lastInstrF = InstrF; lastInstrF = InstrF;
lastPC <= PCF; lastPC <= PCF;
@ -395,7 +406,7 @@ module testbench_busybear();
end end
instrs += 1; instrs += 1;
// are we at a branch/jump? // are we at a branch/jump?
casex (lastInstrF[31:0]) casex (lastInstrF[31:0])
32'b00000000001000000000000001110011, // URET 32'b00000000001000000000000001110011, // URET
32'b00010000001000000000000001110011, // SRET 32'b00010000001000000000000001110011, // SRET
32'b00110000001000000000000001110011, // MRET 32'b00110000001000000000000001110011, // MRET