Fix overall w.r.t iverilog compiler error

This commit is contained in:
jl7719 2020-12-06 15:44:58 +09:00
parent a2bcf3ed1b
commit c5167645e7
10 changed files with 83648 additions and 85 deletions

83537
exec/mips_cpu_harvard_tb_addu Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
350C0003 34040003
350D0005 34050005
018D5021 00851021
01000008 00000008

View file

@ -20,10 +20,10 @@ ORI $5,$0,5
ADDU $2,$4,$5 ADDU $2,$4,$5
JR $0 JR $0
350C0003 34040003
350D0005 34050005
018D5021 00851021
01000008 00000008
register_vo = 8 register_vo = 8

View file

@ -1,11 +1,11 @@
module mips_cpu_alu( module mips_cpu_alu(
input signed logic[31:0] A, //Bus A - Input from the Readdata1 output from the reg file which corresponds to rs. input logic signed[31:0] A, //Bus A - Input from the Readdata1 output from the reg file which corresponds to rs.
input signed logic[31:0] B, //Bus B - Input from the Readdata2 output from the reg file which corresponds to rt. input logic signed[31:0] B, //Bus B - Input from the Readdata2 output from the reg file which corresponds to rt.
input logic[4:0] ALUOp, // 5-bit output from Control that tells the alu what operation to do from a list of 20 distinct alu operations(see below). input logic[4:0] ALUOp, // 5-bit output from Control that tells the alu what operation to do from a list of 20 distinct alu operations(see below).
input logic[4:0] shamt, //5-bit input used to specify shift amount for shift operations. Taken directly from the R-type instruction (Non-Variable) or from input logic[4:0] shamt, //5-bit input used to specify shift amount for shift operations. Taken directly from the R-type instruction (Non-Variable) or from
output logic ALUCond, //If a relevant condition is met, this output goes high(Active High). Note: Relevant as in related to current condition being tested. output logic ALUCond, //If a relevant condition is met, this output goes high(Active High). Note: Relevant as in related to current condition being tested.
output signed logic[31:0] ALURes, // The ouput of the ALU output logic signed[31:0] ALURes // The ouput of the ALU
); );
/* /*
@ -64,7 +64,7 @@ Alu Operations:
Ops ALUOps; //Note confusing naming to avoid potential duplicate variable naming errors, as a result of enum implemetnation quirks. Ops ALUOps; //Note confusing naming to avoid potential duplicate variable naming errors, as a result of enum implemetnation quirks.
assign ALUOps = ALUOp assign ALUOps = ALUOp;
always_comb begin always_comb begin
@ -88,43 +88,43 @@ assign ALUOps = ALUOp
end end
AND: begin AND: begin
ALUOut = A & B; ALURes = A & B;
end end
OR: begin OR: begin
ALUOut = A | B; ALURes = A | B;
end end
XOR: begin XOR: begin
ALUOut = A^B; ALURes = A^B;
end end
SLL: begin SLL: begin
ALUOut = B << shamt; ALURes = B << shamt;
end end
SLLV: begin SLLV: begin
ALUOut = B << A; ALURes = B << A;
end end
SRL: begin SRL: begin
ALUOut = B >> shamt; ALURes = B >> shamt;
end end
SRLV: begin SRLV: begin
ALUOut = B >> A; ALURes = B >> A;
end end
SRA: begin SRA: begin
ALUOut = B >>> shamt; ALURes = B >>> shamt;
end end
SRAV: begin SRAV: begin
ALUOut = B >>> A; ALURes = B >>> A;
end end
EQ: begin EQ: begin
if A == B begin if (A == B) begin
ALUCond = 1; ALUCond = 1;
end end
else begin else begin
@ -134,7 +134,7 @@ assign ALUOps = ALUOp
end end
LES: begin LES: begin
if A < B begin if (A < B) begin
ALUCond = 1; ALUCond = 1;
end end
else begin else begin
@ -144,17 +144,7 @@ assign ALUOps = ALUOp
end end
LEQ: begin LEQ: begin
if A <= B begin if (A <= B) begin
ALUCond = 1;
end
else begin
ALUCond = 0;
end
end
LEQ: begin
if A <= B begin
ALUCond = 1; ALUCond = 1;
end end
else begin else begin
@ -164,7 +154,7 @@ assign ALUOps = ALUOp
end end
GRT: begin GRT: begin
if A > B begin if (A > B) begin
ALUCond = 1; ALUCond = 1;
end end
else begin else begin
@ -174,7 +164,7 @@ assign ALUOps = ALUOp
end end
GEQ: begin GEQ: begin
if A >= B begin if (A >= B) begin
ALUCond = 1; ALUCond = 1;
end end
else begin else begin
@ -184,7 +174,7 @@ assign ALUOps = ALUOp
end end
NEQ: begin NEQ: begin
if A != B begin if (A != B) begin
ALUCond = 1; ALUCond = 1;
end end
else begin else begin

View file

@ -45,7 +45,7 @@ Memtoreg:
//Commented signals represents dont care(x) //Commented signals represents dont care(x)
module mips_cpu_control{ module mips_cpu_control(
input logic[5:0] Instr, input logic[5:0] Instr,
input logic[5:0] rt, input logic[5:0] rt,
output logic[1:0] Regdst, output logic[1:0] Regdst,
@ -55,7 +55,7 @@ module mips_cpu_control{
output logic Memwrite, output logic Memwrite,
output logic Alusrc, output logic Alusrc,
output logic Regwrite, output logic Regwrite,
output logic Jump, output logic Jump
); );
always_comb begin always_comb begin
@ -119,7 +119,7 @@ module mips_cpu_control{
//Memtoreg=; //Memtoreg=;
Memwrite=0; Memwrite=0;
Alusrc=0; Alusrc=0;
Regwrite=0 Regwrite=0;
Jump=0; Jump=0;
end end
6'd6: begin 6'd6: begin
@ -206,7 +206,7 @@ module mips_cpu_control{
Regdst=2'b00; Regdst=2'b00;
Branch=0; Branch=0;
Memread=0; Memread=0;
Memtoreg=2b'00; Memtoreg=2'b00;
Memwrite=0; Memwrite=0;
Alusrc=1; Alusrc=1;
Regwrite=1; Regwrite=1;

View file

@ -23,13 +23,15 @@ module mips_cpu_harvard(
//Control Flags //Control Flags
logic Jump, Branch, ALUSrc, ALUZero, RegWrite; logic Jump, Branch, ALUSrc, ALUZero, RegWrite;
logic[5:0] ALUOp = instr_readdata[31:26]; logic[5:0] ALUOp = instr_readdata[31:26];
logic[999999999999999999999999999999999999999999999999999999999999999999:0] ALUFlags; logic[30:0] ALUFlags; //Not sure if this is needed anymore
logic[1:0] RegDst, MemtoReg; logic[1:0] RegDst, MemtoReg;
//PC wires //PC wires
logic[31:0] pc_curr; logic[31:0] pc_curr;
logic[31:0] pc_next = Jump ? Jump_addr : PCSrc ? {pc_curr+4+{{14{instr_readdata[15]}}, instr_readdata[15:0], 2'b00}} : {pc_curr+4}; logic[31:0] pc_curr_next = pc_curr + 3'd4; //Added due to compilation error
logic[31:0] Jump_addr = {{pc_curr+4}[31:28], instr_readdata[25:0], 2'b00}; logic[31:0] pc_delay; //Added due to compilation error
logic[31:0] Jump_addr = {pc_curr_next[31:28], instr_readdata[25:0], 2'b00};
logic[31:0] pc_next = Jump ? Jump_addr : PCSrc ? {pc_curr_next + {{14{instr_readdata[15]}}, instr_readdata[15:0], 2'b00}} : pc_curr_next;
logic PCSrc = Branch && ALUZero; logic PCSrc = Branch && ALUZero;
//Instruction MEM //Instruction MEM
@ -54,7 +56,7 @@ assign data_address = ALUOut; //address to be written to comes from ALU
assign data_writedata = read_data2; //data to be written comes from reg read bus 2 assign data_writedata = read_data2; //data to be written comes from reg read bus 2
//Writeback logic //Writeback logic
logic[31:0] writeback = MemtoReg==2'b10 ? {pc_curr+4} : MemtoReg==2'b01 ? data_readdata : ALUOut; logic[31:0] writeback = MemtoReg==2'b10 ? {pc_curr_next} : MemtoReg==2'b01 ? data_readdata : ALUOut;
always_ff @(posedge clk) begin always_ff @(posedge clk) begin
pc_delay <= pc_curr; pc_delay <= pc_curr;
@ -67,16 +69,16 @@ pc pc(
.pc_out(pc_curr) .pc_out(pc_curr)
); );
control control( //control flags block mips_cpu_control control( //control flags block
.opcode(opcode), //opcode to be decoded .Instr(opcode), //opcode to be decoded
.jump(Jump), //jump flag: 0 - increment or branch, 1 - J-type jump .Jump(Jump), //jump flag: 0 - increment or branch, 1 - J-type jump
.branch(Branch), //branch flag: 0 - increment, 1 - branch if ALU.Zero == 1 .Branch(Branch), //branch flag: 0 - increment, 1 - branch if ALU.Zero == 1
.memread(data_read), //tells data memory to read out data at dMEM[ALUout] .Memread(data_read), //tells data memory to read out data at dMEM[ALUout]
.memtoreg(MemtoReg), //0: writeback = ALUout, 1: writeback = data_readdata .Memtoreg(MemtoReg), //0: writeback = ALUout, 1: writeback = data_readdata
.memwrite(data_write), //tells data memory to store data_writedata at data_writeaddress .Memwrite(data_write), //tells data memory to store data_writedata at data_writeaddress
.alusrc(ALUSrc), //0: ALUin2 = read_data2, 1: ALUin2 = signextended(instr_readdata[15:0]) .Alusrc(ALUSrc), //0: ALUin2 = read_data2, 1: ALUin2 = signextended(instr_readdata[15:0])
.regwrite(RegWrite), //tells register file to write writeback to rd .Regwrite(RegWrite), //tells register file to write writeback to rd
.regdst(RegDst) //select Rt, Rd or $ra to store to .Regdst(RegDst) //select Rt, Rd or $ra to store to
); );
regfile regfile( regfile regfile(
@ -91,19 +93,20 @@ regfile regfile(
.readdata2(read_data2), //read port 2 output .readdata2(read_data2), //read port 2 output
.regv0(register_v0) //debug output of $v0 or $2 (first register for returning function results .regv0(register_v0) //debug output of $v0 or $2 (first register for returning function results
); );
/*
alucontrol alucontrol( alucontrol alucontrol(
.ALUOp(ALUOp), //opcode of instruction .ALUOp(ALUOp), //opcode of instruction
.funct(immediate[5:0]), //funct of instruction .funct(immediate[5:0]), //funct of instruction
.aluflags(ALUFlags) //ALU Control flags .aluflags(ALUFlags) //ALU Control flags
); );
*/
alu alu( mips_cpu_alu alu(
.ALUFlags(ALUFlags), //selects the operation carried out by the ALU //.ALUFlags(ALUFlags), //selects the operation carried out by the ALU
.A(alu_in1), //operand 1 .A(alu_in1), //operand 1
.B(alu_in2), //operand 2 .B(alu_in2), //operand 2
.ALUzero(ALUZero), //is the result zero, used for checks .ALUCond(ALUZero), //is the result zero, used for checks
.ALUOut(ALUOut), //output/result of operation .ALURes(ALUOut), //output/result of operation
.shamt(shamt) .shamt(shamt),
.ALUOp(ALUOp)
); );
endmodule : mips_cpu_harvard endmodule : mips_cpu_harvard

View file

@ -42,18 +42,20 @@ module mips_cpu_memory(
//Load contents from file if specified //Load contents from file if specified
if (RAM_INIT_FILE != "") begin if (RAM_INIT_FILE != "") begin
$display("RAM : INIT : Loading RAM contents from %s", RAM_INIT_FILE); $display("RAM : INIT : Loading RAM contents from %s", RAM_INIT_FILE);
$readmemh(RAM_INIT_FILE, memory[3217031168:0]); $readmemh(RAM_INIT_FILE, memory, 32'hBFC00000, 32'd0);
end end
end end
//Combinatorial read path for data and instruction. //Combinatorial read path for data and instruction.
if (clk == 1) begin always_comb begin
assign data_readdata = data_read ? memory[data_address] : 16'hxxxx; if (clk == 1'd1) begin
assign instr_readdata = memory[instr_address]; data_readdata = data_read ? memory[data_address] : 16'hxxxx;
instr_readdata = memory[instr_address];
end end
else begin else begin
assign data_readdata = data_readdata; data_readdata = data_readdata;
assign instr_readdata = instr_address; instr_readdata = instr_address;
end
end end

View file

@ -15,7 +15,7 @@ reg[31:0] memory [31:0]; //32 register slots, 32-bits wide
initial begin initial begin
integer i; //Initialise to zero by default integer i; //Initialise to zero by default
for (i = 0; i < 31; i++) begin for (i = 0; i < 32; i++) begin
memory[i] = 0; memory[i] = 0;
end end
end end

View file

@ -37,13 +37,21 @@ then
done done
else else
echo "ELSE"; echo ${INSTR};
# Run Testcase File Of Specified Instruction # Run Testcase File Of Specified Instruction
# iverilog -g 2012 \ # Windows Iverilog with WSL
#/mnt/c/Windows/System32/cmd.exe /C iverilog -g2012 \
# -s mips_cpu_harvard_tb \ # -s mips_cpu_harvard_tb \
# -P mips_cpu_harvard_tb.RAM_INIT_FILE=\"inputs/${INSTR}.hex.txt\" \ # -P mips_cpu_harvard_tb.RAM_INIT_FILE=\"inputs/${INSTR}.txt\" \
# -o program/mips_cpu_harvard_tb_${INSTR} testbench/mips_cpu_harvard_tb.v \ # -o program/mips_cpu_harvard_tb_${INSTR} testbench/mips_cpu_harvard_tb.v \
# ${SRC} # ${SRC}
# Linux Iverilog
iverilog -g2012 \
-s mips_cpu_harvard_tb \
-P mips_cpu_harvard_tb.RAM_INIT_FILE=\"inputs/${INSTR}.txt\" \
-o program/mips_cpu_harvard_tb_${INSTR} testbench/mips_cpu_harvard_tb.v \
${SRC}
fi fi
#/mnt/c/Windows/System32/cmd.exe /C \ # need this to run verilog on windows #/mnt/c/Windows/System32/cmd.exe /C \ # need this to run verilog on windows

View file

@ -10,8 +10,30 @@ module mips_cpu_harvard_tb;
logic data_read, data_write; logic data_read, data_write;
logic[31:0] data_readdata, data_writedata, data_address; logic[31:0] data_readdata, data_writedata, data_address;
mips_cpu_memory #(RAM_INIT_FILE) ramInst(clk, data_address, data_write, data_read, data_writedata, data_readdata, instr_address, instr_readdata); mips_cpu_memory #(RAM_INIT_FILE) ramInst(
mips_cpu_harvard cpuInst(clk, reset, active, register_v0, clk_enable, instr_address, instr_readdata, data_address, data_write, data_read, data_writedata, data_readdata); .clk(clk),
.data_address(data_address),
.data_write(data_write),
.data_read(data_read),
.data_writedata(data_writedata),
.data_readdata(data_readdata),
.instr_address(instr_address),
.instr_readdata(instr_readdata)
);
mips_cpu_harvard cpuInst(
.clk(clk),
.reset(reset),
.active(active),
.register_v0(register_v0),
.clk_enable(clk_enable),
.instr_address(instr_address),
.instr_readdata(instr_readdata),
.data_address(data_address),
.data_write(data_write),
.data_read(data_read),
.data_writedata(data_writedata),
.data_readdata(data_readdata)
);
// Generate clock // Generate clock
initial begin initial begin
@ -37,14 +59,15 @@ module mips_cpu_harvard_tb;
reset <= 0; reset <= 0;
@(posedge clk); @(posedge clk);
assert(running==1) assert(active==1) // Is this assert still valid?
else $display("TB : CPU did not set running=1 after reset."); else $display("TB : CPU did not set active=1 after reset.");
while (running) begin while (active) begin
@(posedge clk); @(posedge clk);
end end
$display("TB : finished; running=0"); $display("TB : finished; running=0");
$display("%d",register_v0);
$finish; $finish;
end end