1 |
3 |
ericw |
/*
|
2 |
|
|
--------------------------------------------------------------------------------
|
3 |
|
|
|
4 |
|
|
Module : op_decode.v
|
5 |
|
|
|
6 |
|
|
--------------------------------------------------------------------------------
|
7 |
|
|
|
8 |
|
|
Function:
|
9 |
|
|
- Opcode decoder for processor.
|
10 |
|
|
|
11 |
|
|
Instantiates:
|
12 |
|
|
- (2x) vector_sr.v
|
13 |
|
|
|
14 |
|
|
Notes:
|
15 |
|
|
- I/O optionally registered.
|
16 |
|
|
- Middle register is always present.
|
17 |
|
|
- Operates on the current thread in the stage.
|
18 |
|
|
|
19 |
|
|
--------------------------------------------------------------------------------
|
20 |
|
|
*/
|
21 |
|
|
|
22 |
|
|
module op_decode
|
23 |
|
|
#(
|
24 |
|
|
parameter integer REGS_IN = 1, // register option for inputs
|
25 |
|
|
parameter integer REGS_OUT = 1, // register option for outputs
|
26 |
|
|
parameter integer STACKS = 4, // number of stacks
|
27 |
|
|
parameter integer STK_W = 2, // stack selector width
|
28 |
|
|
parameter integer DATA_W = 32, // data width
|
29 |
|
|
parameter integer IM_DATA_W = 8, // immediate data width
|
30 |
|
|
parameter integer IM_ADDR_W = 5, // immediate address width
|
31 |
|
|
parameter integer OP_CODE_W = 16, // op code width
|
32 |
|
|
parameter integer LG_W = 2 // logical operation width
|
33 |
|
|
)
|
34 |
|
|
(
|
35 |
|
|
// clocks & resets
|
36 |
|
|
input wire clk_i, // clock
|
37 |
|
|
input wire rst_i, // async. reset, active high
|
38 |
|
|
// state I/O
|
39 |
|
|
input wire thrd_clr_i, // thread clear
|
40 |
|
|
input wire thrd_intr_i, // thread interrupt
|
41 |
|
|
input wire [OP_CODE_W-1:0] op_code_i, // op_code
|
42 |
|
|
output wire op_code_er_o, // 1=illegal op code encountered
|
43 |
|
|
// data I/O
|
44 |
|
|
output wire [IM_DATA_W-1:0] im_data_o, // immediate data
|
45 |
|
|
output wire [IM_ADDR_W-1:0] im_addr_o, // immediate address (offset)
|
46 |
|
|
// pc pipe control
|
47 |
|
|
output wire pc_clr_o, // pc clear
|
48 |
|
|
output wire lit_o, // 1 : pc=pc++ for lit
|
49 |
|
|
output wire jmp_o, // 1 : pc=pc+B for jump (cond)
|
50 |
|
|
output wire gto_o, // 1 : pc=B for goto / gosub (cond)
|
51 |
|
|
output wire intr_o, // 1 : pc=intr
|
52 |
|
|
// conditional masks
|
53 |
|
|
output wire tst_eq_o, // = test
|
54 |
|
|
output wire tst_lt_o, // < test
|
55 |
|
|
output wire tst_gt_o, // > test
|
56 |
|
|
output wire tst_ab_o, // 1=a/b test; 0=a/z test
|
57 |
|
|
// stacks control
|
58 |
|
|
output wire stk_clr_o, // stacks clear
|
59 |
|
|
output wire [STACKS-1:0] pop_o, // stacks pop
|
60 |
|
|
output wire [STACKS-1:0] push_o, // stacks push
|
61 |
|
|
// alu control
|
62 |
|
|
output wire [STK_W-1:0] a_sel_o, // stack selector
|
63 |
|
|
output wire [STK_W-1:0] b_sel_o, // stack selector
|
64 |
|
|
output wire imda_o, // 1=immediate data
|
65 |
|
|
output wire imad_o, // 1=immediate address
|
66 |
|
|
output wire sgn_o, // 1=signed
|
67 |
|
|
output wire ext_o, // 1=extended
|
68 |
|
|
output wire [LG_W-1:0] lg_o, // see decode in notes
|
69 |
|
|
output wire add_o, // 1=add
|
70 |
|
|
output wire sub_o, // 1=subtract
|
71 |
|
|
output wire mul_o, // 1=multiply
|
72 |
|
|
output wire shl_o, // 1=shift left
|
73 |
|
|
output wire cpy_o, // 1=copy b
|
74 |
|
|
output wire dm_o, // 1=data mem
|
75 |
|
|
output wire rtn_o, // 1=return pc
|
76 |
|
|
output wire rd_o, // 1=read
|
77 |
|
|
output wire wr_o // 1=write
|
78 |
|
|
);
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
/*
|
82 |
|
|
----------------------
|
83 |
|
|
-- internal signals --
|
84 |
|
|
----------------------
|
85 |
|
|
*/
|
86 |
|
|
`include "op_encode.h"
|
87 |
|
|
wire thrd_clr, thrd_intr;
|
88 |
|
|
wire [OP_CODE_W-1:0] op_code;
|
89 |
|
|
reg op_ok, op_code_ok_lo, op_code_ok_hi;
|
90 |
|
|
wire op_code_er;
|
91 |
|
|
//
|
92 |
|
|
reg [IM_DATA_W-1:0] im_data;
|
93 |
|
|
wire [IM_ADDR_W-1:0] im_addr;
|
94 |
|
|
reg pc_clr;
|
95 |
|
|
reg intr, gto, jmp, lit;
|
96 |
|
|
reg tst_lo, tst_hi, tst_ab, tst_gt, tst_lt, tst_eq;
|
97 |
|
|
reg stk_clr;
|
98 |
|
|
reg a_pop, b_pop;
|
99 |
|
|
reg push_lo, push_hi;
|
100 |
|
|
wire [STACKS-1:0] pop, push;
|
101 |
|
|
reg [STK_W-1:0] a_sel, b_sel;
|
102 |
|
|
reg imad_5b;
|
103 |
|
|
reg imda_8b, imda_6b;
|
104 |
|
|
wire imad, imda;
|
105 |
|
|
reg rtn, dm, cpy, shl, mul, sub, add, ext, sgn;
|
106 |
|
|
reg [LG_W-1:0] lg;
|
107 |
|
|
reg rd, wr;
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
/*
|
112 |
|
|
================
|
113 |
|
|
== code start ==
|
114 |
|
|
================
|
115 |
|
|
*/
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
// optional input registers
|
119 |
|
|
vector_sr
|
120 |
|
|
#(
|
121 |
|
|
.REGS ( REGS_IN ),
|
122 |
|
|
.DATA_W ( 2+OP_CODE_W ),
|
123 |
|
|
.RESET_VAL ( 0 )
|
124 |
|
|
)
|
125 |
|
|
in_regs
|
126 |
|
|
(
|
127 |
|
|
.clk_i ( clk_i ),
|
128 |
|
|
.rst_i ( rst_i ),
|
129 |
|
|
.data_i ( { thrd_clr_i, thrd_intr_i, op_code_i } ),
|
130 |
|
|
.data_o ( { thrd_clr, thrd_intr, op_code } )
|
131 |
|
|
);
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
// instantiate & split out op_code fields
|
135 |
|
|
wire [1:0] op_code_a_sel = op_code[1:0];
|
136 |
|
|
wire [1:0] op_code_b_sel = op_code[3:2];
|
137 |
|
|
wire op_code_a_pop = op_code[4];
|
138 |
|
|
wire op_code_b_pop = op_code[5];
|
139 |
|
|
wire [9:0] op_code_op = op_code[15:6];
|
140 |
|
|
wire [2:0] op_code_tst_hi = op_code[13:11];
|
141 |
|
|
wire [2:0] op_code_tst_lo = op_code[8:6];
|
142 |
|
|
wire [7:0] op_code_im = op_code[13:6];
|
143 |
|
|
//
|
144 |
|
|
reg [2:0] tst_hi_field, tst_lo_field;
|
145 |
|
|
reg [7:0] im_field;
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
// mid register for immediate and test fields
|
149 |
|
|
always @ ( posedge clk_i or posedge rst_i ) begin
|
150 |
|
|
if ( rst_i ) begin
|
151 |
|
|
tst_hi_field <= 'b0;
|
152 |
|
|
tst_lo_field <= 'b0;
|
153 |
|
|
im_field <= 'b0;
|
154 |
|
|
end else begin
|
155 |
|
|
tst_hi_field <= op_code_tst_hi;
|
156 |
|
|
tst_lo_field <= op_code_tst_lo;
|
157 |
|
|
im_field <= op_code_im;
|
158 |
|
|
end
|
159 |
|
|
end
|
160 |
|
|
|
161 |
|
|
// mid register if & case: clear, interrupt, and op_code decode
|
162 |
|
|
always @ ( posedge clk_i or posedge rst_i ) begin
|
163 |
|
|
if ( rst_i ) begin
|
164 |
|
|
op_ok <= 'b0;
|
165 |
|
|
op_code_ok_lo <= 'b0;
|
166 |
|
|
op_code_ok_hi <= 'b0;
|
167 |
|
|
pc_clr <= 'b0;
|
168 |
|
|
lit <= 'b0;
|
169 |
|
|
jmp <= 'b0;
|
170 |
|
|
gto <= 'b0;
|
171 |
|
|
intr <= 'b0;
|
172 |
|
|
tst_hi <= 'b0;
|
173 |
|
|
tst_lo <= 'b0;
|
174 |
|
|
tst_ab <= 'b0;
|
175 |
|
|
stk_clr <= 'b0;
|
176 |
|
|
a_pop <= 'b0;
|
177 |
|
|
b_pop <= 'b0;
|
178 |
|
|
push_lo <= 'b0;
|
179 |
|
|
push_hi <= 'b0;
|
180 |
|
|
a_sel <= 'b0;
|
181 |
|
|
b_sel <= 'b0;
|
182 |
|
|
imad_5b <= 'b0;
|
183 |
|
|
imda_8b <= 'b0;
|
184 |
|
|
imda_6b <= 'b0;
|
185 |
|
|
sgn <= 'b0;
|
186 |
|
|
ext <= 'b0;
|
187 |
|
|
lg <= 'b0;
|
188 |
|
|
add <= 'b0;
|
189 |
|
|
sub <= 'b0;
|
190 |
|
|
mul <= 'b0;
|
191 |
|
|
shl <= 'b0;
|
192 |
|
|
cpy <= 'b0;
|
193 |
|
|
dm <= 'b0;
|
194 |
|
|
rtn <= 'b0;
|
195 |
|
|
rd <= 'b0;
|
196 |
|
|
wr <= 'b0;
|
197 |
|
|
end else begin
|
198 |
|
|
// default values
|
199 |
|
|
op_ok <= 'b0; // default is bad op
|
200 |
|
|
op_code_ok_lo <= 'b0; // default is bad opcode
|
201 |
|
|
op_code_ok_hi <= 'b0; // default is bad opcode
|
202 |
|
|
pc_clr <= 'b0; // default is no pc clear
|
203 |
|
|
lit <= 'b0; // default is no lit
|
204 |
|
|
jmp <= 'b0; // default is no jump
|
205 |
|
|
gto <= 'b0; // default is no goto
|
206 |
|
|
intr <= 'b0; // default is no interrupt
|
207 |
|
|
tst_hi <= 'b0; // default is no test
|
208 |
|
|
tst_lo <= 'b0; // default is no test
|
209 |
|
|
tst_ab <= 'b0; // default is comparison to zero
|
210 |
|
|
stk_clr <= 'b0; // default is no stack clear
|
211 |
|
|
a_pop <= op_code_a_pop; // default is op_code directive
|
212 |
|
|
b_pop <= op_code_b_pop; // default is op_code directive
|
213 |
|
|
push_lo <= 'b0; // default is no push
|
214 |
|
|
push_hi <= 'b0; // default is no push
|
215 |
|
|
a_sel <= op_code_a_sel; // default is op_code directive
|
216 |
|
|
b_sel <= op_code_b_sel; // default is op_code directive
|
217 |
|
|
imad_5b <= 'b0; // default is not immediate address
|
218 |
|
|
imda_8b <= 'b0; // default is not immediate data
|
219 |
|
|
imda_6b <= 'b0; // default is not immediate data
|
220 |
|
|
sgn <= 'b1; // default is signed!
|
221 |
|
|
ext <= 'b0; // default is unextended
|
222 |
|
|
lg <= 'b0; // default is a&b
|
223 |
|
|
add <= 'b0; // default is logic
|
224 |
|
|
sub <= 'b0; // default is logic
|
225 |
|
|
mul <= 'b0; // default is logic
|
226 |
|
|
shl <= 'b0; // default is logic
|
227 |
|
|
cpy <= 'b0; // default is logic
|
228 |
|
|
dm <= 'b0; // default is logic
|
229 |
|
|
rtn <= 'b0; // default is logic
|
230 |
|
|
rd <= 'b0; // default is don't read
|
231 |
|
|
wr <= 'b0; // default is don't write
|
232 |
|
|
if ( thrd_clr ) begin
|
233 |
|
|
op_ok <= 'b1; // good op
|
234 |
|
|
pc_clr <= 'b1; // clear pc
|
235 |
|
|
stk_clr <= 'b1; // clear stacks
|
236 |
|
|
a_pop <= 'b0; // no pop
|
237 |
|
|
b_pop <= 'b0; // no pop
|
238 |
|
|
end else if ( thrd_intr ) begin
|
239 |
|
|
op_ok <= 'b1; // good op
|
240 |
|
|
intr <= 'b1; // don't inc PC
|
241 |
|
|
a_pop <= 'b0; // no pop
|
242 |
|
|
b_pop <= 'b0; // no pop
|
243 |
|
|
push_lo <= 'b1; // push
|
244 |
|
|
a_sel <= 'b0; // push return address to stack 0
|
245 |
|
|
rtn <= 'b1; // push pc
|
246 |
|
|
end else begin
|
247 |
|
|
casex ( op_code_op )
|
248 |
|
|
///////////////////////////////
|
249 |
|
|
// immediate read - 32 codes //
|
250 |
|
|
///////////////////////////////
|
251 |
|
|
op_rd_i : begin
|
252 |
|
|
op_code_ok_lo <= 'b1; // good opcode
|
253 |
|
|
push_lo <= 'b1; // push
|
254 |
|
|
dm <= 'b1; // dm
|
255 |
|
|
rd <= 'b1; // read
|
256 |
|
|
end
|
257 |
|
|
op_rd_ix : begin
|
258 |
|
|
op_code_ok_lo <= 'b1; // good opcode
|
259 |
|
|
push_lo <= 'b1; // push
|
260 |
|
|
dm <= 'b1; // dm
|
261 |
|
|
rd <= 'b1; // read
|
262 |
|
|
ext <= 'b1; // extended
|
263 |
|
|
end
|
264 |
|
|
////////////////////////////////////////////
|
265 |
|
|
// immediate conditional jump - 224 codes //
|
266 |
|
|
////////////////////////////////////////////
|
267 |
|
|
op_jmp_iez, op_jmp_ilz, op_jmp_ilez : begin
|
268 |
|
|
op_code_ok_lo <= 'b1; // good opcode
|
269 |
|
|
jmp <= 'b1; // jump
|
270 |
|
|
imad_5b <= 'b1; // immediate address
|
271 |
|
|
tst_hi <= 'b1; // high field
|
272 |
|
|
end
|
273 |
|
|
op_jmp_igz, op_jmp_igez, op_jmp_iglz, op_jmp_i : begin
|
274 |
|
|
op_code_ok_lo <= 'b1; // good opcode
|
275 |
|
|
jmp <= 'b1; // jump
|
276 |
|
|
imad_5b <= 'b1; // immediate address
|
277 |
|
|
tst_hi <= 'b1; // high field
|
278 |
|
|
end
|
279 |
|
|
////////////////////////////////
|
280 |
|
|
// immediate write - 32 codes //
|
281 |
|
|
////////////////////////////////
|
282 |
|
|
op_wr_i : begin
|
283 |
|
|
op_code_ok_lo <= 'b1; // good opcode
|
284 |
|
|
wr <= 'b1; // write
|
285 |
|
|
end
|
286 |
|
|
op_wr_ix : begin
|
287 |
|
|
op_code_ok_lo <= 'b1; // good opcode
|
288 |
|
|
wr <= 'b1; // write
|
289 |
|
|
ext <= 'b1; // extended
|
290 |
|
|
end
|
291 |
|
|
////////////////////////////////////////////
|
292 |
|
|
// immediate conditional jump - 192 codes //
|
293 |
|
|
////////////////////////////////////////////
|
294 |
|
|
op_jmp_ie, op_jmp_il, op_jmp_ile : begin
|
295 |
|
|
op_code_ok_lo <= 'b1; // good opcode
|
296 |
|
|
jmp <= 'b1; // jump
|
297 |
|
|
imad_5b <= 'b1; // immediate address
|
298 |
|
|
tst_hi <= 'b1; // high field
|
299 |
|
|
tst_ab <= 'b1; // a & b comparison
|
300 |
|
|
end
|
301 |
|
|
op_jmp_iug, op_jmp_iuge, op_jmp_igl : begin // gl is sign neutral
|
302 |
|
|
op_code_ok_lo <= 'b1; // good opcode
|
303 |
|
|
jmp <= 'b1; // jump
|
304 |
|
|
imad_5b <= 'b1; // immediate address
|
305 |
|
|
tst_hi <= 'b1; // high field
|
306 |
|
|
tst_ab <= 'b1; // a & b comparison
|
307 |
|
|
sgn <= 'b0; // unsigned
|
308 |
|
|
end
|
309 |
|
|
///////////////////////
|
310 |
|
|
// unused - 32 codes //
|
311 |
|
|
///////////////////////
|
312 |
|
|
////////////////////////////////
|
313 |
|
|
// immediate data - 256 codes //
|
314 |
|
|
////////////////////////////////
|
315 |
|
|
op_byt_i : begin
|
316 |
|
|
op_code_ok_lo <= 'b1; // good opcode
|
317 |
|
|
push_lo <= 'b1; // push
|
318 |
|
|
imda_8b <= 'b1; // immediate data
|
319 |
|
|
cpy <= 'b1; // copy
|
320 |
|
|
end
|
321 |
|
|
/////////////////////////////////
|
322 |
|
|
// immediate shift - 128 codes //
|
323 |
|
|
/////////////////////////////////
|
324 |
|
|
op_shl_i : begin
|
325 |
|
|
op_code_ok_lo <= 'b1; // good opcode
|
326 |
|
|
push_lo <= 'b1; // push
|
327 |
|
|
imda_6b <= 'b1; // immediate data
|
328 |
|
|
shl <= 'b1; // shift left
|
329 |
|
|
end
|
330 |
|
|
op_shl_iu : begin
|
331 |
|
|
op_code_ok_lo <= 'b1; // good opcode
|
332 |
|
|
push_lo <= 'b1; // push
|
333 |
|
|
imda_6b <= 'b1; // immediate data
|
334 |
|
|
shl <= 'b1; // shift left
|
335 |
|
|
sgn <= 'b0; // unsigned
|
336 |
|
|
end
|
337 |
|
|
//////////////////////////////
|
338 |
|
|
// immediate add - 64 codes //
|
339 |
|
|
//////////////////////////////
|
340 |
|
|
op_add_i : begin
|
341 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
342 |
|
|
push_hi <= 'b1; // push
|
343 |
|
|
imda_6b <= 'b1; // immediate data
|
344 |
|
|
add <= 'b1; // add
|
345 |
|
|
end
|
346 |
|
|
/////////////////////////////////////
|
347 |
|
|
// conditional jump - 7 of 8 codes //
|
348 |
|
|
/////////////////////////////////////
|
349 |
|
|
op_jmp_ez, op_jmp_lz, op_jmp_lez, op_jmp_gz, op_jmp_gez, op_jmp_glz, op_jmp : begin
|
350 |
|
|
op_code_ok_lo <= 'b1; // good opcode
|
351 |
|
|
jmp <= 'b1; // jump
|
352 |
|
|
tst_lo <= 'b1; // low field
|
353 |
|
|
end
|
354 |
|
|
/////////////////////////////////////
|
355 |
|
|
// conditional goto - 7 of 8 codes //
|
356 |
|
|
/////////////////////////////////////
|
357 |
|
|
op_gto_ez, op_gto_lz, op_gto_lez, op_gto_gz, op_gto_gez, op_gto_glz, op_gto : begin
|
358 |
|
|
op_code_ok_lo <= 'b1; // good opcode
|
359 |
|
|
gto <= 'b1; // goto
|
360 |
|
|
tst_lo <= 'b1; // low field
|
361 |
|
|
end
|
362 |
|
|
////////////////////////
|
363 |
|
|
// singles - 48 codes //
|
364 |
|
|
////////////////////////
|
365 |
|
|
/////////////
|
366 |
|
|
// group 1 //
|
367 |
|
|
/////////////
|
368 |
|
|
op_add : begin
|
369 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
370 |
|
|
push_hi <= 'b1; // push
|
371 |
|
|
add <= 'b1; // add
|
372 |
|
|
end
|
373 |
|
|
op_add_x : begin
|
374 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
375 |
|
|
push_hi <= 'b1; // push
|
376 |
|
|
add <= 'b1; // add
|
377 |
|
|
ext <= 'b1; // extended
|
378 |
|
|
end
|
379 |
|
|
op_add_ux : begin
|
380 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
381 |
|
|
push_hi <= 'b1; // push
|
382 |
|
|
add <= 'b1; // add
|
383 |
|
|
ext <= 'b1; // extended
|
384 |
|
|
sgn <= 'b0; // unsigned
|
385 |
|
|
end
|
386 |
|
|
op_sub : begin
|
387 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
388 |
|
|
push_hi <= 'b1; // push
|
389 |
|
|
sub <= 'b1; // sub
|
390 |
|
|
end
|
391 |
|
|
op_sub_x : begin
|
392 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
393 |
|
|
push_hi <= 'b1; // push
|
394 |
|
|
sub <= 'b1; // sub
|
395 |
|
|
ext <= 'b1; // extended
|
396 |
|
|
end
|
397 |
|
|
op_sub_ux : begin
|
398 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
399 |
|
|
push_hi <= 'b1; // push
|
400 |
|
|
sub <= 'b1; // sub
|
401 |
|
|
ext <= 'b1; // extended
|
402 |
|
|
sgn <= 'b0; // unsigned
|
403 |
|
|
end
|
404 |
|
|
op_mul : begin
|
405 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
406 |
|
|
push_hi <= 'b1; // push
|
407 |
|
|
mul <= 'b1; // multiply
|
408 |
|
|
end
|
409 |
|
|
op_mul_x : begin
|
410 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
411 |
|
|
push_hi <= 'b1; // push
|
412 |
|
|
mul <= 'b1; // multiply
|
413 |
|
|
ext <= 'b1; // extended
|
414 |
|
|
end
|
415 |
|
|
op_mul_ux : begin
|
416 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
417 |
|
|
push_hi <= 'b1; // push
|
418 |
|
|
mul <= 'b1; // multiply
|
419 |
|
|
ext <= 'b1; // extended
|
420 |
|
|
sgn <= 'b0; // unsigned
|
421 |
|
|
end
|
422 |
|
|
op_shl : begin
|
423 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
424 |
|
|
push_hi <= 'b1; // push
|
425 |
|
|
shl <= 'b1; // shift left
|
426 |
|
|
end
|
427 |
|
|
op_shl_u : begin
|
428 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
429 |
|
|
push_hi <= 'b1; // push
|
430 |
|
|
shl <= 'b1; // shift left
|
431 |
|
|
sgn <= 'b0; // unsigned
|
432 |
|
|
end
|
433 |
|
|
/////////////
|
434 |
|
|
// group 2 //
|
435 |
|
|
/////////////
|
436 |
|
|
op_and : begin
|
437 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
438 |
|
|
push_hi <= 'b1; // push
|
439 |
|
|
end
|
440 |
|
|
op_or : begin
|
441 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
442 |
|
|
push_hi <= 'b1; // push
|
443 |
|
|
lg <= 'd1;
|
444 |
|
|
end
|
445 |
|
|
op_xor : begin
|
446 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
447 |
|
|
push_hi <= 'b1; // push
|
448 |
|
|
lg <= 'd2;
|
449 |
|
|
end
|
450 |
|
|
op_not : begin
|
451 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
452 |
|
|
push_hi <= 'b1; // push
|
453 |
|
|
lg <= 'd3;
|
454 |
|
|
end
|
455 |
|
|
op_and_b : begin
|
456 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
457 |
|
|
push_hi <= 'b1; // push
|
458 |
|
|
ext <= 'b1; // extended
|
459 |
|
|
end
|
460 |
|
|
op_or_b : begin
|
461 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
462 |
|
|
push_hi <= 'b1; // push
|
463 |
|
|
lg <= 'd1;
|
464 |
|
|
ext <= 'b1; // extended
|
465 |
|
|
end
|
466 |
|
|
op_xor_b : begin
|
467 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
468 |
|
|
push_hi <= 'b1; // push
|
469 |
|
|
lg <= 'd2;
|
470 |
|
|
ext <= 'b1; // extended
|
471 |
|
|
end
|
472 |
|
|
/////////////
|
473 |
|
|
// group 3 //
|
474 |
|
|
/////////////
|
475 |
|
|
op_lit : begin
|
476 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
477 |
|
|
push_hi <= 'b1; // push
|
478 |
|
|
lit <= 'b1; // lit
|
479 |
|
|
dm <= 'b1; // dm
|
480 |
|
|
end
|
481 |
|
|
op_lit_u : begin
|
482 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
483 |
|
|
push_hi <= 'b1; // push
|
484 |
|
|
lit <= 'b1; // lit
|
485 |
|
|
dm <= 'b1; // dm
|
486 |
|
|
sgn <= 'b0; // unsigned
|
487 |
|
|
end
|
488 |
|
|
op_lit_x : begin
|
489 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
490 |
|
|
push_hi <= 'b1; // push
|
491 |
|
|
lit <= 'b1; // lit
|
492 |
|
|
dm <= 'b1; // dm
|
493 |
|
|
ext <= 'b1; // extended
|
494 |
|
|
end
|
495 |
|
|
op_cpy : begin
|
496 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
497 |
|
|
push_hi <= 'b1; // push
|
498 |
|
|
cpy <= 'b1; // copy
|
499 |
|
|
end
|
500 |
|
|
op_pc : begin
|
501 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
502 |
|
|
push_hi <= 'b1; // push
|
503 |
|
|
rtn <= 'b1; // push pc
|
504 |
|
|
end
|
505 |
|
|
op_gsb : begin
|
506 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
507 |
|
|
push_hi <= 'b1; // push
|
508 |
|
|
gto <= 'b1; // goto
|
509 |
|
|
rtn <= 'b1; // push pc
|
510 |
|
|
end
|
511 |
|
|
op_cls : begin
|
512 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
513 |
|
|
stk_clr <= 'b1; // stack clear
|
514 |
|
|
a_pop <= 'b0; // no pop
|
515 |
|
|
b_pop <= 'b0; // no pop
|
516 |
|
|
end
|
517 |
|
|
op_pop : begin
|
518 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
519 |
|
|
end
|
520 |
|
|
op_nop : begin
|
521 |
|
|
op_code_ok_hi <= 'b1; // good opcode
|
522 |
|
|
a_pop <= 'b0; // no pop
|
523 |
|
|
b_pop <= 'b0; // no pop
|
524 |
|
|
end
|
525 |
|
|
default: begin
|
526 |
|
|
// nothing here
|
527 |
|
|
end
|
528 |
|
|
endcase
|
529 |
|
|
end
|
530 |
|
|
end
|
531 |
|
|
end
|
532 |
|
|
|
533 |
|
|
|
534 |
|
|
// decode test
|
535 |
|
|
always @ ( * ) begin
|
536 |
|
|
casex ( { tst_hi, tst_lo } )
|
537 |
|
|
2'b00 : { tst_gt, tst_lt, tst_eq } <= 3'b111; // default is always
|
538 |
|
|
2'b01 : { tst_gt, tst_lt, tst_eq } <= tst_lo_field;
|
539 |
|
|
2'b1x : { tst_gt, tst_lt, tst_eq } <= tst_hi_field;
|
540 |
|
|
endcase
|
541 |
|
|
end
|
542 |
|
|
|
543 |
|
|
// decode immediate data
|
544 |
|
|
always @ ( * ) begin
|
545 |
|
|
case ( imda_6b )
|
546 |
|
|
1'b0 : im_data <= im_field; // byte default
|
547 |
|
|
1'b1 : im_data <= $signed( im_field[5:0] ); // signed 6 bit
|
548 |
|
|
endcase
|
549 |
|
|
end
|
550 |
|
|
|
551 |
|
|
// assign immediate address
|
552 |
|
|
assign im_addr = im_field[4:0];
|
553 |
|
|
|
554 |
|
|
// decode control
|
555 |
|
|
assign imda = imda_8b | imda_6b;
|
556 |
|
|
assign imad = imad_5b;
|
557 |
|
|
|
558 |
|
|
// decode pop & push
|
559 |
|
|
assign pop = ( a_pop << a_sel ) | ( b_pop << b_sel );
|
560 |
|
|
assign push = ( ( push_lo | push_hi ) << a_sel );
|
561 |
|
|
|
562 |
|
|
// decode errors
|
563 |
|
|
assign op_code_er = ~( op_ok | op_code_ok_lo | op_code_ok_hi );
|
564 |
|
|
|
565 |
|
|
|
566 |
|
|
// optional output registers
|
567 |
|
|
vector_sr
|
568 |
|
|
#(
|
569 |
|
|
.REGS ( REGS_OUT ),
|
570 |
|
|
.DATA_W ( 1+IM_ADDR_W+IM_DATA_W+10+STACKS+STACKS+STK_W+STK_W+9+LG_W+4 ),
|
571 |
|
|
.RESET_VAL ( 0 )
|
572 |
|
|
)
|
573 |
|
|
out_regs
|
574 |
|
|
(
|
575 |
|
|
.clk_i ( clk_i ),
|
576 |
|
|
.rst_i ( rst_i ),
|
577 |
|
|
.data_i ( { op_code_er, im_addr, im_data, pc_clr, intr, gto, jmp, lit, tst_gt, tst_lt, tst_eq, tst_ab, stk_clr, pop, push, a_sel, b_sel, imda, imad, rtn, dm, cpy, shl, mul, sub, add, lg, ext, sgn, rd, wr } ),
|
578 |
|
|
.data_o ( { op_code_er_o, im_addr_o, im_data_o, pc_clr_o, intr_o, gto_o, jmp_o, lit_o, tst_gt_o, tst_lt_o, tst_eq_o, tst_ab_o, stk_clr_o, pop_o, push_o, a_sel_o, b_sel_o, imda_o, imad_o, rtn_o, dm_o, cpy_o, shl_o, mul_o, sub_o, add_o, lg_o, ext_o, sgn_o, rd_o, wr_o } )
|
579 |
|
|
);
|
580 |
|
|
|
581 |
|
|
|
582 |
|
|
endmodule
|