2020-11-24 05:20:29 +00:00
|
|
|
module mips_cpu_harvard(
|
|
|
|
/* Standard signals */
|
|
|
|
input logic clk,
|
|
|
|
input logic reset,
|
|
|
|
output logic active,
|
|
|
|
output logic [31:0] register_v0,
|
|
|
|
|
|
|
|
/* New clock enable. See below. */
|
|
|
|
input logic clk_enable,
|
2020-12-07 21:46:01 +00:00
|
|
|
|
2020-11-24 05:20:29 +00:00
|
|
|
/* Combinatorial read access to instructions */
|
2020-12-07 21:46:01 +00:00
|
|
|
output logic[31:0] instr_address,//Port from PC out to instruction memory address input.
|
|
|
|
input logic[31:0] instr_readdata,//port from instruction memory out, going to various inputs.
|
2020-11-24 05:20:29 +00:00
|
|
|
|
|
|
|
/* Combinatorial read and single-cycle write access to instructions */
|
2020-12-16 15:00:46 +00:00
|
|
|
output logic[31:0] data_address,
|
|
|
|
output logic data_write,
|
|
|
|
output logic data_read,
|
|
|
|
output logic[31:0] data_writedata,
|
|
|
|
input logic[31:0] data_readdata
|
2020-11-29 01:04:08 +00:00
|
|
|
);
|
|
|
|
|
2020-12-15 11:16:01 +00:00
|
|
|
assign instr_address = out_pc_out;
|
2020-12-12 06:59:14 +00:00
|
|
|
assign data_address = out_ALURes;
|
|
|
|
assign data_write = out_MemWrite;
|
|
|
|
assign data_read = out_MemRead;
|
|
|
|
assign data_writedata = out_readdata2;
|
2020-11-29 01:04:08 +00:00
|
|
|
|
2020-12-16 05:04:45 +00:00
|
|
|
logic[31:0] out_pc_out, out_ALURes, out_readdata1, out_readdata2, in_B, in_writedata, out_ALUHi, out_ALULo;
|
2020-12-11 10:45:13 +00:00
|
|
|
logic[4:0] in_readreg1, in_readreg2, in_writereg, out_shamt, out_ALUOp;
|
2020-12-07 21:46:01 +00:00
|
|
|
logic[5:0] in_opcode;
|
2020-12-16 08:38:46 +00:00
|
|
|
logic out_ALUCond, out_RegWrite, out_MemWrite, out_MemRead, out_SpcRegWriteEn;
|
|
|
|
logic[1:0] out_RegDst, out_PC, out_ALUSrc;
|
2020-12-15 21:48:28 +00:00
|
|
|
logic[2:0] out_MemtoReg;
|
2020-11-29 01:04:08 +00:00
|
|
|
|
2020-12-11 10:45:13 +00:00
|
|
|
assign in_readreg1 = instr_readdata[25:21];
|
|
|
|
assign in_readreg2 = instr_readdata[20:16];
|
|
|
|
assign in_opcode = instr_readdata[31:26];
|
2020-11-29 01:04:08 +00:00
|
|
|
|
2020-12-12 06:59:14 +00:00
|
|
|
always @(*) begin
|
2020-12-11 10:45:13 +00:00
|
|
|
//Picking what register should be written to.
|
2020-12-07 21:46:01 +00:00
|
|
|
case(out_RegDst)
|
2020-12-11 10:45:13 +00:00
|
|
|
2'd0: begin
|
2020-12-07 21:46:01 +00:00
|
|
|
in_writereg = instr_readdata[20:16];//GPR rt
|
|
|
|
end
|
2020-12-11 10:45:13 +00:00
|
|
|
2'd1: begin
|
2020-12-07 21:46:01 +00:00
|
|
|
in_writereg = instr_readdata[15:11];//GPR rd
|
|
|
|
end
|
2020-12-11 10:45:13 +00:00
|
|
|
2'd2: begin
|
2020-12-07 21:46:01 +00:00
|
|
|
in_writereg = 5'd31;//Link Register 31.
|
|
|
|
end
|
|
|
|
endcase
|
2020-11-29 01:04:08 +00:00
|
|
|
|
2020-12-11 10:45:13 +00:00
|
|
|
//Picking which output should be written to regfile.
|
2020-12-07 21:46:01 +00:00
|
|
|
case(out_MemtoReg)
|
2020-12-15 21:48:28 +00:00
|
|
|
3'd0:begin
|
2020-12-07 21:46:01 +00:00
|
|
|
in_writedata = out_ALURes;//Output from ALU Result.
|
|
|
|
end
|
2020-12-15 21:48:28 +00:00
|
|
|
3'd1:begin
|
2020-12-07 21:46:01 +00:00
|
|
|
in_writedata = data_readdata;//Output from Data Memory.
|
|
|
|
end
|
2020-12-15 21:48:28 +00:00
|
|
|
3'd2:begin
|
2020-12-07 21:46:01 +00:00
|
|
|
in_writedata = (out_pc_out + 32'd8);//Output from PC +8.
|
2020-12-16 15:00:46 +00:00
|
|
|
$display("LINKING-----------<: %h", in_writedata);
|
2020-12-07 21:46:01 +00:00
|
|
|
end
|
2020-12-15 21:48:28 +00:00
|
|
|
3'd3:begin
|
|
|
|
in_writedata = (out_ALUHi);
|
|
|
|
end
|
|
|
|
3'd4:begin
|
|
|
|
in_writedata = (out_ALULo);
|
|
|
|
end
|
2020-12-07 21:46:01 +00:00
|
|
|
endcase
|
2020-11-29 01:04:08 +00:00
|
|
|
|
2020-12-11 10:45:13 +00:00
|
|
|
//Picking which output should be taken as the second operand for ALU.
|
2020-12-07 21:46:01 +00:00
|
|
|
case(out_ALUSrc)
|
2020-12-16 08:38:46 +00:00
|
|
|
2'd2: begin
|
|
|
|
in_B = {16'd0,instr_readdata[15:0]};
|
|
|
|
end
|
|
|
|
2'd1:begin
|
2020-12-07 21:46:01 +00:00
|
|
|
in_B = {{16{instr_readdata[15]}},instr_readdata[15:0]};//Output from the 16-bit immediate values sign extened to 32bits.
|
|
|
|
end
|
2020-12-16 08:38:46 +00:00
|
|
|
2'd0:begin
|
2020-12-07 21:46:01 +00:00
|
|
|
in_B = out_readdata2;//Output from 'Read data 2' port of regfile.
|
|
|
|
end
|
|
|
|
endcase
|
2020-12-02 17:23:28 +00:00
|
|
|
end
|
|
|
|
|
2020-12-12 06:59:14 +00:00
|
|
|
mips_cpu_pc pc(
|
2020-12-07 21:46:01 +00:00
|
|
|
//PC inputs
|
|
|
|
.clk(clk),//clk taken from the Standard signals
|
|
|
|
.rst(reset),//clk taken from the Standard signals
|
2020-12-16 13:21:57 +00:00
|
|
|
.Instr(instr_readdata), //needed for branches and jumps
|
|
|
|
.JumpReg(out_readdata1), //needed for jump register
|
2020-12-11 10:45:13 +00:00
|
|
|
.pc_ctrl(out_PC),
|
2020-12-07 21:46:01 +00:00
|
|
|
//PC outputs
|
2020-12-15 11:16:01 +00:00
|
|
|
.pc_out(out_pc_out),//What the pc outputs at every clock edge that goes into the 'Read address' port of Instruction Memory.
|
2020-12-11 10:45:13 +00:00
|
|
|
.active(active)
|
2020-11-29 01:04:08 +00:00
|
|
|
);
|
|
|
|
|
2020-12-07 21:46:01 +00:00
|
|
|
mips_cpu_control control( //instance of the 'mips_cpu_control' module called 'control' in top level 'harvard'
|
|
|
|
//Inputs to control
|
|
|
|
.Instr(instr_readdata), //Full instruction taken from the Instruction Memory.
|
|
|
|
.ALUCond(out_ALUCond), //Active high condition check from ALU
|
|
|
|
//Outputs from control
|
|
|
|
.CtrlRegDst(out_RegDst),
|
|
|
|
.CtrlPC(out_PC),
|
|
|
|
.CtrlMemRead(out_MemRead),
|
|
|
|
.CtrlMemtoReg(out_MemtoReg),
|
|
|
|
.CtrlALUOp(out_ALUOp),
|
|
|
|
.Ctrlshamt(out_shamt),
|
|
|
|
.CtrlMemWrite(out_MemWrite),
|
|
|
|
.CtrlALUSrc(out_ALUSrc),
|
2020-12-15 21:48:28 +00:00
|
|
|
.CtrlRegWrite(out_RegWrite),
|
|
|
|
.CtrlSpcRegWriteEn(out_SpcRegWriteEn)
|
2020-11-29 01:04:08 +00:00
|
|
|
);
|
|
|
|
|
2020-12-07 21:46:01 +00:00
|
|
|
mips_cpu_regfile regfile(
|
|
|
|
//Inputs to refile
|
|
|
|
.clk(clk), //clock input for triggering write port
|
|
|
|
.readreg1(in_readreg1), //read port 1 selector
|
|
|
|
.readreg2(in_readreg2), //read port 2 selector
|
|
|
|
.writereg(in_writereg), //write port selector
|
|
|
|
.writedata(in_writedata), //write port input data
|
|
|
|
.regwrite(out_RegWrite), //enable line for write port
|
|
|
|
.opcode(in_opcode), //opcode input for controlling partial load weirdness
|
|
|
|
//Outputs from regfile
|
|
|
|
.readdata1(out_readdata1), //read port 1 output
|
|
|
|
.readdata2(out_readdata2), //read port 2 output
|
|
|
|
.regv0(register_v0) //debug output of $v0 or $2 (first register for returning function results
|
2020-11-29 01:04:08 +00:00
|
|
|
);
|
2020-12-07 21:46:01 +00:00
|
|
|
|
2020-12-06 06:44:58 +00:00
|
|
|
mips_cpu_alu alu(
|
2020-12-07 21:46:01 +00:00
|
|
|
//Inputs to ALU
|
2020-12-15 21:48:28 +00:00
|
|
|
.clk(clk),
|
|
|
|
.rst(reset),
|
2020-12-07 21:46:01 +00:00
|
|
|
.A(out_readdata1), //operand 1 taken from 'Read data 1' aka the data stored in GPR rs.
|
|
|
|
.B(in_B), //operand 2 taken either from: 'Read data 2' aka the data stored in rt; or 16-bit immediate sign extended to 32 bits.
|
|
|
|
.ALUOp(out_ALUOp), //Operation selection for ALU decided, and output by control.
|
|
|
|
.shamt(out_shamt), //Shift amount required for shift instruction taken from control.
|
2020-12-15 21:48:28 +00:00
|
|
|
.Hi_in(out_readdata1),
|
|
|
|
.Lo_in(out_readdata1),
|
|
|
|
.SpcRegWriteEn(out_SpcRegWriteEn),
|
2020-12-07 21:46:01 +00:00
|
|
|
//Outputs from ALU
|
|
|
|
.ALUCond(out_ALUCond), //condition used by control to decide on branch instructions.
|
2020-12-15 21:48:28 +00:00
|
|
|
.ALURes(out_ALURes), //output/result of operation that goes to either: 'Address' port of Data Memory; or 'Write Data' port of the register file.
|
|
|
|
.ALUHi(out_ALUHi), //Special register Hi output to be used for MFHI instructions - feeds in_writedata.
|
2020-12-16 05:04:45 +00:00
|
|
|
.ALULo(out_ALULo) //Special register Hi output to be used for MFLO instructions - feeds in_writedata.
|
2020-11-29 01:04:08 +00:00
|
|
|
);
|
2020-12-07 21:46:01 +00:00
|
|
|
|
|
|
|
endmodule
|