OpenCores
URL https://opencores.org/ocsvn/altor32/altor32/trunk

Subversion Repositories altor32

[/] [altor32/] [trunk/] [rtl/] [cpu/] [altor32_writeback.v] - Diff between revs 37 and 40

Only display areas with differences | Details | Blame | View Log

Rev 37 Rev 40
//-----------------------------------------------------------------
//-----------------------------------------------------------------
//                           AltOR32 
//                           AltOR32 
//                Alternative Lightweight OpenRisc 
//                Alternative Lightweight OpenRisc 
//                            V2.1
//                            V2.1
//                     Ultra-Embedded.com
//                     Ultra-Embedded.com
//                   Copyright 2011 - 2014
//                   Copyright 2011 - 2014
//
//
//               Email: admin@ultra-embedded.com
//               Email: admin@ultra-embedded.com
//
//
//                       License: LGPL
//                       License: LGPL
//-----------------------------------------------------------------
//-----------------------------------------------------------------
//
//
// Copyright (C) 2011 - 2014 Ultra-Embedded.com
// Copyright (C) 2011 - 2014 Ultra-Embedded.com
//
//
// This source file may be used and distributed without         
// This source file may be used and distributed without         
// restriction provided that this copyright statement is not    
// restriction provided that this copyright statement is not    
// removed from the file and that any derivative work contains  
// removed from the file and that any derivative work contains  
// the original copyright notice and the associated disclaimer. 
// the original copyright notice and the associated disclaimer. 
//
//
// This source file is free software; you can redistribute it   
// This source file is free software; you can redistribute it   
// and/or modify it under the terms of the GNU Lesser General   
// and/or modify it under the terms of the GNU Lesser General   
// Public License as published by the Free Software Foundation; 
// Public License as published by the Free Software Foundation; 
// either version 2.1 of the License, or (at your option) any   
// either version 2.1 of the License, or (at your option) any   
// later version.
// later version.
//
//
// This source is distributed in the hope that it will be       
// This source is distributed in the hope that it will be       
// useful, but WITHOUT ANY WARRANTY; without even the implied   
// useful, but WITHOUT ANY WARRANTY; without even the implied   
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      
// PURPOSE.  See the GNU Lesser General Public License for more 
// PURPOSE.  See the GNU Lesser General Public License for more 
// details.
// details.
//
//
// You should have received a copy of the GNU Lesser General    
// You should have received a copy of the GNU Lesser General    
// Public License along with this source; if not, write to the 
// Public License along with this source; if not, write to the 
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
// Boston, MA  02111-1307  USA
// Boston, MA  02111-1307  USA
//-----------------------------------------------------------------
//-----------------------------------------------------------------
 
 
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// Includes
// Includes
//-----------------------------------------------------------------
//-----------------------------------------------------------------
`include "altor32_defs.v"
`include "altor32_defs.v"
 
 
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// Module - Writeback
// Module - Writeback
//-----------------------------------------------------------------
//-----------------------------------------------------------------
module altor32_writeback
module altor32_writeback
(
(
    // General
    // General
    input               clk_i /*verilator public*/,
    input               clk_i /*verilator public*/,
    input               rst_i /*verilator public*/,
    input               rst_i /*verilator public*/,
 
 
    // Opcode
    // Opcode
    input [31:0]        opcode_i /*verilator public*/,
    input [31:0]        opcode_i /*verilator public*/,
 
 
    // Register target
    // Register target
    input [4:0]         rd_i /*verilator public*/,
    input [4:0]         rd_i /*verilator public*/,
 
 
    // ALU result
    // ALU result
    input [31:0]        alu_result_i /*verilator public*/,
    input [31:0]        alu_result_i /*verilator public*/,
 
 
    // Memory load result
    // Memory load result
    input [31:0]        mem_result_i /*verilator public*/,
    input [31:0]        mem_result_i /*verilator public*/,
    input [1:0]         mem_offset_i /*verilator public*/,
    input [1:0]         mem_offset_i /*verilator public*/,
    input               mem_ready_i /*verilator public*/,
    input               mem_ready_i /*verilator public*/,
 
 
    // Multiplier result
    // Multiplier result
    input               mult_i /*verilator public*/,
    input [63:0]        mult_result_i /*verilator public*/,
    input [31:0]        mult_result_i /*verilator public*/,
 
 
 
    // Outputs
    // Outputs
    output              write_enable_o /*verilator public*/,
    output reg          write_enable_o /*verilator public*/,
    output [4:0]        write_addr_o /*verilator public*/,
    output reg [4:0]    write_addr_o /*verilator public*/,
    output [31:0]       write_data_o /*verilator public*/
    output reg [31:0]   write_data_o /*verilator public*/
);
);
 
 
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// Registers
// Registers / Wires
//-----------------------------------------------------------------
//-----------------------------------------------------------------
 
 
// Register address
// Register address
reg [4:0]  rd_q;
reg [4:0]  rd_q;
 
 
// Register writeback value
// Register writeback value
reg [31:0] result_q;
reg [31:0] result_q;
 
 
reg [7:0]  opcode_q;
reg [7:0]  opcode_q;
 
 
// Register writeback enable
// Register writeback enable
reg        write_rd_q;
reg        write_rd_q;
 
 
 
reg [1:0]  mem_offset_q;
 
 
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Writeback
// Pipeline Registers
//-------------------------------------------------------------------
//-------------------------------------------------------------------
always @ (posedge clk_i or posedge rst_i)
always @ (posedge clk_i or posedge rst_i)
begin
begin
   if (rst_i == 1'b1)
   if (rst_i == 1'b1)
   begin
   begin
       write_rd_q   <= 1'b1;
       write_rd_q   <= 1'b1;
       result_q     <= 32'h00000000;
       result_q     <= 32'h00000000;
       rd_q         <= 5'b00000;
       rd_q         <= 5'b00000;
       opcode_q     <= 8'b0;
       opcode_q     <= 8'b0;
 
       mem_offset_q <= 2'b0;
   end
   end
   else
   else
   begin
   begin
        rd_q        <= rd_i;
        rd_q        <= rd_i;
        result_q    <= alu_result_i;
        result_q    <= alu_result_i;
 
 
        opcode_q    <= {2'b00,opcode_i[31:26]};
        opcode_q    <= {2'b00,opcode_i[31:26]};
 
        mem_offset_q<= mem_offset_i;
 
 
        // Register writeback required?
        // Register writeback required?
        if (rd_i != 5'b00000)
        if (rd_i != 5'b00000)
            write_rd_q  <= 1'b1;
            write_rd_q  <= 1'b1;
        else
        else
            write_rd_q  <= 1'b0;
            write_rd_q  <= 1'b0;
   end
   end
end
end
 
 
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Load result resolve
// Load result resolve
//-------------------------------------------------------------------
//-------------------------------------------------------------------
wire            load_inst_w;
wire            load_inst_w;
wire [31:0]     load_result_w;
wire [31:0]     load_result_w;
 
 
altor32_lfu
altor32_lfu
u_lfu
u_lfu
(
(
    // Opcode
    // Opcode
    .opcode_i(opcode_q),
    .opcode_i(opcode_q),
 
 
    // Memory load result
    // Memory load result
    .mem_result_i(mem_result_i),
    .mem_result_i(mem_result_i),
    .mem_offset_i(mem_offset_i),
    .mem_offset_i(mem_offset_q),
 
 
    // Result
    // Result
    .load_result_o(load_result_w),
    .load_result_o(load_result_w),
    .load_insn_o(load_inst_w)
    .load_insn_o(load_inst_w)
);
);
 
 
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Assignments
// Writeback
//-------------------------------------------------------------------
//-------------------------------------------------------------------
assign write_enable_o = load_inst_w ? (write_rd_q & mem_ready_i) : write_rd_q;
always @ *
assign write_data_o   = load_inst_w ? load_result_w : (mult_i ? mult_result_i : result_q);
begin
assign write_addr_o   = rd_q;
    write_addr_o = rd_q;
 
 
 
    // Load result
 
    if (load_inst_w)
 
    begin
 
        write_enable_o = write_rd_q & mem_ready_i;
 
        write_data_o   = load_result_w;
 
    end
 
    // Normal ALU instruction
 
    else
 
    begin
 
        write_enable_o = write_rd_q;
 
        write_data_o   = result_q;
 
    end
 
end
 
 
endmodule
endmodule
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.