1 |
72 |
dgisselq |
`define XULA25
|
2 |
2 |
dgisselq |
///////////////////////////////////////////////////////////////////////////////
|
3 |
|
|
//
|
4 |
|
|
// Filename: cpudefs.v
|
5 |
|
|
//
|
6 |
|
|
// Project: Zip CPU -- a small, lightweight, RISC CPU soft core
|
7 |
|
|
//
|
8 |
|
|
// Purpose: Some architectures have some needs, others have other needs.
|
9 |
|
|
// Some of my projects need a Zip CPU with pipelining, others
|
10 |
|
|
// can't handle the timing required to get the answer from the ALU
|
11 |
|
|
// back into the input for the ALU. As each different projects has
|
12 |
|
|
// different needs, I can either 1) reconfigure my entire baseline prior
|
13 |
|
|
// to building each project, or 2) host a configuration file which contains
|
14 |
|
|
// the information regarding each baseline. This file is that
|
15 |
|
|
// configuration file. It controls how the CPU (not the system,
|
16 |
|
|
// peripherals, or other) is defined and implemented. Several options
|
17 |
|
|
// are available within here, making the Zip CPU pipelined or not,
|
18 |
|
|
// able to handle a faster clock with more stalls or a slower clock with
|
19 |
|
|
// no stalls, etc.
|
20 |
|
|
//
|
21 |
|
|
// This file encapsulates those control options.
|
22 |
|
|
//
|
23 |
|
|
// The number of LUTs the Zip CPU uses varies dramatically with the
|
24 |
|
|
// options defined in this file.
|
25 |
|
|
//
|
26 |
|
|
//
|
27 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
28 |
|
|
// Gisselquist Technology, LLC
|
29 |
|
|
//
|
30 |
|
|
///////////////////////////////////////////////////////////////////////////////
|
31 |
|
|
//
|
32 |
118 |
dgisselq |
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
33 |
2 |
dgisselq |
//
|
34 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
35 |
|
|
// modify it under the terms of the GNU General Public License as published
|
36 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
37 |
|
|
// your option) any later version.
|
38 |
|
|
//
|
39 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
40 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
41 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
42 |
|
|
// for more details.
|
43 |
|
|
//
|
44 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
45 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
46 |
|
|
//
|
47 |
|
|
//
|
48 |
|
|
///////////////////////////////////////////////////////////////////////////////
|
49 |
|
|
`ifndef CPUDEFS_H
|
50 |
|
|
`define CPUDEFS_H
|
51 |
|
|
//
|
52 |
|
|
//
|
53 |
|
|
// The first couple options control the Zip CPU instruction set, and how
|
54 |
|
|
// it handles various instructions within the set:
|
55 |
|
|
//
|
56 |
|
|
//
|
57 |
|
|
// OPT_ILLEGAL_INSTRUCTION is part of a new section of code that is supposed
|
58 |
|
|
// to recognize illegal instructions and interrupt the CPU whenever one such
|
59 |
|
|
// instruction is encountered. The goal is to create a soft floating point
|
60 |
|
|
// unit via this approach, that can then be replaced with a true floating point
|
61 |
|
|
// unit. As I'm not there yet, it just catches illegal instructions and
|
62 |
|
|
// interrupts the CPU on any such instruction--when defined. Otherwise,
|
63 |
|
|
// illegal instructions are quietly ignored and their behaviour is ...
|
64 |
|
|
// undefined. (Many get treated like NOOPs ...)
|
65 |
|
|
//
|
66 |
117 |
dgisselq |
// I recommend setting this flag so highly, that I'm likely going to remove
|
67 |
|
|
// the option to turn this off in future versions of this CPU.
|
68 |
2 |
dgisselq |
//
|
69 |
|
|
`define OPT_ILLEGAL_INSTRUCTION
|
70 |
|
|
//
|
71 |
|
|
//
|
72 |
|
|
//
|
73 |
|
|
// OPT_MULTIPLY controls whether or not the multiply is built and included
|
74 |
|
|
// in the ALU by default. Set this option and a parameter will be set that
|
75 |
|
|
// includes the multiply. (This parameter may still be overridden, as with
|
76 |
|
|
// any parameter ...) If the multiply is not included and
|
77 |
|
|
// OPT_ILLEGAL_INSTRUCTION is set, then the multiply will create an illegal
|
78 |
|
|
// instruction that will then trip the illegal instruction trap.
|
79 |
|
|
//
|
80 |
118 |
dgisselq |
// Either not defining this value, or defining it to zero will disable the
|
81 |
|
|
// hardware multiply. A value of '1' will cause the multiply to occurr in one
|
82 |
|
|
// clock cycle only--often at the expense of the rest of the CPUs speed.
|
83 |
|
|
// A value of 2 will cause the multiply to have a single delay cycle, 3 will
|
84 |
|
|
// have two delay cycles, and 4 (or more) will have 3 delay cycles.
|
85 |
2 |
dgisselq |
//
|
86 |
118 |
dgisselq |
`define OPT_MULTIPLY 4
|
87 |
2 |
dgisselq |
//
|
88 |
|
|
//
|
89 |
|
|
//
|
90 |
|
|
// OPT_DIVIDE controls whether or not the divide instruction is built and
|
91 |
|
|
// included into the ZipCPU by default. Set this option and a parameter will
|
92 |
|
|
// be set that causes the divide unit to be included. (This parameter may
|
93 |
|
|
// still be overridden, as with any parameter ...) If the divide is not
|
94 |
|
|
// included and OPT_ILLEGAL_INSTRUCTION is set, then the multiply will create
|
95 |
|
|
// an illegal instruction exception that will send the CPU into supervisor
|
96 |
|
|
// mode.
|
97 |
|
|
//
|
98 |
|
|
//
|
99 |
31 |
dgisselq |
`ifdef XULA25
|
100 |
2 |
dgisselq |
`define OPT_DIVIDE
|
101 |
31 |
dgisselq |
`endif
|
102 |
2 |
dgisselq |
//
|
103 |
|
|
//
|
104 |
|
|
//
|
105 |
|
|
// OPT_IMPLEMENT_FPU will (one day) control whether or not the floating point
|
106 |
|
|
// unit (once I have one) is built and included into the ZipCPU by default.
|
107 |
|
|
// At that time, if this option is set then a parameter will be set that
|
108 |
|
|
// causes the floating point unit to be included. (This parameter may
|
109 |
|
|
// still be overridden, as with any parameter ...) If the floating point unit
|
110 |
|
|
// is not included and OPT_ILLEGAL_INSTRUCTION is set, then as with the
|
111 |
|
|
// multiply and divide any floating point instruction will result in an illegal
|
112 |
|
|
// instruction exception that will send the CPU into supervisor mode.
|
113 |
|
|
//
|
114 |
|
|
//
|
115 |
|
|
// `define OPT_IMPLEMENT_FPU
|
116 |
|
|
//
|
117 |
|
|
//
|
118 |
|
|
//
|
119 |
|
|
//
|
120 |
|
|
// OPT_SINGLE_FETCH controls whether or not the prefetch has a cache, and
|
121 |
|
|
// whether or not it can issue one instruction per clock. When set, the
|
122 |
|
|
// prefetch has no cache, and only one instruction is fetched at a time.
|
123 |
|
|
// This effectively sets the CPU so that only one instruction is ever
|
124 |
|
|
// in the pipeline at once, and hence you may think of this as a "kill
|
125 |
|
|
// pipeline" option. However, since the pipelined fetch component uses so
|
126 |
|
|
// much area on the FPGA, this is an important option to use in trimming down
|
127 |
|
|
// used area if necessary. Hence, it needs to be maintained for that purpose.
|
128 |
|
|
// Be aware, though, it will drop your performance by a factor between 2x and
|
129 |
|
|
// 3x.
|
130 |
|
|
//
|
131 |
|
|
// We can either pipeline our fetches, or issue one fetch at a time. Pipelined
|
132 |
|
|
// fetches are more complicated and therefore use more FPGA resources, while
|
133 |
|
|
// single fetches will cause the CPU to stall for about 5 stalls each
|
134 |
|
|
// instruction cycle, effectively reducing the instruction count per clock to
|
135 |
|
|
// about 0.2. However, the area cost may be worth it. Consider:
|
136 |
|
|
//
|
137 |
|
|
// Slice LUTs ZipSystem ZipCPU
|
138 |
|
|
// Single Fetching 2521 1734
|
139 |
|
|
// Pipelined fetching 2796 2046
|
140 |
|
|
// (These numbers may be dated, but should still be representative ...)
|
141 |
|
|
//
|
142 |
|
|
// I recommend only defining this if you "need" to, if area is tight and
|
143 |
|
|
// speed isn't as important. Otherwise, just leave this undefined.
|
144 |
|
|
//
|
145 |
|
|
// `define OPT_SINGLE_FETCH
|
146 |
|
|
//
|
147 |
|
|
//
|
148 |
|
|
//
|
149 |
|
|
// The next several options are pipeline optimization options. They make no
|
150 |
|
|
// sense in a single instruction fetch mode, hence we #ifndef them so they
|
151 |
|
|
// are only defined if we are in a full pipelined mode (i.e. OPT_SINGLE_FETCH
|
152 |
|
|
// is not defined).
|
153 |
|
|
//
|
154 |
|
|
`ifndef OPT_SINGLE_FETCH
|
155 |
|
|
//
|
156 |
|
|
//
|
157 |
|
|
//
|
158 |
|
|
// OPT_PIPELINED is the natural result and opposite of using the single
|
159 |
|
|
// instruction fetch unit. If you are not using that unit, the ZipCPU will
|
160 |
|
|
// be pipelined. The option is defined here more for readability than
|
161 |
|
|
// anything else, since OPT_PIPELINED makes more sense than OPT_SINGLE_FETCH,
|
162 |
|
|
// well ... that and it does a better job of explaining what is going on.
|
163 |
|
|
//
|
164 |
|
|
// In other words, leave this define alone--lest you break the ZipCPU.
|
165 |
|
|
//
|
166 |
|
|
`define OPT_PIPELINED
|
167 |
|
|
//
|
168 |
|
|
//
|
169 |
|
|
//
|
170 |
|
|
// OPT_TRADITIONAL_PFCACHE allows you to switch between one of two prefetch
|
171 |
|
|
// caches. If enabled, a more traditional cache is implemented. This more
|
172 |
|
|
// traditional cache (currently) uses many more LUTs, but it also reduces
|
173 |
|
|
// the stall count tremendously over the alternative hacked pipeline cache.
|
174 |
|
|
// (The traditional pfcache is also pipelined, whereas the pipeline cache
|
175 |
|
|
// implements a windowed approach to caching.)
|
176 |
|
|
//
|
177 |
|
|
// If you have the fabric to support this option, I recommend including it.
|
178 |
|
|
//
|
179 |
|
|
`define OPT_TRADITIONAL_PFCACHE
|
180 |
|
|
//
|
181 |
|
|
//
|
182 |
|
|
//
|
183 |
|
|
// OPT_EARLY_BRANCHING is an attempt to execute a BRA statement as early
|
184 |
|
|
// as possible, to avoid as many pipeline stalls on a branch as possible.
|
185 |
|
|
// It's not tremendously successful yet--BRA's still suffer stalls,
|
186 |
|
|
// but I intend to keep working on this approach until the number of stalls
|
187 |
|
|
// gets down to one or (ideally) zero. (With the OPT_TRADITIONAL_PFCACHE, this
|
188 |
|
|
// gets down to a single stall cycle ...) That way a "BRA" can be used as the
|
189 |
|
|
// compiler's branch prediction optimizer: BRA's barely stall, while branches
|
190 |
|
|
// on conditions will always suffer about 4 stall cycles or so.
|
191 |
|
|
//
|
192 |
|
|
// I recommend setting this flag, so as to turn early branching on.
|
193 |
|
|
//
|
194 |
|
|
`define OPT_EARLY_BRANCHING
|
195 |
|
|
//
|
196 |
|
|
//
|
197 |
|
|
//
|
198 |
|
|
// OPT_PIPELINED_BUS_ACCESS controls whether or not LOD/STO instructions
|
199 |
|
|
// can take advantaged of pipelined bus instructions. To be eligible, the
|
200 |
|
|
// operations must be identical (cannot pipeline loads and stores, just loads
|
201 |
|
|
// only or stores only), and the addresses must either be identical or one up
|
202 |
|
|
// from the previous address. Further, the load/store string must all have
|
203 |
|
|
// the same conditional. This approach gains the must use, in my humble
|
204 |
|
|
// opinion, when saving registers to or restoring registers from the stack
|
205 |
|
|
// at the beginning/end of a procedure, or when doing a context swap.
|
206 |
|
|
//
|
207 |
|
|
// I recommend setting this flag, for performance reasons, especially if your
|
208 |
|
|
// wishbone bus can handle pipelined bus accesses.
|
209 |
|
|
//
|
210 |
|
|
`define OPT_PIPELINED_BUS_ACCESS
|
211 |
|
|
//
|
212 |
|
|
//
|
213 |
|
|
//
|
214 |
|
|
//
|
215 |
|
|
//
|
216 |
|
|
// The new instruction set also defines a set of very long instruction words.
|
217 |
|
|
// Well, calling them "very long" instruction words is probably a misnomer,
|
218 |
|
|
// although we're going to do it. They're really 2x16-bit instructions---
|
219 |
|
|
// instruction words that pack two instructions into one word. (2x14 bit
|
220 |
|
|
// really--'cause you need a bit to note the instruction is a 2x instruction,
|
221 |
|
|
// and then 3-bits for the condition codes ...) Set OPT_VLIW to include these
|
222 |
|
|
// double instructions as part of the new instruction set. These allow a single
|
223 |
|
|
// instruction to contain two instructions within. These instructions are
|
224 |
|
|
// designed to get more code density from the instruction set, and to hopefully
|
225 |
|
|
// take some pain off of the performance of the pre-fetch and instruction cache.
|
226 |
|
|
//
|
227 |
|
|
// These new instructions, however, also necessitate a change in the Zip
|
228 |
|
|
// CPU--the Zip CPU can no longer execute instructions atomically. It must
|
229 |
|
|
// now execute non-VLIW instructions, or VLIW instruction pairs, atomically.
|
230 |
|
|
// This logic has been added into the ZipCPU, but it has not (yet) been
|
231 |
|
|
// tested thoroughly.
|
232 |
|
|
//
|
233 |
|
|
// Oh, and the assembler, the debugger, and the object file dumper, and the
|
234 |
|
|
// simulator all need to be updated as well ....
|
235 |
|
|
//
|
236 |
|
|
`define OPT_VLIW
|
237 |
|
|
//
|
238 |
|
|
//
|
239 |
|
|
//
|
240 |
|
|
`endif // OPT_SINGLE_FETCH
|
241 |
|
|
//
|
242 |
|
|
//
|
243 |
|
|
//
|
244 |
|
|
// Now let's talk about peripherals for a moment. These next two defines
|
245 |
|
|
// control whether the DMA controller is included in the Zip System, and
|
246 |
|
|
// whether or not the 8 accounting timers are also included. Set these to
|
247 |
|
|
// include the respective peripherals, comment them out not to.
|
248 |
|
|
//
|
249 |
31 |
dgisselq |
`ifdef XULA25
|
250 |
2 |
dgisselq |
`define INCLUDE_DMA_CONTROLLER
|
251 |
|
|
`define INCLUDE_ACCOUNTING_COUNTERS
|
252 |
|
|
//
|
253 |
|
|
//
|
254 |
|
|
`define DEBUG_SCOPE
|
255 |
113 |
dgisselq |
`else // XULA25
|
256 |
|
|
`ifdef VERILATOR
|
257 |
|
|
`define DEBUG_SCOPE
|
258 |
|
|
`endif // VERILATOR
|
259 |
|
|
`endif // XULA25
|
260 |
2 |
dgisselq |
//
|
261 |
|
|
`endif // CPUDEFS_H
|