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

Subversion Repositories altor32

[/] [altor32/] [trunk/] [rtl/] [cpu/] [altor32_writeback.v] - Blame information for rev 38

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 ultra_embe
//-----------------------------------------------------------------
2
//                           AltOR32 
3
//                Alternative Lightweight OpenRisc 
4 36 ultra_embe
//                            V2.1
5 27 ultra_embe
//                     Ultra-Embedded.com
6 36 ultra_embe
//                   Copyright 2011 - 2014
7 27 ultra_embe
//
8
//               Email: admin@ultra-embedded.com
9
//
10
//                       License: LGPL
11
//-----------------------------------------------------------------
12
//
13 37 ultra_embe
// Copyright (C) 2011 - 2014 Ultra-Embedded.com
14 27 ultra_embe
//
15
// This source file may be used and distributed without         
16
// restriction provided that this copyright statement is not    
17
// removed from the file and that any derivative work contains  
18
// the original copyright notice and the associated disclaimer. 
19
//
20
// This source file is free software; you can redistribute it   
21
// and/or modify it under the terms of the GNU Lesser General   
22
// Public License as published by the Free Software Foundation; 
23
// either version 2.1 of the License, or (at your option) any   
24
// later version.
25
//
26
// This source is distributed in the hope that it will be       
27
// useful, but WITHOUT ANY WARRANTY; without even the implied   
28
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      
29
// PURPOSE.  See the GNU Lesser General Public License for more 
30
// details.
31
//
32
// You should have received a copy of the GNU Lesser General    
33
// Public License along with this source; if not, write to the 
34
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
35
// Boston, MA  02111-1307  USA
36
//-----------------------------------------------------------------
37
 
38
//-----------------------------------------------------------------
39
// Includes
40
//-----------------------------------------------------------------
41
`include "altor32_defs.v"
42
 
43
//-----------------------------------------------------------------
44
// Module - Writeback
45
//-----------------------------------------------------------------
46
module altor32_writeback
47
(
48
    // General
49
    input               clk_i /*verilator public*/,
50
    input               rst_i /*verilator public*/,
51
 
52
    // Opcode
53
    input [31:0]        opcode_i /*verilator public*/,
54
 
55
    // Register target
56
    input [4:0]         rd_i /*verilator public*/,
57
 
58
    // ALU result
59
    input [31:0]        alu_result_i /*verilator public*/,
60
 
61
    // Memory load result
62
    input [31:0]        mem_result_i /*verilator public*/,
63
    input [1:0]         mem_offset_i /*verilator public*/,
64
    input               mem_ready_i /*verilator public*/,
65
 
66
    // Multiplier result
67
    input               mult_i /*verilator public*/,
68
    input [31:0]        mult_result_i /*verilator public*/,
69
 
70
    // Outputs
71
    output              write_enable_o /*verilator public*/,
72
    output [4:0]        write_addr_o /*verilator public*/,
73
    output [31:0]       write_data_o /*verilator public*/
74
);
75
 
76
//-----------------------------------------------------------------
77
// Registers
78
//-----------------------------------------------------------------
79
 
80
// Register address
81 37 ultra_embe
reg [4:0]  rd_q;
82 27 ultra_embe
 
83
// Register writeback value
84 37 ultra_embe
reg [31:0] result_q;
85 27 ultra_embe
 
86 37 ultra_embe
reg [7:0]  opcode_q;
87 27 ultra_embe
 
88
// Register writeback enable
89 37 ultra_embe
reg        write_rd_q;
90 27 ultra_embe
 
91
//-------------------------------------------------------------------
92
// Writeback
93
//-------------------------------------------------------------------
94
always @ (posedge clk_i or posedge rst_i)
95
begin
96
   if (rst_i == 1'b1)
97
   begin
98 37 ultra_embe
       write_rd_q   <= 1'b1;
99
       result_q     <= 32'h00000000;
100
       rd_q         <= 5'b00000;
101
       opcode_q     <= 8'b0;
102 27 ultra_embe
   end
103
   else
104 37 ultra_embe
   begin
105
        rd_q        <= rd_i;
106
        result_q    <= alu_result_i;
107 27 ultra_embe
 
108 37 ultra_embe
        opcode_q    <= {2'b00,opcode_i[31:26]};
109 27 ultra_embe
 
110
        // Register writeback required?
111
        if (rd_i != 5'b00000)
112 37 ultra_embe
            write_rd_q  <= 1'b1;
113
        else
114
            write_rd_q  <= 1'b0;
115 27 ultra_embe
   end
116
end
117
 
118
//-------------------------------------------------------------------
119
// Load result resolve
120
//-------------------------------------------------------------------
121 37 ultra_embe
wire            load_inst_w;
122
wire [31:0]     load_result_w;
123 27 ultra_embe
 
124
altor32_lfu
125
u_lfu
126
(
127
    // Opcode
128 37 ultra_embe
    .opcode_i(opcode_q),
129 27 ultra_embe
 
130
    // Memory load result
131
    .mem_result_i(mem_result_i),
132
    .mem_offset_i(mem_offset_i),
133
 
134
    // Result
135 37 ultra_embe
    .load_result_o(load_result_w),
136
    .load_insn_o(load_inst_w)
137 27 ultra_embe
);
138
 
139
//-------------------------------------------------------------------
140
// Assignments
141
//-------------------------------------------------------------------
142 37 ultra_embe
assign write_enable_o = load_inst_w ? (write_rd_q & mem_ready_i) : write_rd_q;
143
assign write_data_o   = load_inst_w ? load_result_w : (mult_i ? mult_result_i : result_q);
144
assign write_addr_o   = rd_q;
145 27 ultra_embe
 
146
endmodule

powered by: WebSVN 2.1.0

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