1 |
38 |
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 Tecnology, 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 |
|
|
module zipbones(i_clk, i_rst,
|
35 |
|
|
// Wishbone master interface from the CPU
|
36 |
|
|
o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data,
|
37 |
|
|
i_wb_ack, i_wb_stall, i_wb_data, i_wb_err,
|
38 |
|
|
// Incoming interrupts
|
39 |
|
|
i_ext_int,
|
40 |
|
|
// Our one outgoing interrupt
|
41 |
|
|
o_ext_int,
|
42 |
|
|
// Wishbone slave interface for debugging purposes
|
43 |
|
|
i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr, i_dbg_data,
|
44 |
|
|
o_dbg_ack, o_dbg_stall, o_dbg_data);
|
45 |
48 |
dgisselq |
parameter RESET_ADDRESS=32'h0100000, ADDRESS_WIDTH=32,
|
46 |
|
|
LGICACHE=6, START_HALTED=1,
|
47 |
|
|
AW=ADDRESS_WIDTH;
|
48 |
38 |
dgisselq |
input i_clk, i_rst;
|
49 |
|
|
// Wishbone master
|
50 |
|
|
output wire o_wb_cyc, o_wb_stb, o_wb_we;
|
51 |
48 |
dgisselq |
output wire [(AW-1):0] o_wb_addr;
|
52 |
38 |
dgisselq |
output wire [31:0] o_wb_data;
|
53 |
|
|
input i_wb_ack, i_wb_stall;
|
54 |
|
|
input [31:0] i_wb_data;
|
55 |
|
|
input i_wb_err;
|
56 |
|
|
// Incoming interrupts
|
57 |
48 |
dgisselq |
input i_ext_int;
|
58 |
38 |
dgisselq |
// Outgoing interrupt
|
59 |
|
|
output wire o_ext_int;
|
60 |
|
|
// Wishbone slave
|
61 |
|
|
input i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr;
|
62 |
|
|
input [31:0] i_dbg_data;
|
63 |
|
|
output reg o_dbg_ack;
|
64 |
|
|
output wire o_dbg_stall;
|
65 |
|
|
output wire [31:0] o_dbg_data;
|
66 |
|
|
|
67 |
|
|
//
|
68 |
|
|
//
|
69 |
|
|
//
|
70 |
|
|
wire sys_cyc, sys_stb, sys_we;
|
71 |
|
|
wire [4:0] sys_addr;
|
72 |
48 |
dgisselq |
wire [(AW-1):0] cpu_addr;
|
73 |
38 |
dgisselq |
wire [31:0] sys_data;
|
74 |
|
|
wire sys_ack, sys_stall;
|
75 |
|
|
|
76 |
|
|
//
|
77 |
|
|
// The external debug interface
|
78 |
|
|
//
|
79 |
|
|
// We offer only a limited interface here, requiring a pre-register
|
80 |
|
|
// write to set the local address. This interface allows access to
|
81 |
|
|
// the Zip System on a debug basis only, and not to the rest of the
|
82 |
|
|
// wishbone bus. Further, to access these registers, the control
|
83 |
|
|
// register must first be accessed to both stop the CPU and to
|
84 |
|
|
// set the following address in question. Hence all accesses require
|
85 |
|
|
// two accesses: write the address to the control register (and halt
|
86 |
|
|
// the CPU if not halted), then read/write the data from the data
|
87 |
|
|
// register.
|
88 |
|
|
//
|
89 |
|
|
wire cpu_break, dbg_cmd_write;
|
90 |
|
|
reg cmd_reset, cmd_halt, cmd_step, cmd_clear_pf_cache;
|
91 |
|
|
reg [4:0] cmd_addr;
|
92 |
|
|
wire [1:0] cpu_dbg_cc;
|
93 |
|
|
assign dbg_cmd_write = (i_dbg_cyc)&&(i_dbg_stb)&&(i_dbg_we)&&(~i_dbg_addr);
|
94 |
|
|
//
|
95 |
|
|
initial cmd_reset = 1'b1;
|
96 |
|
|
always @(posedge i_clk)
|
97 |
|
|
cmd_reset <= ((dbg_cmd_write)&&(i_dbg_data[6]));
|
98 |
|
|
//
|
99 |
|
|
initial cmd_halt = 1'b1;
|
100 |
|
|
always @(posedge i_clk)
|
101 |
|
|
if (i_rst)
|
102 |
|
|
cmd_halt <= (START_HALTED == 1)? 1'b1 : 1'b0;
|
103 |
|
|
else if (dbg_cmd_write)
|
104 |
|
|
cmd_halt <= ((i_dbg_data[10])||(i_dbg_data[8]));
|
105 |
|
|
else if ((cmd_step)||(cpu_break))
|
106 |
|
|
cmd_halt <= 1'b1;
|
107 |
|
|
|
108 |
|
|
always @(posedge i_clk)
|
109 |
|
|
if (i_rst)
|
110 |
|
|
cmd_clear_pf_cache <= 1'b0;
|
111 |
|
|
else if (dbg_cmd_write)
|
112 |
|
|
cmd_clear_pf_cache <= i_dbg_data[11];
|
113 |
|
|
else
|
114 |
|
|
cmd_clear_pf_cache <= 1'b0;
|
115 |
|
|
//
|
116 |
|
|
initial cmd_step = 1'b0;
|
117 |
|
|
always @(posedge i_clk)
|
118 |
|
|
cmd_step <= (dbg_cmd_write)&&(i_dbg_data[8]);
|
119 |
|
|
//
|
120 |
|
|
always @(posedge i_clk)
|
121 |
|
|
if (dbg_cmd_write)
|
122 |
|
|
cmd_addr <= i_dbg_data[4:0];
|
123 |
|
|
|
124 |
|
|
wire cpu_reset;
|
125 |
|
|
assign cpu_reset = (cmd_reset)||(i_rst);
|
126 |
|
|
|
127 |
|
|
wire cpu_halt, cpu_dbg_stall;
|
128 |
|
|
assign cpu_halt = (i_rst)||((cmd_halt)&&(~cmd_step));
|
129 |
|
|
wire [31:0] pic_data;
|
130 |
|
|
wire [31:0] cmd_data;
|
131 |
|
|
// Values:
|
132 |
|
|
// 0x0003f -> cmd_addr mask
|
133 |
|
|
// 0x00040 -> reset
|
134 |
|
|
// 0x00080 -> PIC interrrupts enabled
|
135 |
|
|
// 0x00100 -> cmd_step
|
136 |
|
|
// 0x00200 -> cmd_stall
|
137 |
|
|
// 0x00400 -> cmd_halt
|
138 |
|
|
// 0x00800 -> cmd_clear_pf_cache
|
139 |
|
|
// 0x01000 -> cc.sleep
|
140 |
|
|
// 0x02000 -> cc.gie
|
141 |
|
|
// 0x10000 -> External interrupt line is high
|
142 |
48 |
dgisselq |
assign cmd_data = { 7'h00, 8'h00, i_ext_int,
|
143 |
38 |
dgisselq |
2'b00, cpu_dbg_cc,
|
144 |
|
|
1'b0, cmd_halt, (~cpu_dbg_stall), 1'b0,
|
145 |
|
|
pic_data[15], cpu_reset, 1'b0, cmd_addr };
|
146 |
|
|
wire cpu_gie;
|
147 |
|
|
assign cpu_gie = cpu_dbg_cc[1];
|
148 |
|
|
|
149 |
|
|
//
|
150 |
|
|
// The CPU itself
|
151 |
|
|
//
|
152 |
|
|
wire cpu_gbl_stb, cpu_lcl_cyc, cpu_lcl_stb,
|
153 |
|
|
cpu_we, cpu_dbg_we,
|
154 |
|
|
cpu_op_stall, cpu_pf_stall, cpu_i_count;
|
155 |
|
|
wire [31:0] cpu_data, wb_data;
|
156 |
|
|
wire cpu_ack, cpu_stall, cpu_err;
|
157 |
|
|
wire [31:0] cpu_dbg_data;
|
158 |
|
|
assign cpu_dbg_we = ((i_dbg_cyc)&&(i_dbg_stb)
|
159 |
|
|
&&(i_dbg_we)&&(i_dbg_addr));
|
160 |
48 |
dgisselq |
zipcpu #(RESET_ADDRESS,ADDRESS_WIDTH,LGICACHE)
|
161 |
|
|
thecpu(i_clk, cpu_reset, i_ext_int,
|
162 |
38 |
dgisselq |
cpu_halt, cmd_clear_pf_cache, cmd_addr[4:0], cpu_dbg_we,
|
163 |
|
|
i_dbg_data, cpu_dbg_stall, cpu_dbg_data,
|
164 |
|
|
cpu_dbg_cc, cpu_break,
|
165 |
|
|
o_wb_cyc, o_wb_stb,
|
166 |
|
|
cpu_lcl_cyc, cpu_lcl_stb,
|
167 |
|
|
o_wb_we, o_wb_addr, o_wb_data,
|
168 |
|
|
i_wb_ack, i_wb_stall, wb_data,
|
169 |
|
|
i_wb_err,
|
170 |
|
|
cpu_op_stall, cpu_pf_stall, cpu_i_count);
|
171 |
|
|
|
172 |
|
|
// Return debug response values
|
173 |
|
|
assign o_dbg_data = (~i_dbg_addr)?cmd_data :cpu_dbg_data;
|
174 |
|
|
initial o_dbg_ack = 1'b0;
|
175 |
|
|
always @(posedge i_clk)
|
176 |
|
|
o_dbg_ack <= (i_dbg_cyc)&&((~i_dbg_addr)||(~o_dbg_stall));
|
177 |
|
|
assign o_dbg_stall=(i_dbg_cyc)&&(cpu_dbg_stall)&&(i_dbg_addr);
|
178 |
|
|
|
179 |
|
|
assign o_ext_int = (cmd_halt) && (~cpu_stall);
|
180 |
|
|
|
181 |
|
|
endmodule
|