OpenCores
URL https://opencores.org/ocsvn/zipcpu/zipcpu/trunk

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [rtl/] [zipbones.v] - Blame information for rev 101

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.