| 1 |
209 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//
|
| 3 |
|
|
// Filename: zipmmu_tb.v
|
| 4 |
|
|
//
|
| 5 |
|
|
// Project: Zip CPU -- a small, lightweight, RISC CPU soft core
|
| 6 |
|
|
//
|
| 7 |
|
|
// Purpose: This is a test-bench wrapper for the MMU. It's used to
|
| 8 |
|
|
// test whether or not the MMU works independent of the ZipCPU
|
| 9 |
|
|
// itself. The rest of the test bench is a C++ Verilator-enabled program.
|
| 10 |
|
|
//
|
| 11 |
|
|
//
|
| 12 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
| 13 |
|
|
// Gisselquist Technology, LLC
|
| 14 |
|
|
//
|
| 15 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
|
|
//
|
| 17 |
|
|
// Copyright (C) 2015-2019, Gisselquist Technology, LLC
|
| 18 |
|
|
//
|
| 19 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
| 20 |
|
|
// modify it under the terms of the GNU General Public License as published
|
| 21 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
| 22 |
|
|
// your option) any later version.
|
| 23 |
|
|
//
|
| 24 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
| 25 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
| 26 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
| 27 |
|
|
// for more details.
|
| 28 |
|
|
//
|
| 29 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
| 30 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
| 31 |
|
|
//
|
| 32 |
|
|
//
|
| 33 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
| 34 |
|
|
//
|
| 35 |
|
|
//
|
| 36 |
|
|
module zipmmu_tb(i_clk, i_reset, i_ctrl_cyc_stb, i_wbm_cyc, i_wbm_stb, i_wb_we,
|
| 37 |
|
|
i_exe, i_wb_addr, i_wb_data, i_wb_sel, i_gie,
|
| 38 |
|
|
o_rtn_stall, o_rtn_ack, o_rtn_err,
|
| 39 |
|
|
o_rtn_miss, o_rtn_data);
|
| 40 |
|
|
parameter CPU_ADDRESS_WIDTH=30,
|
| 41 |
|
|
MEMORY_ADDRESS_WIDTH=15;
|
| 42 |
|
|
localparam AW= CPU_ADDRESS_WIDTH,
|
| 43 |
|
|
MAW= MEMORY_ADDRESS_WIDTH,
|
| 44 |
|
|
LGTBL = 6,
|
| 45 |
|
|
LGPGSZB=12;
|
| 46 |
|
|
input i_clk, i_reset;
|
| 47 |
|
|
//
|
| 48 |
|
|
input i_ctrl_cyc_stb;
|
| 49 |
|
|
//
|
| 50 |
|
|
input i_wbm_cyc, i_wbm_stb;
|
| 51 |
|
|
//
|
| 52 |
|
|
input i_exe;
|
| 53 |
|
|
input i_wb_we;
|
| 54 |
|
|
input [(32-3):0] i_wb_addr;
|
| 55 |
|
|
input [(32-1):0] i_wb_data;
|
| 56 |
|
|
input [(32/8-1):0] i_wb_sel;
|
| 57 |
|
|
input i_gie;
|
| 58 |
|
|
//
|
| 59 |
|
|
// Here's where we return information on either our slave/control bus
|
| 60 |
|
|
// or the memory bus we are controlled from. Note that we share these
|
| 61 |
|
|
// wires ...
|
| 62 |
|
|
output wire o_rtn_stall, o_rtn_ack, o_rtn_err, o_rtn_miss;
|
| 63 |
|
|
output wire [(32-1):0] o_rtn_data;
|
| 64 |
|
|
|
| 65 |
|
|
|
| 66 |
|
|
|
| 67 |
|
|
wire mem_cyc /* verilator public_flat */,
|
| 68 |
|
|
mem_stb /* verilator public_flat */,
|
| 69 |
|
|
mem_we /* verilator public_flat */,
|
| 70 |
|
|
mem_ack /* verilator public_flat */,
|
| 71 |
|
|
mem_stall /* verilator public_flat */;
|
| 72 |
|
|
wire [31:0] mem_idata /* verilator public_flat */,
|
| 73 |
|
|
mem_odata /* verilator public_flat */;
|
| 74 |
|
|
wire [(32/8-1):0] mem_sel;
|
| 75 |
|
|
wire [(CPU_ADDRESS_WIDTH-1):0] mem_addr /* verilator public_flat */;
|
| 76 |
|
|
reg mem_err /* verilator public_flat */;
|
| 77 |
|
|
|
| 78 |
|
|
wire mmus_ack, mmus_stall;
|
| 79 |
|
|
wire [31:0] mmus_data;
|
| 80 |
|
|
|
| 81 |
|
|
wire rtn_ack, rtn_stall;
|
| 82 |
|
|
wire [31:0] rtn_data;
|
| 83 |
|
|
|
| 84 |
|
|
wire ign_stb, ign_we, ign_cache;
|
| 85 |
|
|
wire [(32-LGPGSZB-1):0] ign_p;
|
| 86 |
|
|
wire [(32-LGPGSZB-1):0] ign_v;
|
| 87 |
|
|
|
| 88 |
|
|
//
|
| 89 |
|
|
// mut = Module Under Test
|
| 90 |
|
|
//
|
| 91 |
|
|
zipmmu #(.ADDRESS_WIDTH(CPU_ADDRESS_WIDTH),
|
| 92 |
|
|
.LGTBL(LGTBL),.PLGPGSZB(LGPGSZB))
|
| 93 |
|
|
mut(i_clk, i_reset,
|
| 94 |
|
|
// Slave access
|
| 95 |
|
|
i_ctrl_cyc_stb, i_wb_we, i_wb_addr[(LGTBL+1):0],
|
| 96 |
|
|
i_wb_data,
|
| 97 |
|
|
mmus_ack, mmus_stall, mmus_data,
|
| 98 |
|
|
i_wbm_cyc, i_wbm_stb, i_wb_we, i_exe,
|
| 99 |
|
|
i_wb_addr, i_wb_data, i_wb_sel, i_gie,
|
| 100 |
|
|
mem_cyc, mem_stb, mem_we, mem_addr, mem_idata, mem_sel,
|
| 101 |
|
|
mem_stall, (mem_ack)&&(!mem_err), mem_err, mem_odata,
|
| 102 |
|
|
rtn_stall, rtn_ack, o_rtn_err, o_rtn_miss,
|
| 103 |
|
|
rtn_data,
|
| 104 |
|
|
ign_stb, ign_we, ign_p, ign_v, ign_cache);
|
| 105 |
|
|
|
| 106 |
|
|
memdev #(MAW+2) ram(i_clk,
|
| 107 |
|
|
mem_cyc, mem_stb, mem_we, mem_addr[(MAW-1):0], mem_idata,
|
| 108 |
|
|
mem_sel,
|
| 109 |
|
|
mem_ack, mem_stall, mem_odata);
|
| 110 |
|
|
|
| 111 |
|
|
always@(posedge i_clk)
|
| 112 |
|
|
if (i_reset)
|
| 113 |
|
|
mem_err <= 1'b0;
|
| 114 |
|
|
else if (!mem_cyc)
|
| 115 |
|
|
mem_err <= 1'b0;
|
| 116 |
|
|
else
|
| 117 |
|
|
mem_err <= (mem_err)||((mem_stb)&&(mem_addr[(AW-1):MAW]
|
| 118 |
|
|
!= {{(AW-MAW-1){1'b0}}, 1'b1}));
|
| 119 |
|
|
|
| 120 |
|
|
|
| 121 |
|
|
assign o_rtn_stall = (i_wbm_cyc)&&(rtn_stall);
|
| 122 |
|
|
assign o_rtn_ack = (i_wbm_cyc)?(rtn_ack) :mmus_ack;
|
| 123 |
|
|
assign o_rtn_data = (i_wbm_cyc)?(rtn_data):mmus_data;
|
| 124 |
|
|
|
| 125 |
|
|
// Make Verilator happy
|
| 126 |
|
|
// verilator lint_on UNUSED
|
| 127 |
|
|
wire [2+(32-LGPGSZB)+(32-LGPGSZB)+1+1-1:0] unused;
|
| 128 |
|
|
assign unused = { ign_stb, ign_we, ign_p, ign_v, ign_cache, mmus_stall };
|
| 129 |
|
|
// verilator lint_off UNUSED
|
| 130 |
|
|
endmodule
|