| 1 |
3 |
dgisselq |
///////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//
|
| 3 |
|
|
// Filename: zipbones.v
|
| 4 |
|
|
//
|
| 5 |
|
|
// Project: Zip CPU -- a small, lightweight, RISC CPU soft core
|
| 6 |
|
|
//
|
| 7 |
|
|
// Purpose: In the spirit of keeping the Zip CPU small, this implements a
|
| 8 |
|
|
// Zip System with no peripherals: Any peripherals you wish will
|
| 9 |
|
|
// need to be implemented off-module.
|
| 10 |
|
|
//
|
| 11 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
| 12 |
|
|
// Gisselquist Technology, LLC
|
| 13 |
|
|
//
|
| 14 |
|
|
///////////////////////////////////////////////////////////////////////////
|
| 15 |
|
|
//
|
| 16 |
|
|
// Copyright (C) 2015, Gisselquist Technology, LLC
|
| 17 |
|
|
//
|
| 18 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
| 19 |
|
|
// modify it under the terms of the GNU General Public License as published
|
| 20 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
| 21 |
|
|
// your option) any later version.
|
| 22 |
|
|
//
|
| 23 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
| 24 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
| 25 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
| 26 |
|
|
// for more details.
|
| 27 |
|
|
//
|
| 28 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
| 29 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
| 30 |
|
|
//
|
| 31 |
|
|
//
|
| 32 |
|
|
///////////////////////////////////////////////////////////////////////////
|
| 33 |
|
|
//
|
| 34 |
|
|
`include "cpudefs.v"
|
| 35 |
|
|
//
|
| 36 |
|
|
module zipbones(i_clk, i_rst,
|
| 37 |
|
|
// Wishbone master interface from the CPU
|
| 38 |
|
|
o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data,
|
| 39 |
|
|
i_wb_ack, i_wb_stall, i_wb_data, i_wb_err,
|
| 40 |
|
|
// Incoming interrupts
|
| 41 |
|
|
i_ext_int,
|
| 42 |
|
|
// Our one outgoing interrupt
|
| 43 |
|
|
o_ext_int,
|
| 44 |
|
|
// Wishbone slave interface for debugging purposes
|
| 45 |
|
|
i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr, i_dbg_data,
|
| 46 |
|
|
o_dbg_ack, o_dbg_stall, o_dbg_data
|
| 47 |
|
|
`ifdef DEBUG_SCOPE
|
| 48 |
|
|
, o_zip_debug
|
| 49 |
|
|
`endif
|
| 50 |
|
|
);
|
| 51 |
|
|
parameter RESET_ADDRESS=32'h0100000, ADDRESS_WIDTH=32,
|
| 52 |
|
|
LGICACHE=6, START_HALTED=0,
|
| 53 |
|
|
AW=ADDRESS_WIDTH, HIGHSPEED_CPU=1;
|
| 54 |
|
|
input i_clk, i_rst;
|
| 55 |
|
|
// Wishbone master
|
| 56 |
|
|
output wire o_wb_cyc, o_wb_stb, o_wb_we;
|
| 57 |
|
|
output wire [(AW-1):0] o_wb_addr;
|
| 58 |
|
|
output wire [31:0] o_wb_data;
|
| 59 |
|
|
input i_wb_ack, i_wb_stall;
|
| 60 |
|
|
input [31:0] i_wb_data;
|
| 61 |
|
|
input i_wb_err;
|
| 62 |
|
|
// Incoming interrupts
|
| 63 |
|
|
input i_ext_int;
|
| 64 |
|
|
// Outgoing interrupt
|
| 65 |
|
|
output wire o_ext_int;
|
| 66 |
|
|
// Wishbone slave
|
| 67 |
|
|
input i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr;
|
| 68 |
|
|
input [31:0] i_dbg_data;
|
| 69 |
|
|
output reg o_dbg_ack;
|
| 70 |
|
|
output wire o_dbg_stall;
|
| 71 |
|
|
output wire [31:0] o_dbg_data;
|
| 72 |
|
|
//
|
| 73 |
|
|
`ifdef DEBUG_SCOPE
|
| 74 |
|
|
output wire [31:0] o_zip_debug;
|
| 75 |
|
|
`endif
|
| 76 |
|
|
|
| 77 |
|
|
//
|
| 78 |
|
|
//
|
| 79 |
|
|
//
|
| 80 |
|
|
wire sys_cyc, sys_stb, sys_we;
|
| 81 |
|
|
wire [4:0] sys_addr;
|
| 82 |
|
|
wire [(AW-1):0] cpu_addr;
|
| 83 |
|
|
wire [31:0] sys_data;
|
| 84 |
|
|
wire sys_ack, sys_stall;
|
| 85 |
|
|
|
| 86 |
|
|
//
|
| 87 |
|
|
// The external debug interface
|
| 88 |
|
|
//
|
| 89 |
|
|
// We offer only a limited interface here, requiring a pre-register
|
| 90 |
|
|
// write to set the local address. This interface allows access to
|
| 91 |
|
|
// the Zip System on a debug basis only, and not to the rest of the
|
| 92 |
|
|
// wishbone bus. Further, to access these registers, the control
|
| 93 |
|
|
// register must first be accessed to both stop the CPU and to
|
| 94 |
|
|
// set the following address in question. Hence all accesses require
|
| 95 |
|
|
// two accesses: write the address to the control register (and halt
|
| 96 |
|
|
// the CPU if not halted), then read/write the data from the data
|
| 97 |
|
|
// register.
|
| 98 |
|
|
//
|
| 99 |
|
|
wire cpu_break, dbg_cmd_write;
|
| 100 |
|
|
reg cmd_reset, cmd_halt, cmd_step, cmd_clear_pf_cache;
|
| 101 |
|
|
reg [4:0] cmd_addr;
|
| 102 |
|
|
wire [3:0] cpu_dbg_cc;
|
| 103 |
|
|
assign dbg_cmd_write = (i_dbg_cyc)&&(i_dbg_stb)&&(i_dbg_we)&&(~i_dbg_addr);
|
| 104 |
|
|
//
|
| 105 |
|
|
// Always start us off with an initial reset
|
| 106 |
|
|
//
|
| 107 |
|
|
initial cmd_reset = 1'b1;
|
| 108 |
|
|
always @(posedge i_clk)
|
| 109 |
|
|
cmd_reset <= ((dbg_cmd_write)&&(i_dbg_data[6]));
|
| 110 |
|
|
//
|
| 111 |
|
|
initial cmd_halt = START_HALTED;
|
| 112 |
|
|
always @(posedge i_clk)
|
| 113 |
|
|
if (i_rst)
|
| 114 |
|
|
cmd_halt <= (START_HALTED == 1)? 1'b1 : 1'b0;
|
| 115 |
|
|
else if (dbg_cmd_write)
|
| 116 |
|
|
cmd_halt <= ((i_dbg_data[10])||(i_dbg_data[8]));
|
| 117 |
|
|
else if ((cmd_step)||(cpu_break))
|
| 118 |
|
|
cmd_halt <= 1'b1;
|
| 119 |
|
|
|
| 120 |
|
|
initial cmd_clear_pf_cache = 1'b0;
|
| 121 |
|
|
always @(posedge i_clk)
|
| 122 |
|
|
if (i_rst)
|
| 123 |
|
|
cmd_clear_pf_cache <= 1'b0;
|
| 124 |
|
|
else if (dbg_cmd_write)
|
| 125 |
|
|
cmd_clear_pf_cache <= i_dbg_data[11];
|
| 126 |
|
|
else
|
| 127 |
|
|
cmd_clear_pf_cache <= 1'b0;
|
| 128 |
|
|
//
|
| 129 |
|
|
initial cmd_step = 1'b0;
|
| 130 |
|
|
always @(posedge i_clk)
|
| 131 |
|
|
cmd_step <= (dbg_cmd_write)&&(i_dbg_data[8]);
|
| 132 |
|
|
//
|
| 133 |
|
|
initial cmd_addr = 5'h0;
|
| 134 |
|
|
always @(posedge i_clk)
|
| 135 |
|
|
if (dbg_cmd_write)
|
| 136 |
|
|
cmd_addr <= i_dbg_data[4:0];
|
| 137 |
|
|
|
| 138 |
|
|
wire cpu_reset;
|
| 139 |
|
|
assign cpu_reset = (cmd_reset)||(i_rst);
|
| 140 |
|
|
|
| 141 |
|
|
wire cpu_halt, cpu_dbg_stall;
|
| 142 |
|
|
assign cpu_halt = (i_rst)||((cmd_halt)&&(~cmd_step));
|
| 143 |
|
|
wire [31:0] cmd_data;
|
| 144 |
|
|
// Values:
|
| 145 |
|
|
// 0x0003f -> cmd_addr mask
|
| 146 |
|
|
// 0x00040 -> reset
|
| 147 |
|
|
// 0x00080 -> PIC interrrupts enabled
|
| 148 |
|
|
// 0x00100 -> cmd_step
|
| 149 |
|
|
// 0x00200 -> cmd_stall
|
| 150 |
|
|
// 0x00400 -> cmd_halt
|
| 151 |
|
|
// 0x00800 -> cmd_clear_pf_cache
|
| 152 |
|
|
// 0x01000 -> cc.sleep
|
| 153 |
|
|
// 0x02000 -> cc.gie
|
| 154 |
|
|
// 0x10000 -> External interrupt line is high
|
| 155 |
|
|
assign cmd_data = { 7'h00, 8'h00, i_ext_int,
|
| 156 |
|
|
cpu_dbg_cc,
|
| 157 |
|
|
1'b0, cmd_halt, (~cpu_dbg_stall), 1'b0,
|
| 158 |
|
|
1'b0, cpu_reset, 1'b0, cmd_addr };
|
| 159 |
|
|
|
| 160 |
|
|
//
|
| 161 |
|
|
// The CPU itself
|
| 162 |
|
|
//
|
| 163 |
|
|
wire cpu_gbl_stb, cpu_lcl_cyc, cpu_lcl_stb,
|
| 164 |
|
|
cpu_we, cpu_dbg_we,
|
| 165 |
|
|
cpu_op_stall, cpu_pf_stall, cpu_i_count;
|
| 166 |
|
|
wire [31:0] cpu_data;
|
| 167 |
|
|
wire [31:0] cpu_dbg_data;
|
| 168 |
|
|
assign cpu_dbg_we = ((i_dbg_cyc)&&(i_dbg_stb)
|
| 169 |
|
|
&&(i_dbg_we)&&(i_dbg_addr));
|
| 170 |
|
|
generate
|
| 171 |
|
|
if (HIGHSPEED_CPU==0)
|
| 172 |
|
|
begin
|
| 173 |
|
|
zipcpu #(RESET_ADDRESS,ADDRESS_WIDTH,LGICACHE)
|
| 174 |
|
|
thecpu(i_clk, cpu_reset, i_ext_int,
|
| 175 |
|
|
cpu_halt, cmd_clear_pf_cache, cmd_addr[4:0], cpu_dbg_we,
|
| 176 |
|
|
i_dbg_data, cpu_dbg_stall, cpu_dbg_data,
|
| 177 |
|
|
cpu_dbg_cc, cpu_break,
|
| 178 |
|
|
o_wb_cyc, o_wb_stb,
|
| 179 |
|
|
cpu_lcl_cyc, cpu_lcl_stb,
|
| 180 |
|
|
o_wb_we, o_wb_addr, o_wb_data,
|
| 181 |
|
|
i_wb_ack, i_wb_stall, i_wb_data,
|
| 182 |
|
|
(i_wb_err)||((cpu_lcl_cyc)&&(cpu_lcl_stb)),
|
| 183 |
|
|
cpu_op_stall, cpu_pf_stall, cpu_i_count
|
| 184 |
|
|
`ifdef DEBUG_SCOPE
|
| 185 |
|
|
, o_zip_debug
|
| 186 |
|
|
`endif
|
| 187 |
|
|
);
|
| 188 |
|
|
end else begin
|
| 189 |
|
|
zipcpuhs #(RESET_ADDRESS,ADDRESS_WIDTH,LGICACHE)
|
| 190 |
|
|
thecpu(i_clk, cpu_reset, i_ext_int,
|
| 191 |
|
|
cpu_halt, cmd_clear_pf_cache, cmd_addr[4:0], cpu_dbg_we,
|
| 192 |
|
|
i_dbg_data, cpu_dbg_stall, cpu_dbg_data,
|
| 193 |
|
|
cpu_dbg_cc, cpu_break,
|
| 194 |
|
|
o_wb_cyc, o_wb_stb,
|
| 195 |
|
|
cpu_lcl_cyc, cpu_lcl_stb,
|
| 196 |
|
|
o_wb_we, o_wb_addr, o_wb_data,
|
| 197 |
|
|
i_wb_ack, i_wb_stall, i_wb_data,
|
| 198 |
|
|
(i_wb_err)||((cpu_lcl_cyc)&&(cpu_lcl_stb)),
|
| 199 |
|
|
cpu_op_stall, cpu_pf_stall, cpu_i_count
|
| 200 |
|
|
`ifdef DEBUG_SCOPE
|
| 201 |
|
|
, o_zip_debug
|
| 202 |
|
|
`endif
|
| 203 |
|
|
);
|
| 204 |
|
|
end endgenerate
|
| 205 |
|
|
|
| 206 |
|
|
// Return debug response values
|
| 207 |
|
|
assign o_dbg_data = (~i_dbg_addr)?cmd_data :cpu_dbg_data;
|
| 208 |
|
|
initial o_dbg_ack = 1'b0;
|
| 209 |
|
|
always @(posedge i_clk)
|
| 210 |
|
|
o_dbg_ack <= (i_dbg_cyc)&&((~i_dbg_addr)||(~o_dbg_stall));
|
| 211 |
|
|
assign o_dbg_stall=(i_dbg_cyc)&&(cpu_dbg_stall)&&(i_dbg_addr);
|
| 212 |
|
|
|
| 213 |
|
|
assign o_ext_int = (cmd_halt) && (~i_wb_stall);
|
| 214 |
|
|
|
| 215 |
|
|
endmodule
|