| 1 |
2 |
tobil |
//////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//// ////
|
| 3 |
|
|
//// OR1200's Load/Store unit ////
|
| 4 |
|
|
//// ////
|
| 5 |
|
|
//// This file is part of the OpenRISC 1200 project ////
|
| 6 |
|
|
//// http://www.opencores.org/cores/or1k/ ////
|
| 7 |
|
|
//// ////
|
| 8 |
|
|
//// Description ////
|
| 9 |
|
|
//// Interface between CPU and DC. ////
|
| 10 |
|
|
//// ////
|
| 11 |
|
|
//// To Do: ////
|
| 12 |
|
|
//// - make it smaller and faster ////
|
| 13 |
|
|
//// ////
|
| 14 |
|
|
//// Author(s): ////
|
| 15 |
|
|
//// - Damjan Lampret, lampret@opencores.org ////
|
| 16 |
|
|
//// ////
|
| 17 |
|
|
//////////////////////////////////////////////////////////////////////
|
| 18 |
|
|
//// ////
|
| 19 |
|
|
//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
|
| 20 |
|
|
//// ////
|
| 21 |
|
|
//// This source file may be used and distributed without ////
|
| 22 |
|
|
//// restriction provided that this copyright statement is not ////
|
| 23 |
|
|
//// removed from the file and that any derivative work contains ////
|
| 24 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
| 25 |
|
|
//// ////
|
| 26 |
|
|
//// This source file is free software; you can redistribute it ////
|
| 27 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
| 28 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
| 29 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
| 30 |
|
|
//// later version. ////
|
| 31 |
|
|
//// ////
|
| 32 |
|
|
//// This source is distributed in the hope that it will be ////
|
| 33 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
| 34 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
| 35 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
| 36 |
|
|
//// details. ////
|
| 37 |
|
|
//// ////
|
| 38 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
| 39 |
|
|
//// Public License along with this source; if not, download it ////
|
| 40 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
| 41 |
|
|
//// ////
|
| 42 |
|
|
//////////////////////////////////////////////////////////////////////
|
| 43 |
|
|
//
|
| 44 |
|
|
// CVS Revision History
|
| 45 |
|
|
//
|
| 46 |
|
|
// $Log: not supported by cvs2svn $
|
| 47 |
|
|
// Revision 1.4 2002/03/29 15:16:56 lampret
|
| 48 |
|
|
// Some of the warnings fixed.
|
| 49 |
|
|
//
|
| 50 |
|
|
// Revision 1.3 2002/02/11 04:33:17 lampret
|
| 51 |
|
|
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
|
| 52 |
|
|
//
|
| 53 |
|
|
// Revision 1.2 2002/01/18 07:56:00 lampret
|
| 54 |
|
|
// No more low/high priority interrupts (PICPR removed). Added tick timer exception. Added exception prefix (SR[EPH]). Fixed single-step bug whenreading NPC.
|
| 55 |
|
|
//
|
| 56 |
|
|
// Revision 1.1 2002/01/03 08:16:15 lampret
|
| 57 |
|
|
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
|
| 58 |
|
|
//
|
| 59 |
|
|
// Revision 1.9 2001/11/30 18:59:47 simons
|
| 60 |
|
|
// *** empty log message ***
|
| 61 |
|
|
//
|
| 62 |
|
|
// Revision 1.8 2001/10/21 17:57:16 lampret
|
| 63 |
|
|
// Removed params from generic_XX.v. Added translate_off/on in sprs.v and id.v. Removed spr_addr from dc.v and ic.v. Fixed CR+LF.
|
| 64 |
|
|
//
|
| 65 |
|
|
// Revision 1.7 2001/10/14 13:12:09 lampret
|
| 66 |
|
|
// MP3 version.
|
| 67 |
|
|
//
|
| 68 |
|
|
// Revision 1.1.1.1 2001/10/06 10:18:36 igorm
|
| 69 |
|
|
// no message
|
| 70 |
|
|
//
|
| 71 |
|
|
// Revision 1.2 2001/08/09 13:39:33 lampret
|
| 72 |
|
|
// Major clean-up.
|
| 73 |
|
|
//
|
| 74 |
|
|
// Revision 1.1 2001/07/20 00:46:03 lampret
|
| 75 |
|
|
// Development version of RTL. Libraries are missing.
|
| 76 |
|
|
//
|
| 77 |
|
|
//
|
| 78 |
|
|
|
| 79 |
|
|
// synopsys translate_off
|
| 80 |
|
|
`include "timescale.v"
|
| 81 |
|
|
// synopsys translate_on
|
| 82 |
|
|
`include "or1200_defines.v"
|
| 83 |
|
|
|
| 84 |
|
|
module or1200_lsu_cm3(
|
| 85 |
|
|
clk_i_cml_1,
|
| 86 |
|
|
clk_i_cml_2,
|
| 87 |
|
|
|
| 88 |
|
|
|
| 89 |
|
|
// Internal i/f
|
| 90 |
|
|
addrbase, addrofs, lsu_op, lsu_datain, lsu_dataout, lsu_stall, lsu_unstall,
|
| 91 |
|
|
du_stall, except_align, except_dtlbmiss, except_dmmufault, except_dbuserr,
|
| 92 |
|
|
|
| 93 |
|
|
// External i/f to DC
|
| 94 |
|
|
dcpu_adr_o, dcpu_cycstb_o, dcpu_we_o, dcpu_sel_o, dcpu_tag_o, dcpu_dat_o,
|
| 95 |
|
|
dcpu_dat_i, dcpu_ack_i, dcpu_rty_i, dcpu_err_i, dcpu_tag_i
|
| 96 |
|
|
);
|
| 97 |
|
|
|
| 98 |
|
|
|
| 99 |
|
|
input clk_i_cml_1;
|
| 100 |
|
|
input clk_i_cml_2;
|
| 101 |
|
|
reg [ 4 - 1 : 0 ] lsu_op_cml_2;
|
| 102 |
|
|
reg [ 4 - 1 : 0 ] lsu_op_cml_1;
|
| 103 |
|
|
reg except_align_cml_1;
|
| 104 |
|
|
reg [ 31 : 0 ] dcpu_adr_o_cml_2;
|
| 105 |
|
|
reg [ 31 : 0 ] dcpu_adr_o_cml_1;
|
| 106 |
|
|
|
| 107 |
|
|
|
| 108 |
|
|
|
| 109 |
|
|
parameter dw = `OR1200_OPERAND_WIDTH;
|
| 110 |
|
|
parameter aw = `OR1200_REGFILE_ADDR_WIDTH;
|
| 111 |
|
|
|
| 112 |
|
|
//
|
| 113 |
|
|
// I/O
|
| 114 |
|
|
//
|
| 115 |
|
|
|
| 116 |
|
|
//
|
| 117 |
|
|
// Internal i/f
|
| 118 |
|
|
//
|
| 119 |
|
|
input [31:0] addrbase;
|
| 120 |
|
|
input [31:0] addrofs;
|
| 121 |
|
|
input [`OR1200_LSUOP_WIDTH-1:0] lsu_op;
|
| 122 |
|
|
input [dw-1:0] lsu_datain;
|
| 123 |
|
|
output [dw-1:0] lsu_dataout;
|
| 124 |
|
|
output lsu_stall;
|
| 125 |
|
|
output lsu_unstall;
|
| 126 |
|
|
input du_stall;
|
| 127 |
|
|
output except_align;
|
| 128 |
|
|
output except_dtlbmiss;
|
| 129 |
|
|
output except_dmmufault;
|
| 130 |
|
|
output except_dbuserr;
|
| 131 |
|
|
|
| 132 |
|
|
//
|
| 133 |
|
|
// External i/f to DC
|
| 134 |
|
|
//
|
| 135 |
|
|
output [31:0] dcpu_adr_o;
|
| 136 |
|
|
output dcpu_cycstb_o;
|
| 137 |
|
|
output dcpu_we_o;
|
| 138 |
|
|
output [3:0] dcpu_sel_o;
|
| 139 |
|
|
output [3:0] dcpu_tag_o;
|
| 140 |
|
|
output [31:0] dcpu_dat_o;
|
| 141 |
|
|
input [31:0] dcpu_dat_i;
|
| 142 |
|
|
input dcpu_ack_i;
|
| 143 |
|
|
input dcpu_rty_i;
|
| 144 |
|
|
input dcpu_err_i;
|
| 145 |
|
|
input [3:0] dcpu_tag_i;
|
| 146 |
|
|
|
| 147 |
|
|
//
|
| 148 |
|
|
// Internal wires/regs
|
| 149 |
|
|
//
|
| 150 |
|
|
reg [3:0] dcpu_sel_o;
|
| 151 |
|
|
|
| 152 |
|
|
//
|
| 153 |
|
|
// Internal I/F assignments
|
| 154 |
|
|
//
|
| 155 |
|
|
assign lsu_stall = dcpu_rty_i & dcpu_cycstb_o;
|
| 156 |
|
|
assign lsu_unstall = dcpu_ack_i;
|
| 157 |
|
|
assign except_align = ((lsu_op == `OR1200_LSUOP_SH) | (lsu_op == `OR1200_LSUOP_LHZ) | (lsu_op == `OR1200_LSUOP_LHS)) & dcpu_adr_o[0]
|
| 158 |
|
|
| ((lsu_op == `OR1200_LSUOP_SW) | (lsu_op == `OR1200_LSUOP_LWZ) | (lsu_op == `OR1200_LSUOP_LWS)) & |dcpu_adr_o[1:0];
|
| 159 |
|
|
assign except_dtlbmiss = dcpu_err_i & (dcpu_tag_i == `OR1200_DTAG_TE);
|
| 160 |
|
|
assign except_dmmufault = dcpu_err_i & (dcpu_tag_i == `OR1200_DTAG_PE);
|
| 161 |
|
|
assign except_dbuserr = dcpu_err_i & (dcpu_tag_i == `OR1200_DTAG_BE);
|
| 162 |
|
|
|
| 163 |
|
|
//
|
| 164 |
|
|
// External I/F assignments
|
| 165 |
|
|
//
|
| 166 |
|
|
assign dcpu_adr_o = addrbase + addrofs;
|
| 167 |
|
|
|
| 168 |
|
|
// SynEDA CoreMultiplier
|
| 169 |
|
|
// assignment(s): dcpu_cycstb_o
|
| 170 |
|
|
// replace(s): lsu_op, except_align
|
| 171 |
|
|
assign dcpu_cycstb_o = du_stall | lsu_unstall | except_align_cml_1 ? 1'b0 : |lsu_op_cml_1;
|
| 172 |
|
|
|
| 173 |
|
|
// SynEDA CoreMultiplier
|
| 174 |
|
|
// assignment(s): dcpu_we_o
|
| 175 |
|
|
// replace(s): lsu_op
|
| 176 |
|
|
assign dcpu_we_o = lsu_op_cml_1[3];
|
| 177 |
|
|
assign dcpu_tag_o = dcpu_cycstb_o ? `OR1200_DTAG_ND : `OR1200_DTAG_IDLE;
|
| 178 |
|
|
|
| 179 |
|
|
// SynEDA CoreMultiplier
|
| 180 |
|
|
// assignment(s): dcpu_sel_o
|
| 181 |
|
|
// replace(s): lsu_op, dcpu_adr_o
|
| 182 |
|
|
always @(lsu_op_cml_2 or dcpu_adr_o_cml_2)
|
| 183 |
|
|
casex({lsu_op_cml_2, dcpu_adr_o_cml_2[1:0]})
|
| 184 |
|
|
{`OR1200_LSUOP_SB, 2'b00} : dcpu_sel_o = 4'b1000;
|
| 185 |
|
|
{`OR1200_LSUOP_SB, 2'b01} : dcpu_sel_o = 4'b0100;
|
| 186 |
|
|
{`OR1200_LSUOP_SB, 2'b10} : dcpu_sel_o = 4'b0010;
|
| 187 |
|
|
{`OR1200_LSUOP_SB, 2'b11} : dcpu_sel_o = 4'b0001;
|
| 188 |
|
|
{`OR1200_LSUOP_SH, 2'b00} : dcpu_sel_o = 4'b1100;
|
| 189 |
|
|
{`OR1200_LSUOP_SH, 2'b10} : dcpu_sel_o = 4'b0011;
|
| 190 |
|
|
{`OR1200_LSUOP_SW, 2'b00} : dcpu_sel_o = 4'b1111;
|
| 191 |
|
|
{`OR1200_LSUOP_LBZ, 2'b00}, {`OR1200_LSUOP_LBS, 2'b00} : dcpu_sel_o = 4'b1000;
|
| 192 |
|
|
{`OR1200_LSUOP_LBZ, 2'b01}, {`OR1200_LSUOP_LBS, 2'b01} : dcpu_sel_o = 4'b0100;
|
| 193 |
|
|
{`OR1200_LSUOP_LBZ, 2'b10}, {`OR1200_LSUOP_LBS, 2'b10} : dcpu_sel_o = 4'b0010;
|
| 194 |
|
|
{`OR1200_LSUOP_LBZ, 2'b11}, {`OR1200_LSUOP_LBS, 2'b11} : dcpu_sel_o = 4'b0001;
|
| 195 |
|
|
{`OR1200_LSUOP_LHZ, 2'b00}, {`OR1200_LSUOP_LHS, 2'b00} : dcpu_sel_o = 4'b1100;
|
| 196 |
|
|
{`OR1200_LSUOP_LHZ, 2'b10}, {`OR1200_LSUOP_LHS, 2'b10} : dcpu_sel_o = 4'b0011;
|
| 197 |
|
|
{`OR1200_LSUOP_LWZ, 2'b00}, {`OR1200_LSUOP_LWS, 2'b00} : dcpu_sel_o = 4'b1111;
|
| 198 |
|
|
default : dcpu_sel_o = 4'b0000;
|
| 199 |
|
|
endcase
|
| 200 |
|
|
|
| 201 |
|
|
//
|
| 202 |
|
|
// Instantiation of Memory-to-regfile aligner
|
| 203 |
|
|
//
|
| 204 |
|
|
wire [1:0] mem2reg_addr;
|
| 205 |
|
|
|
| 206 |
|
|
// SynEDA CoreMultiplier
|
| 207 |
|
|
// assignment(s): mem2reg_addr
|
| 208 |
|
|
// replace(s): dcpu_adr_o
|
| 209 |
|
|
assign mem2reg_addr = dcpu_adr_o_cml_1[1:0];
|
| 210 |
|
|
or1200_mem2reg_cm3 or1200_mem2reg(
|
| 211 |
|
|
.clk_i_cml_1(clk_i_cml_1),
|
| 212 |
|
|
.addr(mem2reg_addr),
|
| 213 |
|
|
.lsu_op(lsu_op),
|
| 214 |
|
|
.memdata(dcpu_dat_i),
|
| 215 |
|
|
.regdata(lsu_dataout)
|
| 216 |
|
|
);
|
| 217 |
|
|
|
| 218 |
|
|
//
|
| 219 |
|
|
// Instantiation of Regfile-to-memory aligner
|
| 220 |
|
|
//
|
| 221 |
|
|
or1200_reg2mem_cm3 or1200_reg2mem(
|
| 222 |
|
|
.clk_i_cml_1(clk_i_cml_1),
|
| 223 |
|
|
.clk_i_cml_2(clk_i_cml_2),
|
| 224 |
|
|
.addr(mem2reg_addr),
|
| 225 |
|
|
.lsu_op(lsu_op),
|
| 226 |
|
|
.regdata(lsu_datain),
|
| 227 |
|
|
.memdata(dcpu_dat_o)
|
| 228 |
|
|
);
|
| 229 |
|
|
|
| 230 |
|
|
|
| 231 |
|
|
always @ (posedge clk_i_cml_1) begin
|
| 232 |
|
|
lsu_op_cml_1 <= lsu_op;
|
| 233 |
|
|
except_align_cml_1 <= except_align;
|
| 234 |
|
|
dcpu_adr_o_cml_1 <= dcpu_adr_o;
|
| 235 |
|
|
end
|
| 236 |
|
|
always @ (posedge clk_i_cml_2) begin
|
| 237 |
|
|
lsu_op_cml_2 <= lsu_op_cml_1;
|
| 238 |
|
|
dcpu_adr_o_cml_2 <= dcpu_adr_o_cml_1;
|
| 239 |
|
|
end
|
| 240 |
|
|
endmodule
|
| 241 |
|
|
|