1 |
2 |
mihal |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// //
|
3 |
|
|
// file name: memstate2.v //
|
4 |
|
|
// description: memory opertions for z80 //
|
5 |
|
|
// project: wb_z80 //
|
6 |
|
|
// //
|
7 |
|
|
// Author: B.J. Porcella //
|
8 |
|
|
// e-mail: bporcella@sbcglobal.net //
|
9 |
|
|
// //
|
10 |
|
|
// //
|
11 |
|
|
// //
|
12 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
13 |
|
|
// //
|
14 |
|
|
// Copyright (C) 2000-2002 B.J. Porcella //
|
15 |
|
|
// Real Time Solutions //
|
16 |
|
|
// //
|
17 |
|
|
// //
|
18 |
|
|
// This source file may be used and distributed without //
|
19 |
|
|
// restriction provided that this copyright statement is not //
|
20 |
|
|
// removed from the file and that any derivative work contains //
|
21 |
|
|
// the original copyright notice and the associated disclaimer. //
|
22 |
|
|
// //
|
23 |
|
|
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //
|
24 |
|
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //
|
25 |
|
|
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //
|
26 |
|
|
// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //
|
27 |
|
|
// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //
|
28 |
|
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //
|
29 |
|
|
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //
|
30 |
|
|
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //
|
31 |
|
|
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //
|
32 |
|
|
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //
|
33 |
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //
|
34 |
|
|
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //
|
35 |
|
|
// POSSIBILITY OF SUCH DAMAGE. //
|
36 |
|
|
// //
|
37 |
|
|
//-------1---------2---------3--------Comments on file -------------7---------8---------9--------0
|
38 |
|
|
// The memory state controller controls the wb bus, and provides address sequencing.
|
39 |
|
|
// Insructions are fetched in order (using PC) until the istate machine indicates that
|
40 |
|
|
// a complete instruction is in the first pipline stage (ir1). In general, operands are being
|
41 |
|
|
// fetched (stored) to satisfy ir1 while concurrently instructions are being executed from ir2.
|
42 |
|
|
// this situation can result in a number of potential hazards. As an example, if the ir2
|
43 |
|
|
// instruction changes the flag register and the ir1 instruction is a conditional jump,
|
44 |
|
|
// a hazard is generated by the hazard logic, and execution of the ir1 operation is delayed
|
45 |
|
|
// until the completion of the flag update.
|
46 |
|
|
//
|
47 |
|
|
// Reset starts execution at 0.
|
48 |
|
|
// The PC and SP are described in this file. modifications to other index registers -
|
49 |
|
|
// HL IX and IY are computed here --
|
50 |
|
|
// For the block moves address updates are computed here -- and commanded here.
|
51 |
|
|
// Strobes for the second address update are generally co-incident with count updates, but
|
52 |
|
|
// we provide seperate strobe update lines for clarity.
|
53 |
|
|
//
|
54 |
|
|
// BASIC ARCHITECTURE OF THIS FILE pc and sp not shown, but are inputs to src mux.
|
55 |
|
|
// _____ and may be updated from adder output.
|
56 |
|
|
// | |
|
57 |
|
|
// | | pc-1 register is required to implement relative jumps.
|
58 |
|
|
// | |
|
59 |
|
|
// _____ |lit | |\
|
60 |
|
|
// | | | | | \
|
61 |
|
|
// | | |src2 | | \ _____ _____
|
62 |
|
|
// | | | |----->| | | | | |
|
63 |
|
|
// |src | |_____| |adder|------->| | | |
|
64 |
|
|
// |mux | | | | | | |
|
65 |
|
|
// | |------------------->| / |2/1 |------->|wb |
|
66 |
|
|
// | | | | / |mux | |adr |
|
67 |
|
|
// |_____| | |/ | | | |
|
68 |
|
|
// ------------------->| | | |
|
69 |
|
|
// |_____| |_____|
|
70 |
|
|
//
|
71 |
|
|
//
|
72 |
|
|
//
|
73 |
|
|
//
|
74 |
|
|
// Operand Stores:
|
75 |
|
|
// At first cut, I thought I'ld execute operand stores immediately from the memory sequencer
|
76 |
|
|
// (essentially before ir2 got the store data). While this might be modestly faster in
|
77 |
|
|
// systems that take multiple clocks to complete a memory store, On consideration, I decided
|
78 |
|
|
// to forgo the extra speed for conceptual simplicity.... execute operand stores on op_ph1,
|
79 |
|
|
// and let the inst_exec engine suply the operand.
|
80 |
|
|
//
|
81 |
|
|
// On second thought, above is not only wastful of time, but also inconsistent with the overall
|
82 |
|
|
// schems of things - and so somewhat more complex. If we simply execute the OS from ir1,
|
83 |
|
|
// There is less state to contdend with, as well as extra speed.
|
84 |
|
|
//
|
85 |
|
|
// Block Moves fundamentally execute from ir2. We initiate the first operand fetch from ir1.
|
86 |
|
|
//
|
87 |
|
|
// 3/18/2004 Second time through. In impleenting the execution logic it became clear that
|
88 |
|
|
// there were "minor" problems with the handling of the DD and FD prefix insts (especially
|
89 |
|
|
// DDCD and FDCB --- collectively called PFxCB below. On review, I had to question the
|
90 |
|
|
// value of "breaking up" the ir0 execution engine between the istate sequencer and the
|
91 |
|
|
// memstate sequencer. While I dislike state sequencers of much more than 16 states --
|
92 |
|
|
// the interaction between these sequencers was becomming harder to track than a single
|
93 |
|
|
// state macine. Thus - this file is getting re-worked. I will call it memstate2 (at least
|
94 |
|
|
// for awhile) as I wish to keep the old file around. I want to show (in the state machine
|
95 |
|
|
// logic) what the next memory operation is.... guess the best method consistent with my
|
96 |
|
|
// documentation practices is to define a register (mem_op) = { if, wb_we, wb_cyc }.
|
97 |
|
|
// This will require auxillary logic for computing the address --- but most of the decodes
|
98 |
|
|
// required will be there anyway.
|
99 |
|
|
// On further reflection, I think I will bite-the-bullet and use an always to define next_state.
|
100 |
|
|
// I don't like to use always to define wires, but I also want to dicument the setting of
|
101 |
|
|
// exec_ir2 in the same place - that is 3 different things.
|
102 |
|
|
//
|
103 |
|
|
// Hazards:
|
104 |
|
|
// There are 2 kinds of hazards: mem_hazard => we are storing into the next instruction location
|
105 |
|
|
// reg_hazard => we are modifying a register (ir2) that we are using
|
106 |
|
|
// here (ir1)
|
107 |
|
|
// In the former case, we throw out the instruction that arrives on the next tick, and restart the
|
108 |
|
|
// instruction pipeline, In the latter case, we simply wait a tick for the ir2 operaton to
|
109 |
|
|
// complete before starting the ir1 operation
|
110 |
|
|
//-------1---------2---------3--------CVS Log -----------------------7---------8---------9--------0
|
111 |
|
|
//
|
112 |
|
|
// $Id: memstate2.v,v 1.1.1.1 2004-06-18 08:38:46 mihal Exp $
|
113 |
|
|
//
|
114 |
|
|
// $Date: 2004-06-18 08:38:46 $
|
115 |
|
|
// $Revision: 1.1.1.1 $
|
116 |
|
|
// $Author: mihal $
|
117 |
|
|
// $Locker: $
|
118 |
|
|
// $State: Exp $
|
119 |
|
|
//
|
120 |
|
|
// Change History:
|
121 |
|
|
// $Log: not supported by cvs2svn $
|
122 |
|
|
// Revision 1.4 2004/04/16 18:16:57 bporcella
|
123 |
|
|
// try lint
|
124 |
|
|
//
|
125 |
|
|
// Revision 1.3 2004/04/16 17:06:54 bporcella
|
126 |
|
|
// no code change - added a comment and test lint
|
127 |
|
|
//
|
128 |
|
|
// Revision 1.2 2004/04/16 16:21:04 bporcella
|
129 |
|
|
// no code change - added a comment and test lint
|
130 |
|
|
//
|
131 |
|
|
// Revision 1.1.1.1 2004/04/13 23:50:19 bporcella
|
132 |
|
|
// import first files
|
133 |
|
|
//
|
134 |
|
|
//
|
135 |
|
|
//
|
136 |
|
|
//-------1---------2---------3--------Module Name and Port List------7---------8---------9--------0
|
137 |
|
|
module memstate2(wb_adr, wb_we, wb_cyc, wb_stb, wb_lock, wb_tga_io, wb_dat_o, add_out,
|
138 |
|
|
exec_ir2, ir1, ir2, ir1dd, ir1fd, ir2dd, ir2fd, nn, sp,
|
139 |
|
|
|
140 |
|
|
upd_ar, upd_br, upd_cr, upd_dr, upd_er, upd_hr, upd_lr,upd_fr,
|
141 |
|
|
beq0, ceq0,
|
142 |
|
|
ar, fr, br, cr, dr, er, hr, lr,
|
143 |
|
|
ixr, iyr,
|
144 |
|
|
wb_dat_i, wb_ack, clk, rst,
|
145 |
|
|
wb_int_rq,
|
146 |
|
|
add16
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
);
|
150 |
|
|
|
151 |
|
|
//-------1---------2---------3--------Output Ports---------6---------7---------8---------9--------0
|
152 |
|
|
// mod only to checkout lint
|
153 |
|
|
// mod again for lint check -- first check pretty wierd
|
154 |
|
|
// 3rd lint try
|
155 |
|
|
output [15:0] wb_adr;
|
156 |
|
|
output wb_we;
|
157 |
|
|
output wb_cyc;
|
158 |
|
|
output wb_stb;
|
159 |
|
|
output wb_lock; // bit set and clear insts should be atomic - could matter sometime
|
160 |
|
|
output wb_tga_io;
|
161 |
|
|
output wb_dat_o; // from nn
|
162 |
|
|
output [15:0] add_out; // output of adder (may not wb_adr)
|
163 |
|
|
|
164 |
|
|
output exec_ir2;
|
165 |
|
|
output [9:0] ir1, ir2;
|
166 |
|
|
output ir1dd, ir2dd;
|
167 |
|
|
output ir1fd, ir2fd;
|
168 |
|
|
output [15:0] nn;
|
169 |
|
|
output [15:0] sp;
|
170 |
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
//-------1---------2---------3--------Input Ports----------6---------7---------8---------9--------0
|
175 |
|
|
input upd_ar, upd_br, upd_cr, upd_dr, upd_er, upd_hr, upd_lr,upd_fr;
|
176 |
|
|
|
177 |
|
|
input beq0, ceq0;
|
178 |
|
|
input [7:0] ar, fr, br, cr, dr, er, hr, lr;
|
179 |
|
|
input [15:0] ixr, iyr;
|
180 |
|
|
input [7:0] wb_dat_i;
|
181 |
|
|
input wb_ack, clk, rst;
|
182 |
|
|
input wb_int_rq;
|
183 |
|
|
input [15:0] add16; // ir2 execution engine output for sp updates
|
184 |
|
|
|
185 |
|
|
|
186 |
|
|
//-------1---------2---------3--------Parameters-----------6---------7---------8---------9--------0
|
187 |
|
|
`include "opcodes.v" // states of the main memory sequencer
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
parameter TAG_IO = 2'b01, // need to review general wb usage to undrstand how best to
|
191 |
|
|
TAG_INT = 2'b10; // document this.
|
192 |
|
|
// 12na
|
193 |
|
|
parameter IPIPE_NOP = 4'b0000,
|
194 |
|
|
IPIPE_A2 = 4'b0001,
|
195 |
|
|
IPIPE_ENN = 4'b0010,
|
196 |
|
|
IPIPE_ENNA2 = 4'b0011,
|
197 |
|
|
IPIPE_EN2 = 4'b0100,
|
198 |
|
|
IPIPE_EN2A2 = 4'b0101,
|
199 |
|
|
IPIPE_ENNEN2 = 4'b0110,
|
200 |
|
|
IPIPE_ENNEN2A2 = 4'b0111,
|
201 |
|
|
IPIPE_EN1 = 4'b1000,
|
202 |
|
|
IPIPE_EN1A2 = 4'b1001,
|
203 |
|
|
IPIPE_BOGUS = 4'b1010, // no reason (yet) to load both n and ir1
|
204 |
|
|
IPIPE_BOUS2 = 4'b1011,
|
205 |
|
|
IPIPE_EN12 = 4'b1100,
|
206 |
|
|
IPIPE_EN12A2 = 4'b1101,
|
207 |
|
|
IPIPE_BOGUS3 = 4'b1110,
|
208 |
|
|
IPIPE_BOGUS4 = 4'b1111;
|
209 |
|
|
|
210 |
|
|
// well at first cut I tried to make this 2 state macines both less than 16 states.
|
211 |
|
|
// this is 56 states at first cut. Assignemnt is subject to change.
|
212 |
|
|
|
213 |
|
|
// ------ mem state decoder state machine states --------------------------------
|
214 |
|
|
parameter DEC_IDLE = 6'h00,
|
215 |
|
|
DEC_HALT = 6'h01,
|
216 |
|
|
DEC_IF1 = 6'h02,
|
217 |
|
|
DEC_IF2 = 6'h03,
|
218 |
|
|
DEC_IF2A = 6'h04,
|
219 |
|
|
DEC_EXEC = 6'h05,
|
220 |
|
|
DEC_CB = 6'h06,
|
221 |
|
|
DEC_DDFD = 6'h07,
|
222 |
|
|
DEC_ED = 6'h08,
|
223 |
|
|
DEC_EDNN1 = 6'h09,
|
224 |
|
|
DEC_EDNN2 = 6'h0a,
|
225 |
|
|
DEC_EDRD1 = 6'h0b,
|
226 |
|
|
DEC_EDRD2 = 6'h0c,
|
227 |
|
|
DEC_EDWR = 6'h0d,
|
228 |
|
|
DEC_EDBCP1 = 6'h0e,
|
229 |
|
|
DEC_EDBCP2 = 6'h0f,
|
230 |
|
|
DEC_EDBCP3 = 6'h10,
|
231 |
|
|
DEC_EDBIN1 = 6'h11,
|
232 |
|
|
DEC_EDBIN2 = 6'h12,
|
233 |
|
|
DEC_EDBIN3 = 6'h13,
|
234 |
|
|
DEC_EDBOUT1 = 6'h14,
|
235 |
|
|
DEC_EDBOUT2 = 6'h15,
|
236 |
|
|
DEC_EDBOUT3 = 6'h16,
|
237 |
|
|
DEC_EDBMV1 = 6'h17,
|
238 |
|
|
DEC_EDBMV2 = 6'h18,
|
239 |
|
|
DEC_EDBMV3 = 6'h19,
|
240 |
|
|
DEC_N = 6'h1a,
|
241 |
|
|
DEC_NIN = 6'h1b,
|
242 |
|
|
DEC_NN = 6'h1c,
|
243 |
|
|
DEC_NNCALL1 = 6'h1d,
|
244 |
|
|
DEC_NNCALL2 = 6'h1e,
|
245 |
|
|
DEC_NNOS1 = 6'h1f,
|
246 |
|
|
DEC_NNOS2 = 6'h20,
|
247 |
|
|
DEC_NNOS3 = 6'h21,
|
248 |
|
|
DEC_NNOF1 = 6'h22,
|
249 |
|
|
DEC_NNOF2 = 6'h23,
|
250 |
|
|
DEC_NNOF3 = 6'h24,
|
251 |
|
|
DEC_NNOF4 = 6'h25,
|
252 |
|
|
DEC_DDOS = 6'h26,
|
253 |
|
|
DEC_DDOF = 6'h27,
|
254 |
|
|
DEC_OF = 6'h28,
|
255 |
|
|
DEC_POP = 6'h29,
|
256 |
|
|
DEC_PUSH = 6'h2a,
|
257 |
|
|
DEC_RMW = 6'h2b,
|
258 |
|
|
DEC_RMW2 = 6'h2c,
|
259 |
|
|
DEC_CBM = 6'h2d,
|
260 |
|
|
DEC_PFxCB = 6'h2e,
|
261 |
|
|
DEC_PFxCB2 = 6'h2f,
|
262 |
|
|
DEC_PFxCB3 = 6'h30,
|
263 |
|
|
DEC_PFxCB4 = 6'h31,
|
264 |
|
|
DEC_INT1 = 6'h32,
|
265 |
|
|
DEC_INT2 = 6'h33,
|
266 |
|
|
DEC_INT3 = 6'h34,
|
267 |
|
|
DEC_INT4 = 6'h35,
|
268 |
|
|
DEC_INT5 = 6'h36,
|
269 |
|
|
DEC_RET = 6'h37,
|
270 |
|
|
DEC_NNJMP = 6'h38,
|
271 |
|
|
DEC_RET2 = 6'h39 ;
|
272 |
|
|
|
273 |
|
|
// initial decode assignemnts. These assignemens are made to wires on an initial decode
|
274 |
|
|
// to help document next state transitions
|
275 |
|
|
parameter I1_CB = 4'h0,
|
276 |
|
|
I1_DDFD = 4'h1,
|
277 |
|
|
I1_ED = 4'h2,
|
278 |
|
|
I1_JMP = 4'h3,
|
279 |
|
|
I1_N = 4'h4,
|
280 |
|
|
I1_NN = 4'h5,
|
281 |
|
|
I1_OF = 4'h6,
|
282 |
|
|
I1_OS = 4'h7,
|
283 |
|
|
I1_POP = 4'h8,
|
284 |
|
|
I1_PUSH = 4'h9,
|
285 |
|
|
I1_RET = 4'ha,
|
286 |
|
|
I1_RMW = 4'hb,
|
287 |
|
|
I1_RST = 4'hc,
|
288 |
|
|
I1_R2R = 4'hd ;
|
289 |
|
|
|
290 |
|
|
|
291 |
|
|
// A note here on the choices of mnemonics..... in general, the target registers of
|
292 |
|
|
// memory ops are specified by an instruction register (ir1 for stores ir2 for loads).
|
293 |
|
|
// so Menomics in general are specifying the address source. However, there are exceptions.
|
294 |
|
|
//
|
295 |
|
|
parameter MEM_NOP = 5'h00,
|
296 |
|
|
MEM_IFPP1 = 5'h01,
|
297 |
|
|
MEM_OS1 = 5'h02, // only invoked on I1 OS multiple address sources and data sources
|
298 |
|
|
MEM_OF1 = 5'h03, // Address from HL unless LD A,(BC) or LD A,(DE) (used for rmw)
|
299 |
|
|
MEM_OFSP = 5'h04, // works for both POP and RET
|
300 |
|
|
MEM_OSSP = 5'h05, // if DEC_EXEC op from ir1 else msb nn (implies we store from lsb nn)
|
301 |
|
|
// used in CALL also.
|
302 |
|
|
MEM_OFIXpD = 5'h06, // used for prefix op fetches - all single bytes
|
303 |
|
|
MEM_OSIXpD = 5'h07, // data source is same as MEM_OS1
|
304 |
|
|
MEM_OSADR = 5'h08, // used (at lesat) for prefixed rmw -- perhaps others.
|
305 |
|
|
|
306 |
|
|
MEM_CALL = 5'h09, // pc<=nn, nn<=pc, wb_adr<=sp OS
|
307 |
|
|
MEM_OSNN = 5'h0a, // if DEC_EXEC op from ir1 else msb nn
|
308 |
|
|
MEM_OFNN = 5'h0b, // striaghtfoward
|
309 |
|
|
MEM_OFADRP1 = 5'h0c, // used (at least) when double ops above
|
310 |
|
|
MEM_OSADRP1 = 5'h0d, // "" "" ""
|
311 |
|
|
|
312 |
|
|
MEM_IFRST = 5'h0e, // special address transfer
|
313 |
|
|
MEM_IFREL_N = 5'h0f, // special address transfer for jmp rel
|
314 |
|
|
MEM_JMPHL = 5'h10, // another special jump transfer
|
315 |
|
|
MEM_IFNN = 5'h11, // used by call and return
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
MEM_OFHL_PM = 5'h12, // special block move ops
|
319 |
|
|
MEM_OSHL_PM = 5'h13, // special block move ops
|
320 |
|
|
MEM_OSDE_PM = 5'h14, // special block move ops
|
321 |
|
|
|
322 |
|
|
MEM_IOF_C = 5'h15, // special i/o ops
|
323 |
|
|
MEM_IOS_C = 5'h16, // operand is ar
|
324 |
|
|
MEM_IOF_N = 5'h17,
|
325 |
|
|
MEM_IOS_N = 5'h18,
|
326 |
|
|
MEM_OS_HL_N = 5'h19,
|
327 |
|
|
|
328 |
|
|
MEM_OSSP_PCM2 = 5'h1a, // int code (call
|
329 |
|
|
MEM_OSSP_P = 5'h1b, //
|
330 |
|
|
MEM_INTA = 5'h1c,
|
331 |
|
|
MEM_IFINT = 5'h1d,
|
332 |
|
|
MEM_DECPC = 5'h1e ;
|
333 |
|
|
|
334 |
|
|
|
335 |
|
|
|
336 |
|
|
|
337 |
|
|
|
338 |
|
|
|
339 |
|
|
|
340 |
|
|
|
341 |
|
|
|
342 |
|
|
//-------1---------2---------3--------Wires----------------6---------7---------8---------9--------0
|
343 |
|
|
|
344 |
|
|
|
345 |
|
|
wire use_sp;
|
346 |
|
|
wire use_pc;
|
347 |
|
|
wire use_hl;
|
348 |
|
|
wire use_de;
|
349 |
|
|
wire use_bc;
|
350 |
|
|
wire use_flags;
|
351 |
|
|
wire cb_mem;
|
352 |
|
|
wire br_test8t; // branch test true (8 test field)
|
353 |
|
|
wire br_test4t; // branch test true (4 test field)
|
354 |
|
|
|
355 |
|
|
wire ofos;
|
356 |
|
|
wire any_os; // most terms above only valid on mem_exec this includes all stores
|
357 |
|
|
wire wb_rdy_nhz;
|
358 |
|
|
wire dec_blk_inc;
|
359 |
|
|
wire we_next;
|
360 |
|
|
wire hazard;
|
361 |
|
|
wire wb_int;
|
362 |
|
|
wire [15:0] hl, de, bc;
|
363 |
|
|
wire mem_exec_dec;
|
364 |
|
|
|
365 |
|
|
wire use_a ;
|
366 |
|
|
wire use_b ;
|
367 |
|
|
wire use_c ;
|
368 |
|
|
wire use_d ;
|
369 |
|
|
wire use_e ;
|
370 |
|
|
wire use_h ;
|
371 |
|
|
wire use_l ;
|
372 |
|
|
// don't forget that as 1r1 is executed it is transferred to ir2. Anything I need to know
|
373 |
|
|
// about subsequent operations must be stored.
|
374 |
|
|
// 6 5 4 15
|
375 |
|
|
// assign {next_dec_state, next_mem_state, next_pipe_state} = next_state;
|
376 |
|
|
wire [5:0] next_dec_state;
|
377 |
|
|
wire [4:0] next_mem_state;
|
378 |
|
|
wire [3:0] next_pipe_state;
|
379 |
|
|
wire ed_dbl_rd;
|
380 |
|
|
//-------1---------2---------3--------Registers------------6---------7---------8---------9--------0
|
381 |
|
|
|
382 |
|
|
reg [15:0] pc;
|
383 |
|
|
reg [15:0] sp;
|
384 |
|
|
reg [15:0] wb_adr;
|
385 |
|
|
reg wb_we;
|
386 |
|
|
reg wb_cyc;
|
387 |
|
|
reg wb_stb;
|
388 |
|
|
reg wb_lock;
|
389 |
|
|
reg wb_tga_io;
|
390 |
|
|
|
391 |
|
|
reg blk_inc_flg;
|
392 |
|
|
reg [9:0] ir1, ir2;
|
393 |
|
|
reg ir1dd, ir2dd;
|
394 |
|
|
reg ir1fd, ir2fd;
|
395 |
|
|
reg [15:0] nn;
|
396 |
|
|
|
397 |
|
|
reg [15:0] next_state; // a wire assigned in an alowys loop.
|
398 |
|
|
|
399 |
|
|
reg [5:0] dec_state; // the register set each clock from next_dec_state;
|
400 |
|
|
|
401 |
|
|
reg of16_reg, os16_reg, rmw8_reg, call_reg, ret_reg, ioi;
|
402 |
|
|
reg push_reg;
|
403 |
|
|
reg pop_reg;
|
404 |
|
|
reg inst_haz;
|
405 |
|
|
reg exec_ir2;
|
406 |
|
|
reg blk_rpt_flg;
|
407 |
|
|
reg blk_io_flg;
|
408 |
|
|
reg flag_os1;
|
409 |
|
|
reg int_en, en_int_next;
|
410 |
|
|
reg wb_irq_sync;
|
411 |
|
|
//-------1---------2---------3--------Assignments----------6---------7---------8---------9--------0
|
412 |
|
|
//
|
413 |
|
|
// ir is 10 bits most significant codes ir1[9:8] = { EDgrp, CBgrp } DDgrp and FDgrp are modifiers
|
414 |
|
|
|
415 |
|
|
|
416 |
|
|
assign wb_dat_o = nn[15:8];
|
417 |
|
|
|
418 |
|
|
wire sf, zf, f5f, hf, f3f, pvf, nf, cf;
|
419 |
|
|
assign { sf, zf, f5f, hf, f3f, pvf, nf, cf} = fr;
|
420 |
|
|
|
421 |
|
|
|
422 |
|
|
assign hl = {hr, lr};
|
423 |
|
|
assign de = {dr, er};
|
424 |
|
|
assign bc = {br, cr};
|
425 |
|
|
|
426 |
|
|
|
427 |
|
|
// this "groups" the instructions to determine first memory operation
|
428 |
|
|
|
429 |
|
|
parameter I1DCNT = 4; // parameter used below simply to make possible change easier.
|
430 |
|
|
assign mem_exec_dec =
|
431 |
|
|
{I1DCNT {CBgrp == ir1}} & I1_CB |// CBgrp is rotates and bi
|
432 |
|
|
{I1DCNT {DDgrp == ir1}} & I1_DDFD|// DDgrp
|
433 |
|
|
{I1DCNT {FDgrp == ir1}} & I1_DDFD|// FDgrp FD
|
434 |
|
|
{I1DCNT {EDgrp == ir1}} & I1_ED |// EDgrp ED
|
435 |
|
|
{I1DCNT {JPsHL == ir1}} & I1_JMP |// JP HL ; E9 // doc
|
436 |
|
|
{I1DCNT {ADCsA_N == ir1}} & I1_N |// ADC A,N ; CE XX
|
437 |
|
|
{I1DCNT {ADDsA_N == ir1}} & I1_N |// ADD A,N ; C6 XX
|
438 |
|
|
{I1DCNT {ANDsN == ir1}} & I1_N |// AND N ; E6 XX
|
439 |
|
|
{I1DCNT {CPsN == ir1}} & I1_N |// CP N ; FE XX
|
440 |
|
|
{I1DCNT {INsA_6N7 == ir1}} & I1_N |// IN A,(N) ; DB XX
|
441 |
|
|
{I1DCNT {JRs$t2 == ir1}} & I1_N |// JR $+2 ; 18 XX
|
442 |
|
|
{I1DCNT {JRsC_$t2 == ir1}} & I1_N |// JR C,$+2 ; 38 XX
|
443 |
|
|
{I1DCNT {JRsNC_$t2 == ir1}} & I1_N |// JR NC,$+2 ; 30 XX
|
444 |
|
|
{I1DCNT {JRsZ_$t2 == ir1}} & I1_N |// JR Z,$+2 ; 28 XX
|
445 |
|
|
{I1DCNT {JRsNZ_$t2 == ir1}} & I1_N |// JR NZ,$+2 ; 20 XX
|
446 |
|
|
{I1DCNT {LDs6HL7_N == ir1}} & I1_N |// LD (HL),N ; 36 XX
|
447 |
|
|
{I1DCNT {LDsA_N == ir1}} & I1_N |// LD A,N ; 3E XX
|
448 |
|
|
{I1DCNT {LDsB_N == ir1}} & I1_N |// LD B,N ; 06 XX
|
449 |
|
|
{I1DCNT {LDsC_N == ir1}} & I1_N |// LD C,N ; 0E XX
|
450 |
|
|
{I1DCNT {LDsD_N == ir1}} & I1_N |// LD D,N ; 16 XX
|
451 |
|
|
{I1DCNT {LDsE_N == ir1}} & I1_N |// LD E,N ; 1E XX
|
452 |
|
|
{I1DCNT {LDsH_N == ir1}} & I1_N |// LD H,N ; 26 XX
|
453 |
|
|
{I1DCNT {LDsL_N == ir1}} & I1_N |// LD L,N ; 2E XX
|
454 |
|
|
{I1DCNT {ORsN == ir1}} & I1_N |// OR N ; F6 XX
|
455 |
|
|
{I1DCNT {OUTs6N7_A == ir1}} & I1_N |// OUT (N),A ; D3 XX
|
456 |
|
|
{I1DCNT {SBCsA_N == ir1}} & I1_N |// SBC A,N ; DE XX
|
457 |
|
|
{I1DCNT {SUBsN == ir1}} & I1_N |// SUB N ; D6 XX
|
458 |
|
|
{I1DCNT {XORsN == ir1}} & I1_N |// XOR N ; EE XX
|
459 |
|
|
{I1DCNT {CALLsC_NN == ir1}} & I1_NN |// CALL C,NN ; DC XX XX
|
460 |
|
|
{I1DCNT {CALLsNC_NN == ir1}} & I1_NN |// CALL NC,NN ; D4 XX XX
|
461 |
|
|
{I1DCNT {CALLsNN == ir1}} & I1_NN |// CALL NN ; CD XX XX
|
462 |
|
|
{I1DCNT {CALLsNZ_NN == ir1}} & I1_NN |// CALL NZ,NN ; C4 XX XX
|
463 |
|
|
{I1DCNT {CALLsPE_NN == ir1}} & I1_NN |// CALL PE,NN ; EC XX XX
|
464 |
|
|
{I1DCNT {CALLsPO_NN == ir1}} & I1_NN |// CALL PO,NN ; E4 XX XX
|
465 |
|
|
{I1DCNT {CALLsP_NN == ir1}} & I1_NN |// CALL P,NN ; F4 XX XX
|
466 |
|
|
{I1DCNT {CALLsZ_NN == ir1}} & I1_NN |// CALL Z,NN ; CC XX XX
|
467 |
|
|
{I1DCNT {CALLsM_NN == ir1}} & I1_NN |// CALL M,NN ; FC XX XX
|
468 |
|
|
{I1DCNT {JP == ir1}} & I1_NN |// JP ; C3 XX XX
|
469 |
|
|
{I1DCNT {JPsC == ir1}} & I1_NN |// JP C ; DA XX XX
|
470 |
|
|
{I1DCNT {JPsM == ir1}} & I1_NN |// JP M, ; FA XX XX
|
471 |
|
|
{I1DCNT {JPsNC == ir1}} & I1_NN |// JP NC, ; D2 XX XX
|
472 |
|
|
{I1DCNT {JPsNZ == ir1}} & I1_NN |// JP NZ ; C2 XX XX
|
473 |
|
|
{I1DCNT {JPsP == ir1}} & I1_NN |// JP P ; F2 XX XX
|
474 |
|
|
{I1DCNT {JPsPE == ir1}} & I1_NN |// JP PE, ; EA XX XX
|
475 |
|
|
{I1DCNT {JPsPO == ir1}} & I1_NN |// JP PO ; E2 XX XX
|
476 |
|
|
{I1DCNT {JPsZ == ir1}} & I1_NN |// JP Z ; CA XX XX
|
477 |
|
|
{I1DCNT {LDs6NN7_A == ir1}} & I1_NN |// LD (NN),A ; 32 XX XX
|
478 |
|
|
{I1DCNT {LDs6NN7_HL == ir1}} & I1_NN |// LD (NN),HL ; 22 XX XX
|
479 |
|
|
{I1DCNT {LDsA_6NN7 == ir1}} & I1_NN |// LD A,(NN) ; 3A XX XX
|
480 |
|
|
{I1DCNT {LDsBC_NN == ir1}} & I1_NN |// LD BC,NN ; 01 XX XX
|
481 |
|
|
{I1DCNT {LDsDE_NN == ir1}} & I1_NN |// LD DE,NN ; 11 XX XX
|
482 |
|
|
{I1DCNT {LDsHL_6NN7 == ir1}} & I1_NN |// LD HL,(NN) ; 2A XX XX
|
483 |
|
|
{I1DCNT {LDsHL_NN == ir1}} & I1_NN |// LD HL,NN ; 21 XX XX
|
484 |
|
|
{I1DCNT {LDsSP_NN == ir1}} & I1_NN |// LD SP,NN ; 31 XX XX
|
485 |
|
|
{I1DCNT {ADCsA_6HL7 == ir1}} & I1_OF |// ADC A,(HL) ; 8E
|
486 |
|
|
{I1DCNT {ADDsA_6HL7 == ir1}} & I1_OF |// ADD A,(HL) ; 86
|
487 |
|
|
{I1DCNT {ANDs6HL7 == ir1}} & I1_OF |// AND (HL) ; A6
|
488 |
|
|
{I1DCNT {CPs6HL7 == ir1}} & I1_OF |// CP (HL) ; BE
|
489 |
|
|
{I1DCNT {LDsA_6BC7 == ir1}} & I1_OF |// LD A,(BC) ; 0A
|
490 |
|
|
{I1DCNT {LDsA_6DE7 == ir1}} & I1_OF |// LD A,(DE) ; 1A
|
491 |
|
|
{I1DCNT {LDsA_6HL7 == ir1}} & I1_OF |// LD A,(HL) ; 7E
|
492 |
|
|
{I1DCNT {LDsB_6HL7 == ir1}} & I1_OF |// LD B,(HL) ; 46
|
493 |
|
|
{I1DCNT {LDsC_6HL7 == ir1}} & I1_OF |// LD C,(HL) ; 4E
|
494 |
|
|
{I1DCNT {LDsD_6HL7 == ir1}} & I1_OF |// LD D,(HL) ; 56
|
495 |
|
|
{I1DCNT {LDsE_6HL7 == ir1}} & I1_OF |// LD E,(HL) ; 5E
|
496 |
|
|
{I1DCNT {LDsH_6HL7 == ir1}} & I1_OF |// LD H,(HL) ; 66
|
497 |
|
|
{I1DCNT {LDsL_6HL7 == ir1}} & I1_OF |// LD L,(HL) ; 6E
|
498 |
|
|
{I1DCNT {ORs6HL7 == ir1}} & I1_OF |// OR (HL) ; B6
|
499 |
|
|
{I1DCNT {SBCs6HL7 == ir1}} & I1_OF |// SBC (HL) ; 9E
|
500 |
|
|
{I1DCNT {SUBs6HL7 == ir1}} & I1_OF |// SUB (HL) ; 96
|
501 |
|
|
{I1DCNT {XORs6HL7 == ir1}} & I1_OF |// XOR (HL) ; AE
|
502 |
|
|
{I1DCNT {LDs6BC7_A == ir1}} & I1_OS |// LD (BC),A ; 02
|
503 |
|
|
{I1DCNT {LDs6DE7_A == ir1}} & I1_OS |// LD (DE),A ; 12
|
504 |
|
|
{I1DCNT {LDs6HL7_A == ir1}} & I1_OS |// LD (HL),A ; 77
|
505 |
|
|
{I1DCNT {LDs6HL7_B == ir1}} & I1_OS |// LD (HL),B ; 70
|
506 |
|
|
{I1DCNT {LDs6HL7_C == ir1}} & I1_OS |// LD (HL),C ; 71
|
507 |
|
|
{I1DCNT {LDs6HL7_D == ir1}} & I1_OS |// LD (HL),D ; 72
|
508 |
|
|
{I1DCNT {LDs6HL7_E == ir1}} & I1_OS |// LD (HL),E ; 73
|
509 |
|
|
{I1DCNT {LDs6HL7_H == ir1}} & I1_OS |// LD (HL),H ; 74
|
510 |
|
|
{I1DCNT {LDs6HL7_L == ir1}} & I1_OS |// LD (HL),L ; 75
|
511 |
|
|
{I1DCNT {POPsAF == ir1}} & I1_POP |// POP AF ; F1
|
512 |
|
|
{I1DCNT {POPsBC == ir1}} & I1_POP |// POP BC ; C1
|
513 |
|
|
{I1DCNT {POPsDE == ir1}} & I1_POP |// POP DE ; D1
|
514 |
|
|
{I1DCNT {POPsHL == ir1}} & I1_POP |// POP HL ; E1
|
515 |
|
|
{I1DCNT {PUSHsAF == ir1}} & I1_PUSH|// PUSH AF ; F5
|
516 |
|
|
{I1DCNT {PUSHsBC == ir1}} & I1_PUSH|// PUSH BC ; C5
|
517 |
|
|
{I1DCNT {PUSHsDE == ir1}} & I1_PUSH|// PUSH DE ; D5
|
518 |
|
|
{I1DCNT {PUSHsHL == ir1}} & I1_PUSH|// PUSH HL ; E5
|
519 |
|
|
{I1DCNT {ADCsA_A == ir1}} & I1_R2R |// ADC A,A ; 8F
|
520 |
|
|
{I1DCNT {ADCsA_B == ir1}} & I1_R2R |// ADC A,B ; 88
|
521 |
|
|
{I1DCNT {ADCsA_C == ir1}} & I1_R2R |// ADC A,C ; 89
|
522 |
|
|
{I1DCNT {ADCsA_D == ir1}} & I1_R2R |// ADC A,D ; 8A
|
523 |
|
|
{I1DCNT {ADCsA_E == ir1}} & I1_R2R |// ADC A,E ; 8B
|
524 |
|
|
{I1DCNT {ADCsA_H == ir1}} & I1_R2R |// ADC A,H ; 8C
|
525 |
|
|
{I1DCNT {ADCsA_L == ir1}} & I1_R2R |// ADC A,L ; 8D
|
526 |
|
|
{I1DCNT {ADDsA_A == ir1}} & I1_R2R |// ADD A,A ; 87
|
527 |
|
|
{I1DCNT {ADDsA_B == ir1}} & I1_R2R |// ADD A,B ; 80
|
528 |
|
|
{I1DCNT {ADDsA_C == ir1}} & I1_R2R |// ADD A,C ; 81
|
529 |
|
|
{I1DCNT {ADDsA_D == ir1}} & I1_R2R |// ADD A,D ; 82
|
530 |
|
|
{I1DCNT {ADDsA_E == ir1}} & I1_R2R |// ADD A,E ; 83
|
531 |
|
|
{I1DCNT {ADDsA_H == ir1}} & I1_R2R |// ADD A,H ; 84
|
532 |
|
|
{I1DCNT {ADDsA_L == ir1}} & I1_R2R |// ADD A,L ; 85
|
533 |
|
|
{I1DCNT {ADDsHL_BC == ir1}} & I1_R2R |// ADD HL,BC ; 09
|
534 |
|
|
{I1DCNT {ADDsHL_DE == ir1}} & I1_R2R |// ADD HL,DE ; 19
|
535 |
|
|
{I1DCNT {ADDsHL_HL == ir1}} & I1_R2R |// ADD HL,HL ; 29
|
536 |
|
|
{I1DCNT {ADDsHL_SP == ir1}} & I1_R2R |// ADD HL,SP ; 39
|
537 |
|
|
{I1DCNT {ANDsA == ir1}} & I1_R2R |// AND A ; A7
|
538 |
|
|
{I1DCNT {ANDsB == ir1}} & I1_R2R |// AND B ; A0
|
539 |
|
|
{I1DCNT {ANDsC == ir1}} & I1_R2R |// AND C ; A1
|
540 |
|
|
{I1DCNT {ANDsD == ir1}} & I1_R2R |// AND D ; A2
|
541 |
|
|
{I1DCNT {ANDsE == ir1}} & I1_R2R |// AND E ; A3
|
542 |
|
|
{I1DCNT {ANDsH == ir1}} & I1_R2R |// AND H ; A4
|
543 |
|
|
{I1DCNT {ANDsL == ir1}} & I1_R2R |// AND L ; A5
|
544 |
|
|
{I1DCNT {CCF == ir1}} & I1_R2R |// CCF ; 3F
|
545 |
|
|
{I1DCNT {CPL == ir1}} & I1_R2R |// CPL ; 2F
|
546 |
|
|
{I1DCNT {CPsA == ir1}} & I1_R2R |// CP A ; BF
|
547 |
|
|
{I1DCNT {CPsB == ir1}} & I1_R2R |// CP B ; B8
|
548 |
|
|
{I1DCNT {CPsC == ir1}} & I1_R2R |// CP C ; B9
|
549 |
|
|
{I1DCNT {CPsD == ir1}} & I1_R2R |// CP D ; BA
|
550 |
|
|
{I1DCNT {CPsE == ir1}} & I1_R2R |// CP E ; BB
|
551 |
|
|
{I1DCNT {CPsH == ir1}} & I1_R2R |// CP H ; BC
|
552 |
|
|
{I1DCNT {CPsL == ir1}} & I1_R2R |// CP L ; BD
|
553 |
|
|
{I1DCNT {DAA == ir1}} & I1_R2R |// DAA ; 27
|
554 |
|
|
{I1DCNT {DECsA == ir1}} & I1_R2R |// DEC A ; 3D
|
555 |
|
|
{I1DCNT {DECsB == ir1}} & I1_R2R |// DEC B ; 05
|
556 |
|
|
{I1DCNT {DECsBC == ir1}} & I1_R2R |// DEC BC ; 0B
|
557 |
|
|
{I1DCNT {DECsC == ir1}} & I1_R2R |// DEC C ; 0D
|
558 |
|
|
{I1DCNT {DECsD == ir1}} & I1_R2R |// DEC D ; 15
|
559 |
|
|
{I1DCNT {DECsDE == ir1}} & I1_R2R |// DEC DE ; 1B
|
560 |
|
|
{I1DCNT {DECsE == ir1}} & I1_R2R |// DEC E ; 1D
|
561 |
|
|
{I1DCNT {DECsH == ir1}} & I1_R2R |// DEC H ; 25
|
562 |
|
|
{I1DCNT {DECsHL == ir1}} & I1_R2R |// DEC HL ; 2B
|
563 |
|
|
{I1DCNT {DECsL == ir1}} & I1_R2R |// DEC L ; 2D
|
564 |
|
|
{I1DCNT {DECsSP == ir1}} & I1_R2R |// DEC SP ; 3B
|
565 |
|
|
{I1DCNT {DI == ir1}} & I1_R2R |// DI ; F3
|
566 |
|
|
{I1DCNT {DJNZs$t2 == ir1}} & I1_R2R |// DJNZ $+2 ; 10 XX
|
567 |
|
|
{I1DCNT {EI == ir1}} & I1_R2R |// EI ; FB
|
568 |
|
|
{I1DCNT {EXX == ir1}} & I1_R2R |// EXX ; D9
|
569 |
|
|
{I1DCNT {EXsAF_AFp == ir1}} & I1_R2R |// EX AF,AF' ; 08
|
570 |
|
|
{I1DCNT {EXsDE_HL == ir1}} & I1_R2R |// EX DE,HL ; EB
|
571 |
|
|
{I1DCNT {HALT == ir1}} & I1_R2R |// HALT ; 76
|
572 |
|
|
{I1DCNT {INCsA == ir1}} & I1_R2R |// INC A ; 3C
|
573 |
|
|
{I1DCNT {INCsB == ir1}} & I1_R2R |// INC B ; 04
|
574 |
|
|
{I1DCNT {INCsBC == ir1}} & I1_R2R |// INC BC ; 03
|
575 |
|
|
{I1DCNT {INCsC == ir1}} & I1_R2R |// INC C ; 0C
|
576 |
|
|
{I1DCNT {INCsD == ir1}} & I1_R2R |// INC D ; 14
|
577 |
|
|
{I1DCNT {INCsDE == ir1}} & I1_R2R |// INC DE ; 13
|
578 |
|
|
{I1DCNT {INCsE == ir1}} & I1_R2R |// INC E ; 1C
|
579 |
|
|
{I1DCNT {INCsH == ir1}} & I1_R2R |// INC H ; 24
|
580 |
|
|
{I1DCNT {INCsHL == ir1}} & I1_R2R |// INC HL ; 23
|
581 |
|
|
{I1DCNT {INCsL == ir1}} & I1_R2R |// INC L ; 2C
|
582 |
|
|
{I1DCNT {INCsSP == ir1}} & I1_R2R |// INC SP ; 33
|
583 |
|
|
{I1DCNT {LDsA_A == ir1}} & I1_R2R |// LD A,A ; 7F
|
584 |
|
|
{I1DCNT {LDsA_B == ir1}} & I1_R2R |// LD A,B ; 78
|
585 |
|
|
{I1DCNT {LDsA_C == ir1}} & I1_R2R |// LD A,C ; 79
|
586 |
|
|
{I1DCNT {LDsA_D == ir1}} & I1_R2R |// LD A,D ; 7A
|
587 |
|
|
{I1DCNT {LDsA_E == ir1}} & I1_R2R |// LD A,E ; 7B
|
588 |
|
|
{I1DCNT {LDsA_H == ir1}} & I1_R2R |// LD A,H ; 7C
|
589 |
|
|
{I1DCNT {LDsA_L == ir1}} & I1_R2R |// LD A,L ; 7D
|
590 |
|
|
{I1DCNT {LDsB_A == ir1}} & I1_R2R |// LD B,A ; 47
|
591 |
|
|
{I1DCNT {LDsB_B == ir1}} & I1_R2R |// LD B,B ; 40
|
592 |
|
|
{I1DCNT {LDsB_C == ir1}} & I1_R2R |// LD B,C ; 41
|
593 |
|
|
{I1DCNT {LDsB_D == ir1}} & I1_R2R |// LD B,D ; 42
|
594 |
|
|
{I1DCNT {LDsB_E == ir1}} & I1_R2R |// LD B,E ; 43
|
595 |
|
|
{I1DCNT {LDsB_H == ir1}} & I1_R2R |// LD B,H ; 44
|
596 |
|
|
{I1DCNT {LDsB_L == ir1}} & I1_R2R |// LD B,L ; 45
|
597 |
|
|
{I1DCNT {LDsC_A == ir1}} & I1_R2R |// LD C,A ; 4F
|
598 |
|
|
{I1DCNT {LDsC_B == ir1}} & I1_R2R |// LD C,B ; 48
|
599 |
|
|
{I1DCNT {LDsC_C == ir1}} & I1_R2R |// LD C,C ; 49
|
600 |
|
|
{I1DCNT {LDsC_D == ir1}} & I1_R2R |// LD C,D ; 4A
|
601 |
|
|
{I1DCNT {LDsC_E == ir1}} & I1_R2R |// LD C,E ; 4B
|
602 |
|
|
{I1DCNT {LDsC_H == ir1}} & I1_R2R |// LD C,H ; 4C
|
603 |
|
|
{I1DCNT {LDsC_L == ir1}} & I1_R2R |// LD C,L ; 4D
|
604 |
|
|
{I1DCNT {LDsD_A == ir1}} & I1_R2R |// LD D,A ; 57
|
605 |
|
|
{I1DCNT {LDsD_B == ir1}} & I1_R2R |// LD D,B ; 50
|
606 |
|
|
{I1DCNT {LDsD_C == ir1}} & I1_R2R |// LD D,C ; 51
|
607 |
|
|
{I1DCNT {LDsD_D == ir1}} & I1_R2R |// LD D,D ; 52
|
608 |
|
|
{I1DCNT {LDsD_E == ir1}} & I1_R2R |// LD D,E ; 53
|
609 |
|
|
{I1DCNT {LDsD_H == ir1}} & I1_R2R |// LD D,H ; 54
|
610 |
|
|
{I1DCNT {LDsD_L == ir1}} & I1_R2R |// LD D,L ; 55
|
611 |
|
|
{I1DCNT {LDsE_A == ir1}} & I1_R2R |// LD E,A ; 5F
|
612 |
|
|
{I1DCNT {LDsE_B == ir1}} & I1_R2R |// LD E,B ; 58
|
613 |
|
|
{I1DCNT {LDsE_C == ir1}} & I1_R2R |// LD E,C ; 59
|
614 |
|
|
{I1DCNT {LDsE_D == ir1}} & I1_R2R |// LD E,D ; 5A
|
615 |
|
|
{I1DCNT {LDsE_E == ir1}} & I1_R2R |// LD E,E ; 5B
|
616 |
|
|
{I1DCNT {LDsE_H == ir1}} & I1_R2R |// LD E,H ; 5C
|
617 |
|
|
{I1DCNT {LDsE_L == ir1}} & I1_R2R |// LD E,L ; 5D
|
618 |
|
|
{I1DCNT {LDsH_A == ir1}} & I1_R2R |// LD H,A ; 67
|
619 |
|
|
{I1DCNT {LDsH_B == ir1}} & I1_R2R |// LD H,B ; 60
|
620 |
|
|
{I1DCNT {LDsH_C == ir1}} & I1_R2R |// LD H,C ; 61
|
621 |
|
|
{I1DCNT {LDsH_D == ir1}} & I1_R2R |// LD H,D ; 62
|
622 |
|
|
{I1DCNT {LDsH_E == ir1}} & I1_R2R |// LD H,E ; 63
|
623 |
|
|
{I1DCNT {LDsH_H == ir1}} & I1_R2R |// LD H,H ; 64
|
624 |
|
|
{I1DCNT {LDsH_L == ir1}} & I1_R2R |// LD H,L ; 65
|
625 |
|
|
{I1DCNT {LDsL_A == ir1}} & I1_R2R |// LD L,A ; 6F
|
626 |
|
|
{I1DCNT {LDsL_B == ir1}} & I1_R2R |// LD L,B ; 68
|
627 |
|
|
{I1DCNT {LDsL_C == ir1}} & I1_R2R |// LD L,C ; 69
|
628 |
|
|
{I1DCNT {LDsL_D == ir1}} & I1_R2R |// LD L,D ; 6A
|
629 |
|
|
{I1DCNT {LDsL_E == ir1}} & I1_R2R |// LD L,E ; 6B
|
630 |
|
|
{I1DCNT {LDsL_H == ir1}} & I1_R2R |// LD L,H ; 6C
|
631 |
|
|
{I1DCNT {LDsL_L == ir1}} & I1_R2R |// LD L,L ; 6D
|
632 |
|
|
{I1DCNT {LDsSP_HL == ir1}} & I1_R2R |// LD SP,HL ; F9
|
633 |
|
|
{I1DCNT {NOP == ir1}} & I1_R2R |// NOP ; 00
|
634 |
|
|
{I1DCNT {ORsA == ir1}} & I1_R2R |// OR A ; B7
|
635 |
|
|
{I1DCNT {ORsB == ir1}} & I1_R2R |// OR B ; B0
|
636 |
|
|
{I1DCNT {ORsC == ir1}} & I1_R2R |// OR C ; B1
|
637 |
|
|
{I1DCNT {ORsD == ir1}} & I1_R2R |// OR D ; B2
|
638 |
|
|
{I1DCNT {ORsE == ir1}} & I1_R2R |// OR E ; B3
|
639 |
|
|
{I1DCNT {ORsH == ir1}} & I1_R2R |// OR H ; B4
|
640 |
|
|
{I1DCNT {ORsL == ir1}} & I1_R2R |// OR L ; B5
|
641 |
|
|
{I1DCNT {RLA == ir1}} & I1_R2R |// RLA ; 17
|
642 |
|
|
{I1DCNT {RLCA == ir1}} & I1_R2R |// RLCA ; 07
|
643 |
|
|
{I1DCNT {RRA == ir1}} & I1_R2R |// RRA ; 1F
|
644 |
|
|
{I1DCNT {RRCA == ir1}} & I1_R2R |// RRCA ; 0F
|
645 |
|
|
{I1DCNT {SBCsA == ir1}} & I1_R2R |// SBC A ; 9F
|
646 |
|
|
{I1DCNT {SBCsB == ir1}} & I1_R2R |// SBC B ; 98
|
647 |
|
|
{I1DCNT {SBCsC == ir1}} & I1_R2R |// SBC C ; 99
|
648 |
|
|
{I1DCNT {SBCsD == ir1}} & I1_R2R |// SBC D ; 9A
|
649 |
|
|
{I1DCNT {SBCsE == ir1}} & I1_R2R |// SBC E ; 9B
|
650 |
|
|
{I1DCNT {SBCsH == ir1}} & I1_R2R |// SBC H ; 9C
|
651 |
|
|
{I1DCNT {SBCsL == ir1}} & I1_R2R |// SBC L ; 9D
|
652 |
|
|
{I1DCNT {SCF == ir1}} & I1_R2R |// SCF ; 37
|
653 |
|
|
{I1DCNT {SUBsA == ir1}} & I1_R2R |// SUB A ; 97
|
654 |
|
|
{I1DCNT {SUBsB == ir1}} & I1_R2R |// SUB B ; 90
|
655 |
|
|
{I1DCNT {SUBsC == ir1}} & I1_R2R |// SUB C ; 91
|
656 |
|
|
{I1DCNT {SUBsD == ir1}} & I1_R2R |// SUB D ; 92
|
657 |
|
|
{I1DCNT {SUBsE == ir1}} & I1_R2R |// SUB E ; 93
|
658 |
|
|
{I1DCNT {SUBsH == ir1}} & I1_R2R |// SUB H ; 94
|
659 |
|
|
{I1DCNT {SUBsL == ir1}} & I1_R2R |// SUB L ; 95
|
660 |
|
|
{I1DCNT {XORsA == ir1}} & I1_R2R |// XOR A ; AF
|
661 |
|
|
{I1DCNT {XORsB == ir1}} & I1_R2R |// XOR B ; A8
|
662 |
|
|
{I1DCNT {XORsC == ir1}} & I1_R2R |// XOR C ; A9
|
663 |
|
|
{I1DCNT {XORsD == ir1}} & I1_R2R |// XOR D ; AA
|
664 |
|
|
{I1DCNT {XORsE == ir1}} & I1_R2R |// XOR E ; AB
|
665 |
|
|
{I1DCNT {XORsH == ir1}} & I1_R2R |// XOR H ; AC
|
666 |
|
|
{I1DCNT {XORsL == ir1}} & I1_R2R |// XOR L ; AD
|
667 |
|
|
{I1DCNT {RET == ir1}} & I1_RET |// RET ; C9
|
668 |
|
|
{I1DCNT {RETsC == ir1 & cf }} & I1_RET |// RET C ; D8
|
669 |
|
|
{I1DCNT {RETsM == ir1 & sf }} & I1_RET |// RET M ; F8
|
670 |
|
|
{I1DCNT {RETsNC== ir1 & ~cf }} & I1_RET |// RET NC ; D0
|
671 |
|
|
{I1DCNT {RETsP == ir1 & ~sf }} & I1_RET |// RET P ; F0
|
672 |
|
|
{I1DCNT {RETsPE== ir1 & pvf }} & I1_RET |// RET PE ; E8
|
673 |
|
|
{I1DCNT {RETsPO== ir1 & ~pvf}} & I1_RET |// RET PO ; E0
|
674 |
|
|
{I1DCNT {RETsNZ== ir1 & ~zf }} & I1_RET |// RET NZ ; C0
|
675 |
|
|
{I1DCNT {RETsZ == ir1 & zf }} & I1_RET |// RET Z ; C8
|
676 |
|
|
{I1DCNT {EXs6SP7_HL == ir1}} & I1_RMW |// EX (SP),HL ; E3
|
677 |
|
|
{I1DCNT {DECs6HL7 == ir1}} & I1_RMW |// DEC (HL) ; 35
|
678 |
|
|
{I1DCNT {INCs6HL7 == ir1}} & I1_RMW |// INC (HL) ; 34
|
679 |
|
|
{I1DCNT {RSTs0 == ir1}} & I1_RST |// RST 0 ; C7
|
680 |
|
|
{I1DCNT {RSTs10H == ir1}} & I1_RST |// RST 10H ; D7
|
681 |
|
|
{I1DCNT {RSTs18H == ir1}} & I1_RST |// RST 18H ; DF
|
682 |
|
|
{I1DCNT {RSTs20H == ir1}} & I1_RST |// RST 20H ; E7
|
683 |
|
|
{I1DCNT {RSTs28H == ir1}} & I1_RST |// RST 28H ; EF
|
684 |
|
|
{I1DCNT {RSTs30H == ir1}} & I1_RST |// RST 30H ; F7
|
685 |
|
|
{I1DCNT {RSTs38H == ir1}} & I1_RST |// RST 38H ; FF
|
686 |
|
|
{I1DCNT {RSTs8H == ir1}} & I1_RST ;// RST 8H ; CF
|
687 |
|
|
|
688 |
|
|
//-------- CB decodes -----------------------
|
689 |
|
|
|
690 |
|
|
// First cut below
|
691 |
|
|
// CB_RLC = 7'b01_00_000, // these must be compaired with ir[9:3]
|
692 |
|
|
// CB_RRC = 7'b01_00_001, // these must be compaired with ir[9:3]
|
693 |
|
|
// CB_RL = 7'b01_00_010, // these must be compaired with ir[9:3]
|
694 |
|
|
// CB_RR = 7'b01_00_011, // these must be compaired with ir[9:3]
|
695 |
|
|
// CB_SLA = 7'b01_00_100, // these must be compaired with ir[9:3]
|
696 |
|
|
// CB_SRA = 7'b01_00_101, // these must be compaired with ir[9:3]
|
697 |
|
|
// CB_SLL = 7'b01_00_110, // these must be compaired with ir[9:3]
|
698 |
|
|
// CB_SRL = 7'b01_00_111, // these must be compaired with ir[9:3]
|
699 |
|
|
|
700 |
|
|
// CB_BIT = 4'b01_01, // these must be compaired with ir[9:6]
|
701 |
|
|
// CB_RES = 4'b01_10, // these must be compaired with ir[9:6]
|
702 |
|
|
// CB_SET = 4'b01_11, // these must be compaired with ir[9:6]
|
703 |
|
|
|
704 |
|
|
// note these are all read-modify-writ except CB_BIT
|
705 |
|
|
assign cb_mem = (CB_MEM == ir1[2:0]); // this must be compaired with ir[2:0]
|
706 |
|
|
|
707 |
|
|
// The ED Group
|
708 |
|
|
// These are the "unique instructions in the 46, 47 rows that NEED? to be implemented
|
709 |
|
|
// Not sure I want to worry about all undocumented stuff in these rows - hard to believe
|
710 |
|
|
// It will matter.(IM modes are very system dependent - hard to believe even a programmer
|
711 |
|
|
// would use undocumented instructions to muck with this stuff)
|
712 |
|
|
// reg 2 reg simply executed by ir2 logic
|
713 |
|
|
// ED_IMs0 = 10'h246// IM 0 ; ED 46 set IM0
|
714 |
|
|
// ED_LDsI_A = 10'h247// LD I,A ; ED 47 move a to I
|
715 |
|
|
// ED_IMs1 = 10'h256// IM 1 ; ED 56 set IM1
|
716 |
|
|
// ED_LDsA_I = 10'h257// LD A,I ; ED 57 move I to A
|
717 |
|
|
// ED_IMs2 = 10'h25E// IM 2 ; ED 5E set IM2
|
718 |
|
|
// ED_RRD = 10'h267// RRD ; ED 67 nibble roates A HL
|
719 |
|
|
// ED_RLD = 10'h26F// RLD ; ED 6F nibble roates A HL
|
720 |
|
|
|
721 |
|
|
// set (or clear) repeat flag at DEC_EB.
|
722 |
|
|
// set (or clear) inc flag at DEC_EB.
|
723 |
|
|
// seperate flows for LD, CP, IN, OUT.
|
724 |
|
|
// ED_LDI == ir1// LDI ; ED A0 These are block move
|
725 |
|
|
// ED_CPI == ir1// CPI ; ED A1 type insts that don't repeat
|
726 |
|
|
// ED_INI == ir1// INI ; ED A2
|
727 |
|
|
// ED_OUTI == ir1// OUTI ; ED A3
|
728 |
|
|
// ED_LDD == ir1// LDD ; ED A8
|
729 |
|
|
// ED_CPD == ir1// CPD ; ED A9
|
730 |
|
|
// ED_IND == ir1// IND ; ED AA
|
731 |
|
|
// ED_OUTD == ir1// OUTD ; ED AB
|
732 |
|
|
wire dec_blk_rpt =
|
733 |
|
|
ED_LDIR == ir1 |// LDIR ; ED B0 These are block move
|
734 |
|
|
ED_CPIR == ir1 |// CPIR ; ED B1 type insts that DO repeat
|
735 |
|
|
ED_INIR == ir1 |// INIR ; ED B2
|
736 |
|
|
ED_OTIR == ir1 |// OTIR ; ED B3
|
737 |
|
|
ED_LDDR == ir1 |// LDDR ; ED B8
|
738 |
|
|
ED_CPDR == ir1 |// CPDR ; ED B9
|
739 |
|
|
ED_INDR == ir1 |// INDR ; ED BA
|
740 |
|
|
ED_OTDR == ir1 ;// OTDR ; ED BB
|
741 |
|
|
wire ed_blk_mv = ED_LDIR == ir1 | ED_LDI == ir1 |
|
742 |
|
|
ED_LDDR == ir1 | ED_LDD == ir1 ;
|
743 |
|
|
wire ed_blk_cp = ED_CPIR == ir1 | ED_CPI == ir1 |
|
744 |
|
|
ED_CPDR == ir1 | ED_CPD == ir1 ;
|
745 |
|
|
wire ed_blk_in = ED_INIR == ir1 | ED_INI == ir1 |
|
746 |
|
|
ED_INDR == ir1 | ED_IND == ir1 ;
|
747 |
|
|
|
748 |
|
|
wire ed_blk_out = ED_OTIR == ir1 | ED_OUTI == ir1 |
|
749 |
|
|
ED_OTDR == ir1 | ED_OUTD == ir1 ;
|
750 |
|
|
|
751 |
|
|
wire dec_blk_io = ed_blk_in | ed_blk_in;
|
752 |
|
|
|
753 |
|
|
wire blk_done = ~blk_rpt_flg | beq0 & ceq0 | blk_io_flg & ceq0;
|
754 |
|
|
|
755 |
|
|
assign dec_blk_inc = ED_LDIR == ir1 |
|
756 |
|
|
ED_CPIR == ir1 |
|
757 |
|
|
ED_INIR == ir1 |
|
758 |
|
|
ED_OTIR == ir1 |
|
759 |
|
|
ED_LDI == ir1 |
|
760 |
|
|
ED_CPI == ir1 |
|
761 |
|
|
ED_INI == ir1 |
|
762 |
|
|
ED_OUTI == ir1 ;
|
763 |
|
|
|
764 |
|
|
|
765 |
|
|
//The ED70 instruction reads from I/O port C,
|
766 |
|
|
//but does not store the result.
|
767 |
|
|
//It just affects the flags. Hard to test. like the other IN x,(C) instruction.
|
768 |
|
|
//
|
769 |
|
|
//ED71 simply outs the value 0 to I/O port C.
|
770 |
|
|
// This suggests that we should decode as follows:
|
771 |
|
|
// I hope if I don't get all the IM duplicates right it won't be a tragedy
|
772 |
|
|
// ED_INsREG_6C7 = 7'b1001___000,// compair with {ir[7:6],ir[2:0]}
|
773 |
|
|
//
|
774 |
|
|
// ED_SBCsHL_REG = 8'b1001__0010, // compair with {ir[9:6],ir[3:0]}
|
775 |
|
|
// ED_ADCsHL_REG = 8'b1001__1010, // compair with {ir[9:6],ir[3:0]}
|
776 |
|
|
// ED_LDs6NN7_REG = 8'b1001__0011, // compair with {ir[9:6],ir[3:0]} REG = BC,DE,HL,SP
|
777 |
|
|
// ED_LDsREG_6NN7 = 8'b1001__1011, // compair with {ir[9:6],ir[3:0]} REG = BC,DE,HL,SP
|
778 |
|
|
// ED_NEG = 7'b1001___100, // compair with {ir[9:6],ir[2:0]} all A<= -A
|
779 |
|
|
// ED_RETN = 7'b1001___101, // compair with {ir[9:6],ir[2:0]} and !reti
|
780 |
|
|
wire ed_nn = ED_LDs6NN7_REG == {ir1[9:6],ir1[3:0]} |
|
781 |
|
|
ED_LDsREG_6NN7 == {ir1[9:6],ir1[3:0]} ;
|
782 |
|
|
|
783 |
|
|
// we use all these to enable interrupts
|
784 |
|
|
wire ed_retn = ED_RETN == {ir1[9:6],ir1[2:0]};
|
785 |
|
|
|
786 |
|
|
assign ed_dbl_rd = ED_LDsREG_6NN7 == {ir1[9:6],ir1[3:0]};
|
787 |
|
|
|
788 |
|
|
|
789 |
|
|
// assign cb_mem = CB_MEM = ir1[2:0]; // CB_MEM = 3'h110,
|
790 |
|
|
|
791 |
|
|
|
792 |
|
|
|
793 |
|
|
|
794 |
|
|
wire jmpr_true =
|
795 |
|
|
JRs$t2 == ir1 |
|
796 |
|
|
JRsC_$t2 == ir1 & fr[0] |
|
797 |
|
|
JRsNC_$t2 == ir1 & ~fr[0] |
|
798 |
|
|
JRsZ_$t2 == ir1 & fr[6] |
|
799 |
|
|
JRsNZ_$t2 == ir1 & ~fr[6] ;
|
800 |
|
|
|
801 |
|
|
//assign { sf, zf. f5f, hf, f3f, pvf, nf, cf} = fr;
|
802 |
|
|
wire callnn_true = CALLsC_NN == ir1 & cf |
|
803 |
|
|
CALLsNC_NN == ir1 & ~cf |
|
804 |
|
|
CALLsNN == ir1 |
|
805 |
|
|
CALLsNZ_NN == ir1 & ~zf |
|
806 |
|
|
CALLsPE_NN == ir1 & pvf |
|
807 |
|
|
CALLsPO_NN == ir1 & ~pvf|
|
808 |
|
|
CALLsP_NN == ir1 & ~sf |
|
809 |
|
|
CALLsZ_NN == ir1 & zf |
|
810 |
|
|
CALLsM_NN == ir1 & sf ;
|
811 |
|
|
|
812 |
|
|
wire jmpnn_true = JPsC == ir1 & cf |
|
813 |
|
|
JPsNC == ir1 & ~cf |
|
814 |
|
|
JP == ir1 |
|
815 |
|
|
JPsNZ == ir1 & ~zf |
|
816 |
|
|
JPsPE == ir1 & pvf |
|
817 |
|
|
JPsPO == ir1 & ~pvf|
|
818 |
|
|
JPsP == ir1 & ~sf |
|
819 |
|
|
JPsZ == ir1 & zf |
|
820 |
|
|
JPsM == ir1 & sf ;
|
821 |
|
|
|
822 |
|
|
// PUSHsAF == ir1
|
823 |
|
|
// PUSHsBC == ir1
|
824 |
|
|
// PUSHsDE == ir1
|
825 |
|
|
// PUSHsHL == ir1
|
826 |
|
|
|
827 |
|
|
wire os_a = LDs6BC7_A == ir1 | // LD (BC),A ; 02
|
828 |
|
|
LDs6DE7_A == ir1 | // LD (DE),A ; 12
|
829 |
|
|
LDs6HL7_A == ir1 | // LD (HL),A ; 77
|
830 |
|
|
LDs6NN7_A == ir1 | // LD (NN),A ; 32 XX XX
|
831 |
|
|
PUSHsAF == ir1 |
|
832 |
|
|
OUTs6N7_A == ir1 |
|
833 |
|
|
ED_OUTs6C7_REG == {ir1[9:6],ir1[2:0] && REG8_A == ir1[5:3]} ;
|
834 |
|
|
|
835 |
|
|
wire os_b = LDs6HL7_B == ir1 | // LD (HL),B ; 70
|
836 |
|
|
ED_LDs6NN7_REG == {ir1[9:6],ir1[3:0]} & DBL_REG_BC == ir1[5:4] |
|
837 |
|
|
ED_OUTs6C7_REG == {ir1[9:6],ir1[2:0]} & REG8_B == ir1[5:3] ;
|
838 |
|
|
|
839 |
|
|
wire os_c = LDs6HL7_C == ir1 | // LD (HL),C ; 71
|
840 |
|
|
PUSHsBC == ir1 | // PUSH BC
|
841 |
|
|
ED_OUTs6C7_REG == {ir1[9:6],ir1[2:0]} & REG8_C == ir1[5:3] ;
|
842 |
|
|
|
843 |
|
|
wire os_d = LDs6HL7_D == ir1 | // LD (HL),D ; 72
|
844 |
|
|
ED_LDs6NN7_REG == {ir1[9:6],ir1[3:0]} & DBL_REG_DE == ir1[5:4] |
|
845 |
|
|
ED_OUTs6C7_REG == {ir1[9:6],ir1[2:0]} & REG8_D == ir1[5:3] ;
|
846 |
|
|
|
847 |
|
|
|
848 |
|
|
wire os_e = LDs6HL7_E == ir1 | // LD (HL),E ; 73
|
849 |
|
|
PUSHsDE == ir1 | // PUSH DE
|
850 |
|
|
ED_OUTs6C7_REG == {ir1[9:6],ir1[2:0]} & REG8_E == ir1[5:3] ;
|
851 |
|
|
|
852 |
|
|
wire os_h = LDs6HL7_H == ir1 | // LD (HL),H ; 74
|
853 |
|
|
LDs6NN7_HL == ir1 | // LD (NN),HL ; 22 XX XX
|
854 |
|
|
ED_LDs6NN7_REG == {ir1[9:6],ir1[3:0]} & DBL_REG_HL == ir1[5:4] |
|
855 |
|
|
ED_OUTs6C7_REG == {ir1[9:6],ir1[2:0]} & REG8_H == ir1[5:3] ;
|
856 |
|
|
|
857 |
|
|
wire os_l = LDs6HL7_L == ir1 | // LD (HL),L ; 75
|
858 |
|
|
PUSHsHL == ir1 |
|
859 |
|
|
ED_OUTs6C7_REG == {ir1[9:6],ir1[2:0]} & REG8_L == ir1[5:3] ;
|
860 |
|
|
|
861 |
|
|
wire os_sp = ED_LDs6NN7_REG == {ir1[9:6],ir1[3:0]} & DBL_REG_SP == ir1[5:4];
|
862 |
|
|
|
863 |
|
|
wire os_f = PUSHsAF == ir1 ;
|
864 |
|
|
|
865 |
|
|
|
866 |
|
|
//---------------- inst hazard ----------------------------------------------------------
|
867 |
|
|
//
|
868 |
|
|
// On some reflection, I don't think I'm going to worry about this immediately - it
|
869 |
|
|
// should be easy to kludge in a fix if necessary -- and there are more important things
|
870 |
|
|
// todo. It is a very bad programming practice to muck with the instruction stream in any
|
871 |
|
|
// case -- I have to believe most target applications do not do this -- although I'll probably
|
872 |
|
|
// get hit pretty early with a instruction test that does. Oh well -- if that happens we fix
|
873 |
|
|
// it.
|
874 |
|
|
// Well -- think some here -- the hazard is because of a change in design.
|
875 |
|
|
// If used to any extent.. Somebody WILL
|
876 |
|
|
// want this to act the same way as the origional - even if the programming is "poor".
|
877 |
|
|
// >>>>>>>> bite the bullet and do it.
|
878 |
|
|
//
|
879 |
|
|
// if we do an operand store and the address == pc-1 its an inst hazard, We need to execute the
|
880 |
|
|
// store decrement pc and re-fetch. This is a high priority interrupt.
|
881 |
|
|
// what about multi-byte stores - like LDs6NN7_A or LDs6NN7_HL - i guess we do an IF - to start
|
882 |
|
|
// the pipe before the os -- same logic.
|
883 |
|
|
//
|
884 |
|
|
|
885 |
|
|
|
886 |
|
|
//-----------------data hazard ----------------------------------------------------------
|
887 |
|
|
//
|
888 |
|
|
// Issues here have evolved to a degree as the design progressed. However the
|
889 |
|
|
// Key has always been that for each instruction (no matter how complex) there
|
890 |
|
|
// is only a single state in which the previous instruction can also be active
|
891 |
|
|
// and that is the DEC_EXEC state. If there is a data hazard, we need to delay
|
892 |
|
|
// execution of that state until the ir2 execution completes (which it always does
|
893 |
|
|
// in a single tick). Note that only the RET instructions test the flag register
|
894 |
|
|
// on DEC_EXEC.
|
895 |
|
|
//
|
896 |
|
|
// WARNING: be very careful about this. Data hazard logic is very difficult to
|
897 |
|
|
// verify as there are so many instruction pairs to test.
|
898 |
|
|
//
|
899 |
|
|
// Situations 1) operand stores from ir1 when register is updated in ir2
|
900 |
|
|
// 2) flag tests when fr is being updated
|
901 |
|
|
// 3) sp issues see below LDsSP_HL DECsSP INCsSP
|
902 |
|
|
// ANY OTHERS ???
|
903 |
|
|
//
|
904 |
|
|
// upd_ar, upd_br, upd_cr, upd_dr, upd_er, upd_hr, upd_lr,upd_fr,
|
905 |
|
|
wire use_hl_exec = LDsSP_HL == ir1;
|
906 |
|
|
wire use_sp_exec = MEM_OFSP == next_mem_state |
|
907 |
|
|
MEM_OSSP == next_mem_state ;
|
908 |
|
|
wire upd_sp_exec = DECsSP == ir2 |
|
909 |
|
|
INCsSP == ir2 ;
|
910 |
|
|
|
911 |
|
|
|
912 |
|
|
|
913 |
|
|
wire use_fr_exec = ( RETsC == ir1 |
|
914 |
|
|
RETsM == ir1 |
|
915 |
|
|
RETsNC == ir1 |
|
916 |
|
|
RETsP == ir1 |
|
917 |
|
|
RETsPE == ir1 |
|
918 |
|
|
RETsPO == ir1 |
|
919 |
|
|
RETsNZ == ir1 |
|
920 |
|
|
RETsZ == ir1 ) ;
|
921 |
|
|
|
922 |
|
|
assign hazard = (dec_state == DEC_EXEC & exec_ir2 ) & ( upd_fr & use_fr_exec |
|
923 |
|
|
upd_ar & os_a |
|
924 |
|
|
upd_br & os_b |
|
925 |
|
|
upd_cr & os_c |
|
926 |
|
|
upd_dr & os_d |
|
927 |
|
|
upd_er & os_e |
|
928 |
|
|
upd_hr & os_h |
|
929 |
|
|
upd_lr & os_l |
|
930 |
|
|
upd_hr & use_hl_exec |
|
931 |
|
|
upd_lr & use_hl_exec |
|
932 |
|
|
upd_sp_exec & use_sp_exec );
|
933 |
|
|
|
934 |
|
|
|
935 |
|
|
|
936 |
|
|
|
937 |
|
|
|
938 |
|
|
|
939 |
|
|
// does not include extension stuff as we are mostly looking for hazards here
|
940 |
|
|
// course we do use these terms to build more decodes
|
941 |
|
|
//
|
942 |
|
|
wire opadr_bc = LDsA_6BC7 == ir1 | LDs6BC7_A == ir1;
|
943 |
|
|
wire opadr_de = LDsA_6DE7 == ir1 | LDs6DE7_A == ir1;
|
944 |
|
|
wire opadr_hl = LDsB_6HL7 == ir1 | ORs6HL7 == ir1 | LDs6HL7_B == ir1 |
|
945 |
|
|
LDsD_6HL7 == ir1 | LDsC_6HL7 == ir1 | LDs6HL7_C == ir1 |
|
946 |
|
|
LDsH_6HL7 == ir1 | LDsE_6HL7 == ir1 | LDs6HL7_D == ir1 |
|
947 |
|
|
ADDsA_6HL7 == ir1 | LDsL_6HL7 == ir1 | LDs6HL7_E == ir1 |
|
948 |
|
|
SUBs6HL7 == ir1 | LDsA_6HL7 == ir1 | LDs6HL7_H == ir1 |
|
949 |
|
|
ANDs6HL7 == ir1 | ADCsA_6HL7 == ir1 | LDs6HL7_L == ir1 |
|
950 |
|
|
XORs6HL7 == ir1 | SBCs6HL7 == ir1 | CPs6HL7 == ir1 ;
|
951 |
|
|
|
952 |
|
|
assign use_a = os_a;
|
953 |
|
|
assign use_b = os_b | opadr_bc;
|
954 |
|
|
assign use_c = os_c | opadr_bc;
|
955 |
|
|
assign use_d = os_d | opadr_de;
|
956 |
|
|
assign use_e = os_e | opadr_de;
|
957 |
|
|
assign use_h = os_h | opadr_hl;
|
958 |
|
|
assign use_l = os_l | opadr_hl;
|
959 |
|
|
|
960 |
|
|
|
961 |
|
|
|
962 |
|
|
assign use_flags = c_jmp8 | c_jmp4 | c_call | c_ret;
|
963 |
|
|
|
964 |
|
|
|
965 |
|
|
|
966 |
|
|
wire bc_eq0 = beq0 & ceq0;
|
967 |
|
|
// ??? not used ? why defined ?
|
968 |
|
|
//assign rpt_blk_mv = (blk_mv_reg ) & !bc_eq0 |
|
969 |
|
|
// (blk_cmp_reg) & !bc_eq0 & (nn[7:0] != 8'h0) |
|
970 |
|
|
// (blk_in_reg | blk_out_reg) & !b_eq0 ;
|
971 |
|
|
|
972 |
|
|
|
973 |
|
|
|
974 |
|
|
|
975 |
|
|
|
976 |
|
|
|
977 |
|
|
|
978 |
|
|
// BASIC ARCHITECTURE OF THIS FILE pc and sp not shown, but are inputs to src mux.
|
979 |
|
|
// _____ and may be updated from adder output.
|
980 |
|
|
// | |
|
981 |
|
|
// | | pc-1 register is required to implement relative jumps.
|
982 |
|
|
// | |
|
983 |
|
|
// _____ |lit | |\
|
984 |
|
|
// | | | | | \
|
985 |
|
|
// | | |src2 | | \ _____ _____
|
986 |
|
|
// | | | |----->| | | | | |
|
987 |
|
|
// |src | |_____| |adder|------->| | | |
|
988 |
|
|
// |mux | | | | | | |
|
989 |
|
|
// | |------------------->| / |2/1 |------->|wb |
|
990 |
|
|
// | | | | / |mux | |adr |
|
991 |
|
|
// |_____| | |/ | | | |
|
992 |
|
|
// ------------------->| | | |
|
993 |
|
|
// |_____| |_____|
|
994 |
|
|
// MEM_NOP
|
995 |
|
|
// MEM_IFPP1 MEM_OFIXpD MEM_CALL MEM_IFRST MEM_OFHL_PM MEM_IOF_C
|
996 |
|
|
// MEM_OS1, MEM_OSIXpD MEM_OSNN, MEM_IFREL_N MEM_OSHL_PM MEM_IOS_C
|
997 |
|
|
// MEM_OF1, MEM_OSADR MEM_OFNN MEM_JMPHL MEM_OSDE_PM MEM_IOF_N
|
998 |
|
|
// MEM_OFSP MEM_OSSP_PCM2 MEM_OFADRP1 MEM_IFNN MEM_INTA MEM_IOS_N
|
999 |
|
|
// MEM_OSSP MEM_OSSP_P MEM_OSADRP1 MEM_IFINT MEM_OS_HL_N
|
1000 |
|
|
//
|
1001 |
|
|
|
1002 |
|
|
wire src_sp = next_mem_state == MEM_OF1 & EXs6SP7_HL == ir1 | //special case rmw
|
1003 |
|
|
next_mem_state == MEM_OFSP |
|
1004 |
|
|
next_mem_state == MEM_OSSP |
|
1005 |
|
|
next_mem_state == MEM_CALL ;
|
1006 |
|
|
wire src_pc = next_mem_state == MEM_IFPP1 |
|
1007 |
|
|
next_mem_state == MEM_IFREL_N ;
|
1008 |
|
|
|
1009 |
|
|
wire src_nn = next_mem_state == MEM_IFNN |
|
1010 |
|
|
next_mem_state == MEM_OSNN |
|
1011 |
|
|
next_mem_state == MEM_OFNN ;
|
1012 |
|
|
|
1013 |
|
|
|
1014 |
|
|
wire src_de = dec_state == DEC_EXEC & LDsA_6DE7 == ir1 | // MEM_OS1 MEM_OF1
|
1015 |
|
|
dec_state == DEC_EXEC & LDs6DE7_A == ir1 | // are both true at this time
|
1016 |
|
|
next_mem_state == MEM_OSDE_PM ;
|
1017 |
|
|
wire src_bc = dec_state == DEC_EXEC & LDsA_6BC7 == ir1 |
|
1018 |
|
|
dec_state == DEC_EXEC & LDs6BC7_A == ir1 |
|
1019 |
|
|
next_mem_state ==MEM_IOF_C |
|
1020 |
|
|
next_mem_state ==MEM_IOS_C ;
|
1021 |
|
|
|
1022 |
|
|
|
1023 |
|
|
// don't forget that hl source can be modified by prefix
|
1024 |
|
|
// this gets messy as we use wb_adr for some of these.
|
1025 |
|
|
//
|
1026 |
|
|
wire src_hl = next_mem_state == MEM_OF1 &
|
1027 |
|
|
(dec_state == DEC_EXEC) &
|
1028 |
|
|
!src_de & !src_bc & !src_sp |
|
1029 |
|
|
next_mem_state == MEM_OS1 &
|
1030 |
|
|
(dec_state == DEC_EXEC) &
|
1031 |
|
|
!src_de & !src_bc |
|
1032 |
|
|
next_mem_state == MEM_OFHL_PM |
|
1033 |
|
|
next_mem_state == MEM_OSHL_PM |
|
1034 |
|
|
next_mem_state == MEM_OS_HL_N |
|
1035 |
|
|
next_mem_state == MEM_JMPHL ;
|
1036 |
|
|
|
1037 |
|
|
wire src_ix = next_mem_state == MEM_OFIXpD & ir1dd |
|
1038 |
|
|
next_mem_state == MEM_OSIXpD & ir1dd ;
|
1039 |
|
|
|
1040 |
|
|
wire src_iy = next_mem_state == MEM_OFIXpD & ir1fd |
|
1041 |
|
|
next_mem_state == MEM_OSIXpD & ir1fd ;
|
1042 |
|
|
|
1043 |
|
|
wire src_adr = next_mem_state == MEM_OFADRP1 |
|
1044 |
|
|
next_mem_state == MEM_OSADRP1 |
|
1045 |
|
|
next_mem_state == MEM_NOP |
|
1046 |
|
|
next_mem_state == MEM_OSADR ;
|
1047 |
|
|
|
1048 |
|
|
wire src_int = next_mem_state == MEM_IOF_N |
|
1049 |
|
|
next_mem_state == MEM_IOS_N ;
|
1050 |
|
|
|
1051 |
|
|
|
1052 |
|
|
|
1053 |
|
|
wire src_mux = {16{ src_sp }} & sp |
|
1054 |
|
|
{16{ src_pc }} & pc |
|
1055 |
|
|
{16{ src_nn }} & nn |
|
1056 |
|
|
{16{ src_hl }} & hl |
|
1057 |
|
|
{16{ src_de }} & de |
|
1058 |
|
|
{16{ src_bc }} & bc |
|
1059 |
|
|
{16{ src_ix }} & ixr |
|
1060 |
|
|
{16{ src_iy }} & iyr |
|
1061 |
|
|
{16{ src_adr }} & wb_adr |
|
1062 |
|
|
{16{ src_int }} & { intr, nn[15:8] } |
|
1063 |
|
|
{16{next_mem_state == MEM_IFRST}} & {10'h0, ir1[6:4], 3'h0} ;
|
1064 |
|
|
|
1065 |
|
|
wire block_mv_inc = (dec_state == DEC_ED) ? dec_blk_inc : blk_inc_flg; // flag set at DEC_ED
|
1066 |
|
|
|
1067 |
|
|
|
1068 |
|
|
|
1069 |
|
|
wire inc_s2 = next_mem_state ==MEM_OFADRP1 |
|
1070 |
|
|
next_mem_state ==MEM_OSADRP1 |
|
1071 |
|
|
next_mem_state ==MEM_OFHL_PM & block_mv_inc |
|
1072 |
|
|
next_mem_state ==MEM_OSHL_PM & block_mv_inc |
|
1073 |
|
|
next_mem_state ==MEM_OSDE_PM & block_mv_inc |
|
1074 |
|
|
next_mem_state ==MEM_OFSP |
|
1075 |
|
|
next_mem_state ==MEM_IFPP1 |
|
1076 |
|
|
next_mem_state ==MEM_OSSP_PCM2 |
|
1077 |
|
|
next_mem_state ==MEM_OSSP_P ;
|
1078 |
|
|
|
1079 |
|
|
wire dec_s2 = next_mem_state ==MEM_OFHL_PM & ~block_mv_inc |
|
1080 |
|
|
next_mem_state ==MEM_OSHL_PM & ~block_mv_inc |
|
1081 |
|
|
next_mem_state ==MEM_OSDE_PM & ~block_mv_inc |
|
1082 |
|
|
next_mem_state == MEM_OFSP ;
|
1083 |
|
|
|
1084 |
|
|
|
1085 |
|
|
wire reln_s2 = next_mem_state == MEM_IFREL_N |
|
1086 |
|
|
next_mem_state == MEM_OFIXpD |
|
1087 |
|
|
next_mem_state == MEM_OSIXpD ;
|
1088 |
|
|
|
1089 |
|
|
wire src2 = {16{ inc }} & 16'h0001 |
|
1090 |
|
|
{16{ dec }} & 16'hffff |
|
1091 |
|
|
{16{ rel }} & {{8{nn[15]}},nn[15:8]}|
|
1092 |
|
|
{16{~(rel_jmp|inc|dec)}} & 16'h0 ;
|
1093 |
|
|
|
1094 |
|
|
wire adr_alu = src2 + src_mux;
|
1095 |
|
|
|
1096 |
|
|
|
1097 |
|
|
wire pre_inc_dec = next_mem_state == MEM_CALL |
|
1098 |
|
|
next_mem_state == MEM_OSSP_P |
|
1099 |
|
|
next_mem_state == MEM_OSSP ;
|
1100 |
|
|
|
1101 |
|
|
|
1102 |
|
|
wire mux21 = pre_inc_dec ? alu : src_mux;
|
1103 |
|
|
|
1104 |
|
|
assign wb_rdy_nhz = (!wb_cyc | wb_ack ) & ~hazard; // wishbone ready with no hazard
|
1105 |
|
|
wire wb_rdy = !wb_cyc | wb_ack;
|
1106 |
|
|
|
1107 |
|
|
assign we_next = next_mem_state == MEM_OS1 |
|
1108 |
|
|
next_mem_state == MEM_OSP |
|
1109 |
|
|
next_mem_state == MEM_OSIXpD |
|
1110 |
|
|
next_mem_state == MEM_OSADR |
|
1111 |
|
|
next_mem_state == MEM_OSSP_PCM2 |
|
1112 |
|
|
next_mem_state == MEM_OSSP_P |
|
1113 |
|
|
next_mem_state == MEM_CALL |
|
1114 |
|
|
next_mem_state == MEM_OSNN |
|
1115 |
|
|
next_mem_state == MEM_OSADRP1 |
|
1116 |
|
|
next_mem_state == MEM_OSHL_PM |
|
1117 |
|
|
next_mem_state == MEM_OSDE_PM |
|
1118 |
|
|
next_mem_state == MEM_OS_HL_N |
|
1119 |
|
|
next_mem_state == MEM_IOS_C |
|
1120 |
|
|
next_mem_state == MEM_IOS_N ;
|
1121 |
|
|
|
1122 |
|
|
|
1123 |
|
|
//-------1---------2---------3--------State Machines-------6---------7---------8---------9--------0
|
1124 |
|
|
// we do this just to save virtual paper below.
|
1125 |
|
|
// 6 5 4 15
|
1126 |
|
|
assign {next_dec_state, next_mem_state, next_pipe_state} = next_state;
|
1127 |
|
|
|
1128 |
|
|
always @(ir1 or wb_int or inst_haz or wb_int or dec_state or mem_exec_dec or cb_mem or ed_nn or
|
1129 |
|
|
ed_blk_cp or ed_blk_in or ed_blk_out or ed_retn or ed_blk_mv or ed_dbl_rd or blk_done or
|
1130 |
|
|
fr or jmpr_true or callnn_true or jmpnn_true )
|
1131 |
|
|
|
1132 |
|
|
begin
|
1133 |
|
|
case (dec_state)
|
1134 |
|
|
DEC_IDLE: next_state = {DEC_IF1, MEM_NOP, IPIPE_NOP};
|
1135 |
|
|
|
1136 |
|
|
DEC_HALT:
|
1137 |
|
|
if (wb_int) next_state = {DEC_INT1,MEM_NOP ,IPIPE_NOP};// stay here until interrupt or reset
|
1138 |
|
|
else next_state = {DEC_HALT,MEM_NOP ,IPIPE_NOP};
|
1139 |
|
|
DEC_IF1 : next_state = {DEC_IF2 ,MEM_IFPP1 ,IPIPE_NOP};
|
1140 |
|
|
DEC_IF2 : next_state = {DEC_EXEC,MEM_IFPP1 ,IPIPE_EN1};
|
1141 |
|
|
DEC_IF2A: next_state = {DEC_EXEC,MEM_IFPP1 ,IPIPE_NOP};
|
1142 |
|
|
DEC_EXEC:
|
1143 |
|
|
if (inst_haz) next_state = {DEC_IF1, MEM_DECPC , IPIPE_NOP};
|
1144 |
|
|
else if (wb_int) next_state = {DEC_INT1,MEM_NOP ,IPIPE_NOP};
|
1145 |
|
|
else
|
1146 |
|
|
case (mem_exec_dec) // full case but can all tools understand ? just make a default
|
1147 |
|
|
I1_CB : next_state = {DEC_CB, MEM_IFPP1, IPIPE_EN1};// IF2_NOP -> nn <= (MEM)
|
1148 |
|
|
I1_DDFD : next_state = {DEC_DDFD, MEM_IFPP1, IPIPE_EN1};// gets real inst
|
1149 |
|
|
I1_ED : next_state = {DEC_ED, MEM_IFPP1, IPIPE_EN1};
|
1150 |
|
|
I1_JMP : next_state = {DEC_IF2, MEM_JMPHL, IPIPE_NOP};
|
1151 |
|
|
I1_N : next_state = {DEC_N, MEM_IFPP1, IPIPE_ENN};
|
1152 |
|
|
I1_NN : next_state = {DEC_NN, MEM_IFPP1, IPIPE_ENN};
|
1153 |
|
|
I1_OF : next_state = {DEC_OF, MEM_OF1, IPIPE_EN12};//transfer, don't activate
|
1154 |
|
|
I1_OS : next_state = {DEC_IF2, MEM_OS1, IPIPE_EN1}; // -> ir2_NOP
|
1155 |
|
|
I1_POP : next_state = {DEC_POP, MEM_OFSP, IPIPE_EN12};
|
1156 |
|
|
I1_PUSH : next_state = {DEC_PUSH, MEM_OSSP, IPIPE_EN12};
|
1157 |
|
|
I1_RET : next_state = {DEC_RET, MEM_OFSP, IPIPE_EN12};
|
1158 |
|
|
I1_RMW : next_state = {DEC_RMW, MEM_OF1, IPIPE_EN12};//can't activate till data rdy
|
1159 |
|
|
I1_RST : next_state = {DEC_IF2, MEM_IFRST, IPIPE_ENN};
|
1160 |
|
|
I1_R2R : next_state = {DEC_EXEC, MEM_IFPP1, IPIPE_EN12A2};
|
1161 |
|
|
default : next_state = {DEC_EXEC, MEM_IFPP1, IPIPE_EN12A2}; //I1_R2R
|
1162 |
|
|
endcase
|
1163 |
|
|
DEC_CB: if (cb_mem) next_state = {DEC_CBM, MEM_OF1, IPIPE_EN12};
|
1164 |
|
|
else next_state = {DEC_EXEC, MEM_IFPP1, IPIPE_EN12A2};
|
1165 |
|
|
DEC_DDFD: // except for CB and EB these all act the same H and L get modified by prefix
|
1166 |
|
|
case (mem_exec_dec)
|
1167 |
|
|
I1_CB : next_state = {DEC_PFxCB,MEM_IFPP1, IPIPE_EN1};// IF2_NOP -> nn <= (MEM)
|
1168 |
|
|
I1_DDFD : next_state = {DEC_DDFD, MEM_IFPP1, IPIPE_EN1};
|
1169 |
|
|
I1_ED : next_state = {DEC_ED, MEM_IFPP1, IPIPE_EN1};//How do we clear the prefix?
|
1170 |
|
|
I1_JMP : next_state = {DEC_IF2, MEM_JMPHL, IPIPE_NOP};
|
1171 |
|
|
I1_N : next_state = {DEC_N, MEM_IFPP1, IPIPE_ENN};
|
1172 |
|
|
I1_NN : next_state = {DEC_NN, MEM_IFPP1, IPIPE_ENN};
|
1173 |
|
|
I1_OF : next_state = {DEC_DDOF, MEM_IFPP1, IPIPE_ENN}; // d to nn - need to get d
|
1174 |
|
|
// LD A,(BC) LD A,(DE) will
|
1175 |
|
|
// become ix+d - do we care ?
|
1176 |
|
|
// i hope not
|
1177 |
|
|
I1_OS : next_state = {DEC_DDOS, MEM_IFPP1, IPIPE_ENN}; // d to nn
|
1178 |
|
|
I1_POP : next_state = {DEC_POP, MEM_OFSP, IPIPE_EN12};
|
1179 |
|
|
I1_PUSH : next_state = {DEC_PUSH, MEM_OSSP, IPIPE_EN12};
|
1180 |
|
|
I1_RET : next_state = {DEC_RET, MEM_OFSP, IPIPE_EN12};
|
1181 |
|
|
I1_RMW : next_state = {DEC_RMW, MEM_OF1, IPIPE_EN12};
|
1182 |
|
|
I1_RST : next_state = {DEC_IF2, MEM_IFRST, IPIPE_NOP}; // just dump next inst
|
1183 |
|
|
I1_R2R : next_state = {DEC_EXEC, MEM_IFPP1, IPIPE_EN12A2}; //I1_R2R
|
1184 |
|
|
default : next_state = {DEC_EXEC, MEM_IFPP1, IPIPE_EN12A2}; //I1_R2R
|
1185 |
|
|
endcase
|
1186 |
|
|
DEC_ED:
|
1187 |
|
|
if (ed_nn) next_state = {DEC_EDNN1, MEM_IFPP1, IPIPE_ENN};
|
1188 |
|
|
// we need to set inc and io and repeat flags on this state for continued block
|
1189 |
|
|
// processing -- keep the states of this machine somewhat manageable.
|
1190 |
|
|
else if (ed_blk_cp ) next_state = {DEC_EDBCP1, MEM_OFHL_PM, IPIPE_EN12};// MEM_OFHL_PM triggers --BC
|
1191 |
|
|
else if (ed_blk_in ) next_state = {DEC_EDBIN1, MEM_IOF_C, IPIPE_EN12};// MEM_IOF_C triggers --B
|
1192 |
|
|
else if (ed_blk_out) next_state = {DEC_EDBOUT1,MEM_OFHL_PM, IPIPE_EN12};
|
1193 |
|
|
else if (ed_blk_mv ) next_state = {DEC_EDBMV1, MEM_OFHL_PM, IPIPE_EN12};
|
1194 |
|
|
else if (ed_retn ) next_state = {DEC_RET, MEM_OFSP, IPIPE_EN12};// see int logic below
|
1195 |
|
|
else next_state = {DEC_EXEC, MEM_IFPP1, IPIPE_EN12A2};
|
1196 |
|
|
// double register reads and writes here
|
1197 |
|
|
DEC_EDNN1: next_state = {DEC_EDNN2, MEM_NOP, IPIPE_ENN}; // address to nn
|
1198 |
|
|
DEC_EDNN2:
|
1199 |
|
|
if (ed_dbl_rd) next_state = {DEC_EDRD1, MEM_OFNN, IPIPE_NOP};
|
1200 |
|
|
else next_state = {DEC_EDWR, MEM_OSNN, IPIPE_NOP};// OSNN selects data ok?
|
1201 |
|
|
DEC_EDRD1: next_state = {DEC_EDRD2, MEM_OFADRP1, IPIPE_ENN}; // 1st byte 2n
|
1202 |
|
|
DEC_EDRD2: next_state = {DEC_IF2, MEM_IFPP1, IPIPE_ENNA2}; // 2nd byte 2nn
|
1203 |
|
|
DEC_EDWR: next_state = {DEC_IF1, MEM_OSADRP1, IPIPE_NOP};
|
1204 |
|
|
|
1205 |
|
|
// ED block moves
|
1206 |
|
|
DEC_EDBCP1:
|
1207 |
|
|
if (blk_done) next_state = {DEC_EXEC, MEM_IFPP1,IPIPE_ENNA2};
|
1208 |
|
|
else if(wb_int) next_state = {DEC_INT1, MEM_NOP, IPIPE_ENNA2};
|
1209 |
|
|
else next_state = {DEC_EDBCP2, MEM_NOP, IPIPE_ENNA2};//set flags
|
1210 |
|
|
DEC_EDBCP2: next_state = {DEC_EDBCP3, MEM_NOP, IPIPE_NOP};//wait for fr. alu_out is slow
|
1211 |
|
|
DEC_EDBCP3: if (fr[7]) next_state = {DEC_EXEC , MEM_IFPP1, IPIPE_NOP};
|
1212 |
|
|
else next_state = {DEC_EDBCP1, MEM_OFHL_PM, IPIPE_NOP};
|
1213 |
|
|
|
1214 |
|
|
DEC_EDBIN1: next_state = {DEC_EDBIN2, MEM_NOP, IPIPE_ENN};
|
1215 |
|
|
DEC_EDBIN2: if (blk_done) next_state = {DEC_IF2A, MEM_OSHL_PM,IPIPE_NOP}; // implies nn
|
1216 |
|
|
else if (wb_int) next_state = {DEC_INT1, MEM_OSHL_PM,IPIPE_NOP};
|
1217 |
|
|
else next_state = {DEC_EDBIN1,MEM_OSHL_PM,IPIPE_NOP};//set flags
|
1218 |
|
|
DEC_EDBIN3: next_state = {DEC_EDBIN1, MEM_IOF_C, IPIPE_NOP};
|
1219 |
|
|
|
1220 |
|
|
DEC_EDBOUT1: next_state = {DEC_EDBOUT2, MEM_NOP, IPIPE_ENN};
|
1221 |
|
|
DEC_EDBOUT2:if (blk_done) next_state = {DEC_EXEC, MEM_IOS_C,IPIPE_NOP};
|
1222 |
|
|
else if (wb_int) next_state = {DEC_INT1, MEM_IOS_C,IPIPE_NOP}; // DEC_EDBOUT: if (blk_rpt)
|
1223 |
|
|
else next_state = {DEC_EDBOUT3,MEM_IOS_C,IPIPE_NOP};
|
1224 |
|
|
|
1225 |
|
|
DEC_EDBOUT3: next_state = {DEC_EDBOUT1,MEM_OFHL_PM, IPIPE_NOP};
|
1226 |
|
|
|
1227 |
|
|
DEC_EDBMV1: next_state = {DEC_EDBMV2, MEM_NOP, IPIPE_ENN};
|
1228 |
|
|
DEC_EDBMV2: if (blk_done) next_state = {DEC_EXEC, MEM_OSDE_PM,IPIPE_NOP};
|
1229 |
|
|
else if (wb_int) next_state = {DEC_INT1, MEM_OSDE_PM,IPIPE_NOP}; //DEC_EDBOUT: if (blk_rpt)
|
1230 |
|
|
else next_state = {DEC_EDBMV3,MEM_OSDE_PM,IPIPE_NOP};
|
1231 |
|
|
|
1232 |
|
|
DEC_EDBMV3: next_state = {DEC_EDBMV1,MEM_OFHL_PM, IPIPE_NOP};
|
1233 |
|
|
|
1234 |
|
|
DEC_N:
|
1235 |
|
|
if (INsA_6N7== ir1) next_state = {DEC_NIN, MEM_IOF_N, IPIPE_EN12};
|
1236 |
|
|
else if (OUTs6N7_A==ir1) next_state = {DEC_IF1, MEM_IOS_N, IPIPE_EN12};
|
1237 |
|
|
else if (LDs6HL7_N==ir1) next_state = {DEC_IF1, MEM_OS_HL_N, IPIPE_EN12};
|
1238 |
|
|
else if (jmpr_true) next_state = {DEC_IF2, MEM_IFREL_N, IPIPE_NOP};
|
1239 |
|
|
else next_state = {DEC_EXEC, MEM_IFPP1, IPIPE_EN12A2};//r2r or false jumps
|
1240 |
|
|
DEC_NIN: next_state = {DEC_IF2, MEM_IFPP1, IPIPE_ENNA2};
|
1241 |
|
|
|
1242 |
|
|
|
1243 |
|
|
//ISSUES: LDsSP_NN - load commanded from ir2 decode? and mechaninsm for updating PC on
|
1244 |
|
|
// JMP and CALL
|
1245 |
|
|
// on CALL We have IFNN for JMP
|
1246 |
|
|
// For CALL Use MEM_CALL to transfer pc<=nn, nn<=pc, adr<=sp then MEM_OSSP then IFPP1
|
1247 |
|
|
// For LDsSP_NN yes update from ir2 decode.
|
1248 |
|
|
DEC_NN:
|
1249 |
|
|
if (callnn_true) next_state = {DEC_NNCALL1, MEM_NOP, IPIPE_ENN}; // this gets new adr in nn
|
1250 |
|
|
// if we store from nn we can't do
|
1251 |
|
|
// a mem op now
|
1252 |
|
|
|
1253 |
|
|
else if (jmpnn_true) next_state = {DEC_NNJMP, MEM_NOP, IPIPE_ENN}; // gotta get nn before we can
|
1254 |
|
|
// transfer to adr.
|
1255 |
|
|
else if (LDs6NN7_A==ir1) next_state = {DEC_NNOS3, MEM_IFPP1, IPIPE_ENN};
|
1256 |
|
|
else if (LDs6NN7_HL==ir1) next_state = {DEC_NNOS1, MEM_IFPP1, IPIPE_ENN};
|
1257 |
|
|
else if (LDsA_6NN7==ir1) next_state = {DEC_NNOF3, MEM_IFPP1, IPIPE_ENN};
|
1258 |
|
|
else if (LDsHL_6NN7==ir1) next_state = {DEC_NNOF1, MEM_IFPP1, IPIPE_ENN};
|
1259 |
|
|
else next_state = { DEC_IF2, MEM_IFPP1, IPIPE_ENNEN2A2};
|
1260 |
|
|
|
1261 |
|
|
DEC_NNCALL1: next_state = {DEC_NNCALL2, MEM_CALL , IPIPE_NOP};
|
1262 |
|
|
DEC_NNCALL2: next_state = {DEC_IF1, MEM_OSSP, IPIPE_ENN};//A1 activates r2r xfers from ir1
|
1263 |
|
|
DEC_NNJMP: next_state = {DEC_IF2, MEM_IFNN , IPIPE_NOP};
|
1264 |
|
|
|
1265 |
|
|
// ISSUE: we blow out ir1 here - so need to keep some status to execute OSNN2.
|
1266 |
|
|
// general solution if not DEC_EXEC we get op frmo nn high byte.
|
1267 |
|
|
// note that first MEM_OSNN trabsferrs nn to wb_adr.
|
1268 |
|
|
DEC_NNOS1: next_state = {DEC_NNOS2, MEM_OSNN, IPIPE_EN1};
|
1269 |
|
|
DEC_NNOS2: next_state = {DEC_IF2A, MEM_OSNN, IPIPE_NOP};
|
1270 |
|
|
DEC_NNOS3: next_state = {DEC_IF2A, MEM_OSNN, IPIPE_EN1};
|
1271 |
|
|
|
1272 |
|
|
DEC_NNOF1: next_state = {DEC_NNOF2, MEM_OFNN, IPIPE_EN12};
|
1273 |
|
|
DEC_NNOF2: next_state = {DEC_NNOF4, MEM_OFNN, IPIPE_ENN};
|
1274 |
|
|
DEC_NNOF3: next_state = {DEC_NNOF4, MEM_OFNN, IPIPE_EN12};
|
1275 |
|
|
DEC_NNOF4: next_state = {DEC_EXEC, MEM_IFPP1, IPIPE_ENNA2};
|
1276 |
|
|
|
1277 |
|
|
DEC_DDOS: next_state = {DEC_IF2A, MEM_OSIXpD, IPIPE_EN12};
|
1278 |
|
|
DEC_DDOF: next_state = {DEC_OF , MEM_OFIXpD, IPIPE_EN12};
|
1279 |
|
|
|
1280 |
|
|
|
1281 |
|
|
DEC_OF: next_state = {DEC_EXEC, MEM_IFPP1 , IPIPE_ENNA2};
|
1282 |
|
|
DEC_POP: next_state = {DEC_NNOF4, MEM_OFSP, IPIPE_ENN };
|
1283 |
|
|
DEC_PUSH: next_state = {DEC_IF2A , MEM_OSSP, IPIPE_NOP };
|
1284 |
|
|
|
1285 |
|
|
|
1286 |
|
|
DEC_RET: next_state = { DEC_RET2, MEM_OFSP, IPIPE_ENN };
|
1287 |
|
|
DEC_RET2: next_state = { DEC_NNCALL2, MEM_NOP, IPIPE_ENN };
|
1288 |
|
|
// blow off a tick so we don't gronk adr
|
1289 |
|
|
DEC_RMW: next_state = {DEC_RMW2, MEM_NOP, IPIPE_ENNA2}; //activate
|
1290 |
|
|
DEC_RMW2: next_state = {DEC_IF1 , MEM_OSADR, IPIPE_NOP }; // from nn
|
1291 |
|
|
|
1292 |
|
|
|
1293 |
|
|
// IF memory -- rmw else these are all reg 2 reg
|
1294 |
|
|
DEC_CBM: if (CB_BIT==ir1[9:6]) next_state = {DEC_IF2, MEM_IFPP1, IPIPE_ENNA2};
|
1295 |
|
|
else next_state = {DEC_RMW2 , MEM_NOP, IPIPE_ENNA2};
|
1296 |
|
|
|
1297 |
|
|
// The DDCB anf FDCB all assume memory operands
|
1298 |
|
|
// These beauties always rmw memory. If a register op is default, they also
|
1299 |
|
|
// update the register. Programmers think of this as 2 ops for the price of 1.
|
1300 |
|
|
// unfortunately it is 2 ops for the price of 4.-- its not the number of lines
|
1301 |
|
|
// of assembler code that count but the number of bytes assembled. Oh well I signed
|
1302 |
|
|
// up for this...... and had a notion of what I was getting into.
|
1303 |
|
|
//
|
1304 |
|
|
DEC_PFxCB: next_state = { DEC_PFxCB2, MEM_IFPP1, IPIPE_ENN}; // this gets d
|
1305 |
|
|
DEC_PFxCB2: next_state = { DEC_PFxCB3, MEM_OFIXpD, IPIPE_EN1}; //actual inst
|
1306 |
|
|
DEC_PFxCB3: next_state = { DEC_PFxCB4, MEM_IFPP1, IPIPE_ENNEN2A2};
|
1307 |
|
|
DEC_PFxCB4: next_state = { DEC_IF2A, MEM_OSADR, IPIPE_EN1}; //execute ir2
|
1308 |
|
|
|
1309 |
|
|
// crap gotta subtract 2 (we always increment pc 2 times relative to the inst
|
1310 |
|
|
// that got interrupted. also can't push and dec pc without 2 adders.
|
1311 |
|
|
// choices: 1) fix up pc in 2 ticks 2) fix in 1 tick 3) add adder and do it fast
|
1312 |
|
|
// if there's anyone who knows is there anyone who cares.
|
1313 |
|
|
// guess I'll do it fast -- just a 16 bit subtractor. heck silicon is
|
1314 |
|
|
// cheap.
|
1315 |
|
|
DEC_INT1: next_state <= {DEC_INT2, MEM_OSSP_PCM2, IPIPE_NOP}; //must derement PC
|
1316 |
|
|
DEC_INT2: next_state <= {DEC_INT3, MEM_OSSP_P, IPIPE_NOP}; //must dec sp and PC 2 ops?
|
1317 |
|
|
DEC_INT3: next_state <= {DEC_INT4, MEM_INTA, IPIPE_NOP};
|
1318 |
|
|
DEC_INT4: next_state <= {DEC_INT5, MEM_NOP, IPIPE_ENN};
|
1319 |
|
|
DEC_INT5: next_state <= {DEC_IF2, MEM_IFINT, IPIPE_NOP};
|
1320 |
|
|
default: next_state <= {DEC_IDLE, MEM_NOP, IPIPE_NOP};
|
1321 |
|
|
endcase
|
1322 |
|
|
end
|
1323 |
|
|
|
1324 |
|
|
|
1325 |
|
|
always @(posedge clk or posedge rst)
|
1326 |
|
|
if (rst) dec_state <= DEC_IDLE;
|
1327 |
|
|
else if (wb_rdy_nhz ) dec_state <= next_dec_state;
|
1328 |
|
|
|
1329 |
|
|
|
1330 |
|
|
//-----------------------instruction register #1 ----------------------------------
|
1331 |
|
|
// // next_pipe_state {ir1,ir2,nn,act_ir2}
|
1332 |
|
|
|
1333 |
|
|
wire update_prefix = dec_state == DEC_EXEC | dec_state == DEC_DDFD;
|
1334 |
|
|
|
1335 |
|
|
always @(posedge clk or posedge rst)
|
1336 |
|
|
if (rst) ir1 <= NOP;
|
1337 |
|
|
else if (wb_rdy_nhz & next_pipe_state[3]) ir1 <= {2'b0, wb_dat_i} ;
|
1338 |
|
|
else if ( wb_rdy_nhz &update_prefix ) ir1 <= {ir1[7:0]==8'hed, ir1[7:0]==8'hcd, ir1[7:0]};
|
1339 |
|
|
|
1340 |
|
|
//----------- prefix states -----------------------------------------
|
1341 |
|
|
// strings of prefix insts are ignored up to last one. Also dded and fded are ignored
|
1342 |
|
|
// but ddcd and fdcd are defined prefix sets.
|
1343 |
|
|
//
|
1344 |
|
|
always @(posedge clk)
|
1345 |
|
|
if (wb_rdy_nhz & next_pipe_state[3]) {ir1dd, ir1fd } <= 2'b0;
|
1346 |
|
|
else if ( wb_rdy_nhz & update_prefix )
|
1347 |
|
|
{ir1dd, ir1fd } <= {ir1dd | (ir1[7:0]==8'hdd ) & (ir1[7:0]!=8'hed) & (ir1[7:0]!=8'hfd),
|
1348 |
|
|
ir1fd | (ir1[7:0]==8'hfd ) & (ir1[7:0]!=8'hed) & (ir1[7:0]!=8'hdd) };
|
1349 |
|
|
|
1350 |
|
|
//------------------- inst reg #2 -----------------------------------
|
1351 |
|
|
// This stuff is key to the data hazard logic. Hazards arise only AFTER activation of
|
1352 |
|
|
// a previous instruction. Fundamentally all state changes related to ir1 may be
|
1353 |
|
|
// delayed eithor by a delay in wb response, or by a hazard. Ir2 state changes
|
1354 |
|
|
// are keyed off exec_ir2 - and always happen immediately. ( exec_ir2 always is
|
1355 |
|
|
// immediately reset - unless of course a new instruction is transferred and executed.
|
1356 |
|
|
//
|
1357 |
|
|
//
|
1358 |
|
|
//
|
1359 |
|
|
always @(posedge clk or posedge rst)
|
1360 |
|
|
if (rst) ir2 <= 10'h0;
|
1361 |
|
|
else if (wb_rdy_nhz & next_pipe_state[2]) ir2 <= ir1;
|
1362 |
|
|
|
1363 |
|
|
always @(posedge clk or posedge rst)
|
1364 |
|
|
if (rst)
|
1365 |
|
|
begin
|
1366 |
|
|
ir2dd <= 1'b0;
|
1367 |
|
|
ir2fd <= 1'b0;
|
1368 |
|
|
end
|
1369 |
|
|
else if (wb_rdy_nhz & next_pipe_state[2])
|
1370 |
|
|
begin
|
1371 |
|
|
ir2dd <= ir1dd;
|
1372 |
|
|
ir2fd <= ir1fd;
|
1373 |
|
|
end
|
1374 |
|
|
|
1375 |
|
|
always @(posedge clk )
|
1376 |
|
|
if (wb_rdy_nhz & next_pipe_state[0]) exec_ir2 <= 1'b1;
|
1377 |
|
|
else exec_ir2 <= 1'b0;
|
1378 |
|
|
|
1379 |
|
|
|
1380 |
|
|
|
1381 |
|
|
|
1382 |
|
|
|
1383 |
|
|
//--------------- block move flags ------------------------
|
1384 |
|
|
always @(posedge clk)
|
1385 |
|
|
if (dec_state == DEC_ED) blk_inc_flg <= dec_blk_inc;
|
1386 |
|
|
|
1387 |
|
|
always @(posedge clk)
|
1388 |
|
|
if (dec_state == DEC_ED) blk_rpt_flg <= dec_blk_rpt;
|
1389 |
|
|
|
1390 |
|
|
|
1391 |
|
|
always @(posedge clk)
|
1392 |
|
|
if (dec_state == DEC_ED) blk_io_flg <= dec_blk_io;
|
1393 |
|
|
|
1394 |
|
|
|
1395 |
|
|
//-------------------------- memory interface stuff ----------------------------
|
1396 |
|
|
|
1397 |
|
|
|
1398 |
|
|
// -- wb_adr
|
1399 |
|
|
always @(posedge clk) if (wb_rdy) wb_adr <= mux21;
|
1400 |
|
|
|
1401 |
|
|
// -- wb_we;
|
1402 |
|
|
|
1403 |
|
|
always @(posedge clk or posedge rst)
|
1404 |
|
|
if (rst) wb_we <= 1'b0;
|
1405 |
|
|
else if (wb_rdy_nhz) wb_we <= we_next;
|
1406 |
|
|
|
1407 |
|
|
|
1408 |
|
|
|
1409 |
|
|
// -- wb_cyc
|
1410 |
|
|
|
1411 |
|
|
wire no_wb_start = mem_idle | mem_halt | mem_op3 & blk_cmp_reg | mem_op1 & rmw_reg;
|
1412 |
|
|
always @(posedge clk or posedge rst)
|
1413 |
|
|
if (rst) wb_cyc <= 1'b0;
|
1414 |
|
|
else if (wb_rdy_nhz) wb_cyc <= next_mem_state != MEM_NOP ;
|
1415 |
|
|
|
1416 |
|
|
// -- wb_stb;
|
1417 |
|
|
|
1418 |
|
|
always @(posedge clk or posedge rst)
|
1419 |
|
|
if (rst) wb_stb <= 1'b0;
|
1420 |
|
|
else if (wb_rdy_nhz) wb_stb <= next_mem_state != MEM_NOP ;
|
1421 |
|
|
|
1422 |
|
|
|
1423 |
|
|
// -- wb_lock lets not worry about lock unless somebody thinks it matters.
|
1424 |
|
|
|
1425 |
|
|
// -- wb_tga_io
|
1426 |
|
|
always @(posedge clk or posedge rst)
|
1427 |
|
|
if (rst) wb_tga_io <= 2'b0;
|
1428 |
|
|
else if (wb_rdy_nhz)
|
1429 |
|
|
begin
|
1430 |
|
|
if (next_mem_state == MEM_IOF_C |
|
1431 |
|
|
next_mem_state == MEM_IOS_C |
|
1432 |
|
|
next_mem_state == MEM_IOF_N |
|
1433 |
|
|
next_mem_state == MEM_IOS_N ) wb_tga_io <= TAG_IO;
|
1434 |
|
|
|
1435 |
|
|
else if (next_mem_state == MEM_INTA ) wb_tga_io <= TAG_INT;
|
1436 |
|
|
else wb_tga_io <= 2'b0 ;
|
1437 |
|
|
end
|
1438 |
|
|
|
1439 |
|
|
//------------ the input-output data register (nn) -----------------------------------------
|
1440 |
|
|
// basicaly we store lsb's folowed by msb's
|
1441 |
|
|
// input is always to msb (of input regiser) first (if a 2 byte operand, lsb<=msb before transfer)
|
1442 |
|
|
// this gets nn to position { msb, lsb } before we execute 2 byte transfer.
|
1443 |
|
|
//
|
1444 |
|
|
// if we don't update - we byte swap as well as
|
1445 |
|
|
// when we read
|
1446 |
|
|
// IMPORTANT We store from MSB's so that on block moves read and write from same place.
|
1447 |
|
|
// this makes the output look somewhat bass-ackwards but who is looking?
|
1448 |
|
|
//
|
1449 |
|
|
// There is probably a simpler way to do this. Unfortunately there are a lot of
|
1450 |
|
|
// dependencies here. Ill continue as planned till it proves untractable.
|
1451 |
|
|
// Issue is that we are using ir1 to provide the op specification -- but in general
|
1452 |
|
|
// ir1 gets gronked before 2nd store (if it happens) - so we need to capture both
|
1453 |
|
|
// data first time OSIXpD OS1 OSSP, and MEM_OSNN
|
1454 |
|
|
//
|
1455 |
|
|
// on consideration lets make a flag flag_firstos that gets set on first store after
|
1456 |
|
|
// DEC_EXEC
|
1457 |
|
|
// ISSUE reads both here and in ir1 need to execute on wb_ack ?
|
1458 |
|
|
// I recall wb_ack must stay active until a change in cycle ?
|
1459 |
|
|
// need to review wb spec.
|
1460 |
|
|
//
|
1461 |
|
|
//issue: how is EXs6SP7_HL implemented -- it is known as a rmw - and only trick for this file is
|
1462 |
|
|
// that nn must be properly updates with ir2
|
1463 |
|
|
|
1464 |
|
|
always @(posedge clk or posedge rst)
|
1465 |
|
|
if (rst) flag_os1 <= 1'b0;
|
1466 |
|
|
else if ((DEC_EXEC == next_dec_state) & wb_rdy) flag_os1 <= 1'b0;
|
1467 |
|
|
else if ( we_next ) flag_os1 <= 1'b1;
|
1468 |
|
|
|
1469 |
|
|
|
1470 |
|
|
wire [15:0] pc_2 = pc - 16'h2;
|
1471 |
|
|
always @(posedge clk)
|
1472 |
|
|
if (wb_rdy_nhz)
|
1473 |
|
|
begin
|
1474 |
|
|
if ( we_next & flag_os1) nn <= { nn[7:0], nn[15:8] } ;
|
1475 |
|
|
else if(we_next & ( next_mem_state == MEM_CALL)) nn <= {pc[7:0], pc[15:8]};
|
1476 |
|
|
else if(we_next & ( next_mem_state == MEM_OSSP_PCM2)) nn <= {pc_2[7:0], pc_2[15:8]};
|
1477 |
|
|
else if(EXs6SP7_HL== ir2 & ir2dd & exec_ir2) nn <= ixr;
|
1478 |
|
|
else if(EXs6SP7_HL== ir2 & ir2fd & exec_ir2) nn <= iyr;
|
1479 |
|
|
else if(EXs6SP7_HL== ir2 & exec_ir2) nn <= hl;
|
1480 |
|
|
// these are the general cases with ir1 providing register specification
|
1481 |
|
|
else if(we_next & ( next_mem_state == MEM_OS1 |
|
1482 |
|
|
next_mem_state == MEM_OSIXpD |
|
1483 |
|
|
next_mem_state == MEM_OSSP |
|
1484 |
|
|
next_mem_state == MEM_OSNN ) )
|
1485 |
|
|
begin
|
1486 |
|
|
if (os_a) nn[15:8] <= ar;
|
1487 |
|
|
if (os_b) nn[15:8] <= br;
|
1488 |
|
|
if (os_c) nn <= {cr, br }; // use for PUSHsBC
|
1489 |
|
|
if (os_d) nn[15:8] <= dr;
|
1490 |
|
|
if (os_e) nn <= {er, dr }; // use for PUSHsDE
|
1491 |
|
|
if (os_h) nn[15:8] <= hr;
|
1492 |
|
|
if (os_l) nn <= {lr, hr }; // use for PUSHsHL
|
1493 |
|
|
if (os_f) nn <= {fr, ar }; // use for PUSHsAF
|
1494 |
|
|
end
|
1495 |
|
|
|
1496 |
|
|
else nn <= { wb_dat_i, nn[15:8] };
|
1497 |
|
|
end
|
1498 |
|
|
|
1499 |
|
|
|
1500 |
|
|
|
1501 |
|
|
//------------------- pc and sp ----------------------------------------------------
|
1502 |
|
|
always @(posedge clk or posedge rst)
|
1503 |
|
|
if (rst) pc <= 16'h0;
|
1504 |
|
|
else if (wb_rdy_nhz)
|
1505 |
|
|
begin
|
1506 |
|
|
if (next_mem_state == MEM_DECPC) pc <= pc - 16'h1; // decrementer could perhaps be shared.
|
1507 |
|
|
if (next_mem_state == MEM_IFPP1) pc <= adr_alu;
|
1508 |
|
|
if (next_mem_state == MEM_CALL ) pc <= nn; //Use MEM_CALL to exchange pc<=>nn
|
1509 |
|
|
if (next_mem_state == MEM_IFRST) pc <= src_mux;
|
1510 |
|
|
if (next_mem_state == MEM_JMPHL) pc <= src_mux;
|
1511 |
|
|
if (next_mem_state == MEM_IFNN ) pc <= src_mux;
|
1512 |
|
|
if (next_mem_state == MEM_IFINT) pc <= src_mux;
|
1513 |
|
|
end
|
1514 |
|
|
|
1515 |
|
|
//---------------------------------- sp -----------------------------------------------------
|
1516 |
|
|
//
|
1517 |
|
|
// with pc updates are always made from ir1 as the PC is so critical to instruction flow.
|
1518 |
|
|
// (this of course creates the possibility of an "inst_hazard" - where data is stored in an
|
1519 |
|
|
// instruction already fetched - see below)
|
1520 |
|
|
// with sp the situation is not so simple.
|
1521 |
|
|
// Issues - especially regarding hazards.
|
1522 |
|
|
//
|
1523 |
|
|
// LDsSP_NN this should be done from ir2 - no hazard as active state is ALWAYS IF2
|
1524 |
|
|
//
|
1525 |
|
|
// ADDsHL_SP The add is a pre-add so sp cannot be modified before inst is executed from ir2
|
1526 |
|
|
// DECsSP Just do it with ir1 at DEC_EXEC gotcha need -- IFPP1 in general use ir2 -> hazard
|
1527 |
|
|
// EXs6SP7_HL rmw - no change to sp - no issue here
|
1528 |
|
|
// INCsSP Just do it with ir1 at DEC_EXEC gotcha -- IFPP1 use ir2 -> hazard
|
1529 |
|
|
// LDsSP_HL do from ir1 and use standard hazard logic (if H or L is being
|
1530 |
|
|
// updated -- wait)
|
1531 |
|
|
//
|
1532 |
|
|
// ED_LDs6NN7_REG REG== SP // needs to be done from ir2
|
1533 |
|
|
// ED_LDsREG_6NN7 REG== SP // do from ir2 - no hazard as executed on IF2 - refill pipe
|
1534 |
|
|
|
1535 |
|
|
always @(posedge clk )
|
1536 |
|
|
if (exec_ir2 ) // this has priority of course
|
1537 |
|
|
begin
|
1538 |
|
|
if (LDsSP_NN == ir2) sp <= nn;
|
1539 |
|
|
if (ED_LDsREG_6NN7 == ir2) sp <= nn;
|
1540 |
|
|
if ( DECsSP == ir2 ) sp <= add16;
|
1541 |
|
|
if ( INCsSP == ir2 ) sp <= add16;
|
1542 |
|
|
end
|
1543 |
|
|
else if (wb_rdy_nhz)
|
1544 |
|
|
begin
|
1545 |
|
|
if ( DECsSP == ir1 & dec_state == DEC_EXEC) sp <= adr_alu;
|
1546 |
|
|
if ( INCsSP == ir1 & dec_state == DEC_EXEC) sp <= adr_alu;
|
1547 |
|
|
if ( LDsSP_HL == ir1 & dec_state == DEC_EXEC) sp <= {hr,lr};
|
1548 |
|
|
if (next_mem_state == MEM_OFSP ) sp <= adr_alu;
|
1549 |
|
|
if (next_mem_state == MEM_OSSP ) sp <= adr_alu;
|
1550 |
|
|
if (next_mem_state == MEM_OSSP_PCM2 ) sp <= adr_alu;
|
1551 |
|
|
if (next_mem_state == MEM_OSSP_P ) sp <= adr_alu;
|
1552 |
|
|
end
|
1553 |
|
|
//----------------- inst hazard logic ------------------------------------------
|
1554 |
|
|
|
1555 |
|
|
|
1556 |
|
|
|
1557 |
|
|
always @(posedge clk or posedge rst)
|
1558 |
|
|
if (rst) inst_haz <= 1'b0;
|
1559 |
|
|
else if (we_next & (pc - 16'h1) == mux21) inst_haz <= 1'b1;
|
1560 |
|
|
else if (dec_state == DEC_EXEC) inst_haz <= 1'b0; // highest priority interrupt
|
1561 |
|
|
|
1562 |
|
|
//-------------------- int logic ----------------------------------------
|
1563 |
|
|
// We have a wishbone interrupt system - which i guess does not preclude a
|
1564 |
|
|
// non-maskable interrupt...... but bottom line is that such an interrupt is
|
1565 |
|
|
// definately out of favor with current system thinking. Within an embedded system
|
1566 |
|
|
// ( the target application here ) a single interrupt controller capable of handeling
|
1567 |
|
|
// as many interrupts as desired is the best choice.
|
1568 |
|
|
// Therefore we enable only mode 2 interrupts and a single enable ff.
|
1569 |
|
|
//
|
1570 |
|
|
// This begs the question of what to do with the "RETI" instruction -- ED4D. We opt to
|
1571 |
|
|
// enable interrupts with this instruction (and all its "aliases").
|
1572 |
|
|
//
|
1573 |
|
|
always @(posedge clk or posedge rst)
|
1574 |
|
|
if (rst) int_en <= 1'b0;
|
1575 |
|
|
else if (wb_rdy_nhz)
|
1576 |
|
|
begin
|
1577 |
|
|
if ((dec_state == DEC_EXEC) & (DI== ir1)) int_en <= 1'b0;
|
1578 |
|
|
else if ((dec_state == DEC_EXEC) & en_int_next) int_en <= 1'b1;
|
1579 |
|
|
else if ((dec_state == DEC_ED) & ed_retn) int_en <= 1'b0;
|
1580 |
|
|
if (dec_state == DEC_INT1) int_en <= 1'b0;
|
1581 |
|
|
end
|
1582 |
|
|
|
1583 |
|
|
|
1584 |
|
|
always @(posedge clk or posedge rst)
|
1585 |
|
|
if (rst) en_int_next <=1'b0;
|
1586 |
|
|
else if (wb_rdy_nhz)
|
1587 |
|
|
begin
|
1588 |
|
|
if ((dec_state == DEC_EXEC) & (EI== ir1)) en_int_next <=1'b1;
|
1589 |
|
|
else if (dec_state == DEC_EXEC) en_int_next <=1'b0;
|
1590 |
|
|
end
|
1591 |
|
|
|
1592 |
|
|
always @(posedge clk)
|
1593 |
|
|
wb_irq_sync <= wb_int_rq;
|
1594 |
|
|
|
1595 |
|
|
assign wb_int = wb_irq_sync & int_en;
|
1596 |
|
|
|
1597 |
|
|
endmodule
|
1598 |
|
|
|