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

Subversion Repositories altor32

[/] [altor32/] [trunk/] [rtl/] [cpu/] [altor32_lsu.v] - Blame information for rev 37

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
// Module: Load / Store Unit
40
//-----------------------------------------------------------------
41
module altor32_lsu
42
(
43
    // Current instruction
44
    input               opcode_valid_i /*verilator public*/,
45
    input [7:0]         opcode_i /*verilator public*/,
46
 
47
    // Load / Store pending
48
    input               load_pending_i /*verilator public*/,
49
    input               store_pending_i /*verilator public*/,
50
 
51
    // Load dest register
52
    input [4:0]         rd_load_i /*verilator public*/,
53
 
54
    // Load insn in WB stage
55
    input               load_wb_i /*verilator public*/,
56
 
57
    // Memory status
58
    input               mem_access_i /*verilator public*/,
59
    input               mem_ack_i /*verilator public*/,
60
 
61
    // Load / store still pending
62
    output reg          load_pending_o /*verilator public*/,
63
    output reg          store_pending_o /*verilator public*/,
64
 
65
    // Insert load result into pipeline
66
    output reg          write_result_o /*verilator public*/,
67
 
68
    // Stall pipeline due load / store / insert
69
    output reg          stall_o /*verilator public*/
70
);
71
 
72 36 ultra_embe
//-----------------------------------------------------------------
73
// Includes
74
//-----------------------------------------------------------------
75
`include "altor32_defs.v"
76
`include "altor32_funcs.v"
77
 
78 27 ultra_embe
//-------------------------------------------------------------------
79
// Outstanding memory access logic
80
//-------------------------------------------------------------------
81 37 ultra_embe
reg inst_load_r;
82
reg inst_store_r;
83 27 ultra_embe
 
84
always @ *
85
begin
86
 
87
    load_pending_o   = load_pending_i;
88
    store_pending_o  = store_pending_i;
89
    stall_o          = 1'b0;
90
    write_result_o   = 1'b0;
91
 
92
    // Is this instruction a load or store?
93 37 ultra_embe
    inst_load_r     = is_load_operation(opcode_i);
94
    inst_store_r    = is_store_operation(opcode_i);
95 27 ultra_embe
 
96
    // Store operation just completed?
97
    if (store_pending_o & mem_ack_i & ~mem_access_i)
98
    begin
99
    `ifdef CONF_CORE_DEBUG
100
        $display("   Store operation now completed");
101
    `endif
102
        store_pending_o = 1'b0;
103
    end
104
 
105
    // Load just completed (and result ready in-time for writeback stage)?
106
    if (load_pending_o & mem_ack_i & ~mem_access_i & load_wb_i)
107
    begin
108
        // Load complete
109
        load_pending_o       = 1'b0;
110
 
111
    `ifdef CONF_CORE_DEBUG
112
        $display("   Load operation completed in writeback stage");
113
    `endif
114
    end
115
    // Load just completed (later than writeback stage)?
116
    else if (load_pending_o & mem_ack_i & ~mem_access_i)
117
    begin
118
    `ifdef CONF_CORE_DEBUG
119
        $display("   Load operation completed later than writeback stage");
120
    `endif
121
 
122
        // Valid target register?
123
        if (rd_load_i != 5'b00000)
124
        begin
125
    `ifdef CONF_CORE_DEBUG
126
            $display("   Load result now ready for R%d", rd_load_i);
127
    `endif
128
            // Stall instruction and write load result to pipeline
129
            stall_o         = opcode_valid_i;
130
            write_result_o  = 1'b1;
131
        end
132
        else
133
        begin
134
    `ifdef CONF_CORE_DEBUG
135
            $display("   Load result ready but not needed");
136
    `endif
137
        end
138
 
139
        // Load complete
140
        load_pending_o       = 1'b0;
141
    end
142
 
143
    // If load or store in progress (and this instruction is valid)
144
    if ((load_pending_o | store_pending_o) & opcode_valid_i)
145
    begin
146
        // Load or store whilst memory bus busy
147 37 ultra_embe
        if (inst_load_r | inst_store_r)
148 27 ultra_embe
        begin
149
    `ifdef CONF_CORE_DEBUG
150
            $display("   Data bus already busy, stall (load_pending_o=%d, store_pending_o=%d)",  load_pending_o, store_pending_o);
151
    `endif
152
            // Stall!
153
            stall_o         = 1'b1;
154
        end
155
    end
156
end
157
 
158
endmodule

powered by: WebSVN 2.1.0

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