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