Line 222... |
Line 222... |
assign id_stall = ex_stall || raw_detected;
|
assign id_stall = ex_stall || raw_detected;
|
assign ex_stall = mem_stall || mul_busy || div_busy;
|
assign ex_stall = mem_stall || mul_busy || div_busy;
|
assign mem_stall = wb_stall || ( (dmem_read_o||dmem_write_o) && !dmem_done_i);
|
assign mem_stall = wb_stall || ( (dmem_read_o||dmem_write_o) && !dmem_done_i);
|
assign wb_stall = 0;
|
assign wb_stall = 0;
|
|
|
|
// Branch taken
|
|
wire branch_taken;
|
|
assign branch_taken = ( ex_mem_branch==1 && (ex_mem_aluout==32'h00000001) );
|
|
|
// Name the System Configuration registers
|
// Name the System Configuration registers
|
wire[31:0] BadVAddr = SysCon[`SYSCON_BADVADDR];
|
wire[31:0] BadVAddr = SysCon[`SYSCON_BADVADDR];
|
wire[31:0] Status = SysCon[`SYSCON_STATUS];
|
wire[31:0] Status = SysCon[`SYSCON_STATUS];
|
wire[31:0] Cause = SysCon[`SYSCON_CAUSE];
|
wire[31:0] Cause = SysCon[`SYSCON_CAUSE];
|
wire[31:0] EPC = SysCon[`SYSCON_EPC];
|
wire[31:0] EPC = SysCon[`SYSCON_EPC];
|
Line 330... |
Line 334... |
* - write the PC register
|
* - write the PC register
|
*
|
*
|
* DESCRIPTION:
|
* DESCRIPTION:
|
* This stage usually reads the next instruction from the PC address in memory and
|
* This stage usually reads the next instruction from the PC address in memory and
|
* then updates the PC value by incrementing it by 4.
|
* then updates the PC value by incrementing it by 4.
|
* When a hazard is detected this stage is idle.
|
|
*/
|
*/
|
|
|
// A RAW hazard will stall the CPU
|
// Handle hazards (if_stall = id_stall || !imem_done_i)
|
if(if_stall) begin
|
if(if_stall) begin
|
|
|
|
// IF stall backward propagated from ID
|
if(id_stall) begin
|
if(id_stall) begin
|
$display("INFO: CPU(%m)-IF: Fetching stalled and latch kept for following stalled pipeline stage");
|
$display("INFO: CPU(%m)-IF: Fetching stalled like ID, latch keeps old value");
|
|
// IMEM is not ready
|
end else begin
|
end else begin
|
$display("INFO: CPU(%m)-IF: Fetching stalled and bubble inserted for following running pipeline stage");
|
$display("INFO: CPU(%m)-IF: Fetching stalled due to IMEM, latch filled with bubble");
|
if_id_opcode <= `BUBBLE;
|
if_id_opcode <= `BUBBLE;
|
end
|
end
|
|
|
end else begin
|
end else begin
|
|
|
// If branch taken update the Program Counter
|
// If branch taken update the Program Counter (branch_taken = ex_mem_branch==1 && ex_mem_aluout==32'h00000001)
|
if(ex_mem_branch==1 && ex_mem_aluout==32'h00000001) begin
|
if(branch_taken) begin
|
|
|
$display("INFO: CPU(%m)-IF: Bubble inserted due branch taken in EX/MEM instruction @ADDR=%X w/OPCODE=%X having ALUout=%X", ex_mem_addr, ex_mem_opcode, ex_mem_aluout);
|
$display("INFO: CPU(%m)-IF: Bubble inserted due branch taken in EX/MEM instruction @ADDR=%X w/OPCODE=%X having ALUout=%X", ex_mem_addr, ex_mem_opcode, ex_mem_aluout);
|
if_id_opcode <= `BUBBLE;
|
if_id_opcode <= `BUBBLE;
|
PC <= ex_mem_addrbranch;
|
PC <= ex_mem_addrbranch;
|
|
|
Line 390... |
Line 395... |
*
|
*
|
* DESCRIPTION:
|
* DESCRIPTION:
|
* This stage decodes the instruction and puts the values for the ALU inputs
|
* This stage decodes the instruction and puts the values for the ALU inputs
|
*/
|
*/
|
|
|
if(id_stall) begin
|
if(branch_taken) begin
|
|
$display("INFO: CPU(%m)-ID: Branch taken and bubble inserted");
|
|
id_ex_opcode <=`BUBBLE;
|
|
id_ex_alu_a <= 0;
|
|
id_ex_alu_b <= 0;
|
|
id_ex_alu_func <= `ALU_OP_ADD;
|
|
id_ex_alu_signed <= 0;
|
|
id_ex_addr <= if_id_addr;
|
|
id_ex_addrnext <= 0;
|
|
id_ex_addrjump <= 0;
|
|
id_ex_addrbranch <= 0;
|
|
id_ex_branch <= 0;
|
|
id_ex_jump <= 0;
|
|
id_ex_jr <= 0;
|
|
id_ex_linked <= 0;
|
|
id_ex_mult <= 0;
|
|
id_ex_div <= 0;
|
|
id_ex_load <= 0;
|
|
id_ex_store <= 0;
|
|
id_ex_destreg <= 0;
|
|
id_ex_desthi <= 0;
|
|
id_ex_destlo <= 0;
|
|
end else if(id_stall) begin
|
|
|
if(ex_stall) begin
|
if(ex_stall) begin
|
$display("INFO: CPU(%m)-ID: Decoding stalled and latch kept for following stalled pipeline stage");
|
$display("INFO: CPU(%m)-ID: Decoding stalled and latch kept");
|
end else begin
|
end else begin
|
$display("INFO: CPU(%m)-ID: Decoding stalled and bubble inserted for following running pipeline stage");
|
$display("INFO: CPU(%m)-ID: Decoding stalled and bubble inserted");
|
id_ex_opcode <=`BUBBLE;
|
id_ex_opcode <=`BUBBLE;
|
id_ex_alu_a <= 0;
|
id_ex_alu_a <= 0;
|
id_ex_alu_b <= 0;
|
id_ex_alu_b <= 0;
|
id_ex_alu_func <= `ALU_OP_ADD;
|
id_ex_alu_func <= `ALU_OP_ADD;
|
id_ex_alu_signed <= 0;
|
id_ex_alu_signed <= 0;
|
Line 1733... |
Line 1760... |
*/
|
*/
|
|
|
if(ex_stall) begin
|
if(ex_stall) begin
|
|
|
if(mem_stall) begin
|
if(mem_stall) begin
|
$display("INFO: CPU(%m)-EX: Execution stalled and latch kept for following stalled pipeline stage");
|
$display("INFO: CPU(%m)-EX: Execution stalled and latch kept");
|
end else begin
|
end else begin
|
$display("INFO: CPU(%m)-EX: Execution stalled and bubble inserted for following running pipeline stage");
|
$display("INFO: CPU(%m)-EX: Execution stalled and bubble inserted");
|
ex_mem_opcode <= `BUBBLE;
|
ex_mem_opcode <= `BUBBLE;
|
ex_mem_addr <= id_ex_addr;
|
ex_mem_addr <= id_ex_addr;
|
ex_mem_addrnext <= 0;
|
ex_mem_addrnext <= 0;
|
ex_mem_destreg <= 0;
|
ex_mem_destreg <= 0;
|
ex_mem_desthi <= 0;
|
ex_mem_desthi <= 0;
|