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

Subversion Repositories steelcore

[/] [vivado/] [steel-core.srcs/] [sim_1/] [imports/] [steel-core/] [rtl/] [bench/] [tb_decoder.v] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 rafaelcalc
//////////////////////////////////////////////////////////////////////////////////
2
// Engineer: Rafael de Oliveira Calçada (rafaelcalcada@gmail.com)
3
// 
4
// Create Date: 03.04.2020 18:35:35
5
// Module Name: tb_decoder
6
// Project Name: Steel Core
7
// Description: Decoder testbench
8
// 
9
// Dependencies: globals.vh
10
//               decoder.v
11
// 
12
// Version 0.01
13
// 
14
//////////////////////////////////////////////////////////////////////////////////
15
 
16
/*********************************************************************************
17
 
18
MIT License
19
 
20
Copyright (c) 2020 Rafael de Oliveira Calçada
21
 
22
Permission is hereby granted, free of charge, to any person obtaining a copy
23
of this software and associated documentation files (the "Software"), to deal
24
in the Software without restriction, including without limitation the rights
25
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
copies of the Software, and to permit persons to whom the Software is
27
furnished to do so, subject to the following conditions:
28
 
29
The above copyright notice and this permission notice shall be included in all
30
copies or substantial portions of the Software.
31
 
32
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38
SOFTWARE.
39
 
40
********************************************************************************/
41
 
42
`timescale 1ns / 1ps
43
`include "../globals.vh"
44
 
45
 
46
module tb_decoder();
47
 
48
    reg [6:0] OPCODE;
49
    reg FUNCT7_5;
50
    reg [2:0] FUNCT3;
51
    reg [1:0] IADDER_OUT_1_TO_0;
52
    reg TRAP_TAKEN;
53
 
54
    wire [3:0] ALU_OPCODE;
55
    wire MEM_WR_REQ;
56
    wire [1:0] LOAD_SIZE;
57
    wire LOAD_UNSIGNED;
58
    wire ALU_SRC;
59
    wire IADDER_SRC;
60
    wire CSR_WR_EN;
61
    wire RF_WR_EN;
62
    wire [2:0] WB_MUX_SEL;
63
    wire [2:0] IMM_TYPE;
64
    wire [2:0] CSR_OP;
65
    wire ILLEGAL_INSTR;
66
    wire MISALIGNED_LOAD;
67
    wire MISALIGNED_STORE;
68
 
69
    decoder dut(
70
 
71
        .OPCODE(OPCODE),
72
        .FUNCT7_5(FUNCT7_5),
73
        .FUNCT3(FUNCT3),
74
        .IADDER_OUT_1_TO_0(IADDER_OUT_1_TO_0),
75
        .TRAP_TAKEN(TRAP_TAKEN),
76
        .ALU_OPCODE(ALU_OPCODE),
77
        .MEM_WR_REQ(MEM_WR_REQ),
78
        .LOAD_SIZE(LOAD_SIZE),
79
        .LOAD_UNSIGNED(LOAD_UNSIGNED),
80
        .ALU_SRC(ALU_SRC),
81
        .IADDER_SRC(IADDER_SRC),
82
        .CSR_WR_EN(CSR_WR_EN),
83
        .RF_WR_EN(RF_WR_EN),
84
        .WB_MUX_SEL(WB_MUX_SEL),
85
        .IMM_TYPE(IMM_TYPE),
86
        .CSR_OP(CSR_OP),
87
        .ILLEGAL_INSTR(ILLEGAL_INSTR),
88
        .MISALIGNED_LOAD(MISALIGNED_LOAD),
89
        .MISALIGNED_STORE(MISALIGNED_STORE)
90
 
91
    );
92
 
93
    reg [4:0] opcode_6_to_2;
94
    reg [6:0] funct7;
95
 
96
    initial
97
    begin
98
 
99
        $display("Testing Decoder...");
100
 
101
        $display("Testing OP opcode control signals...");
102
 
103
        $display("Testing signals common to all instructions...");
104
 
105
        opcode_6_to_2 = `OPCODE_OP;
106
        OPCODE = {opcode_6_to_2, 2'b11};
107
        IADDER_OUT_1_TO_0 = 2'b00;
108
        TRAP_TAKEN = 1'b0;
109
 
110
        #10;
111
        if(MEM_WR_REQ != 1'b0)
112
        begin
113
            $display("FAIL. Check the results.");
114
            $finish;
115
        end
116
        if(MISALIGNED_LOAD != 1'b0)
117
        begin
118
            $display("FAIL. Check the results.");
119
            $finish;
120
        end
121
        if(MISALIGNED_STORE != 1'b0)
122
        begin
123
            $display("FAIL. Check the results.");
124
            $finish;
125
        end
126
        if(ALU_SRC != 1'b1)
127
        begin
128
            $display("FAIL. Check the results.");
129
            $finish;
130
        end
131
        if(ILLEGAL_INSTR != 1'b0)
132
        begin
133
            $display("FAIL. Check the results.");
134
            $finish;
135
        end
136
        if(RF_WR_EN != 1'b1)
137
        begin
138
            $display("FAIL. Check the results.");
139
            $finish;
140
        end
141
        if(CSR_WR_EN != 1'b0)
142
        begin
143
            $display("FAIL. Check the results.");
144
            $finish;
145
        end
146
        if(WB_MUX_SEL != `WB_ALU)
147
        begin
148
            $display("FAIL. Check the results.");
149
            $finish;
150
        end
151
 
152
        $display("OP control signals common to all instructions successfully tested.");
153
 
154
        $display("Testing ALU_OPCODE signal generation for OP opcode...");
155
 
156
        funct7 = `FUNCT7_ADD;
157
        FUNCT7_5 = funct7[5];
158
        FUNCT3 = `FUNCT3_ADD;
159
        #10;
160
        if(ALU_OPCODE != `ALU_ADD)
161
        begin
162
            $display("FAIL. Check the results.");
163
            $finish;
164
        end
165
 
166
        $display("ALU_OPCODE for ADD... OK.");
167
 
168
        funct7 = `FUNCT7_SUB;
169
        FUNCT7_5 = funct7[5];
170
        FUNCT3 = `FUNCT3_SUB;
171
        #10;
172
        if(ALU_OPCODE != `ALU_SUB)
173
        begin
174
            $display("FAIL. Check the results.");
175
            $finish;
176
        end
177
 
178
        $display("ALU_OPCODE for SUB... OK.");
179
 
180
        funct7 = `FUNCT7_SLT;
181
        FUNCT7_5 = funct7[5];
182
        FUNCT3 = `FUNCT3_SLT;
183
        #10;
184
        if(ALU_OPCODE != `ALU_SLT)
185
        begin
186
            $display("FAIL. Check the results.");
187
            $finish;
188
        end
189
 
190
        $display("ALU_OPCODE for SLT... OK.");
191
 
192
        funct7 = `FUNCT7_SLTU;
193
        FUNCT7_5 = funct7[5];
194
        FUNCT3 = `FUNCT3_SLTU;
195
        #10;
196
        if(ALU_OPCODE != `ALU_SLTU)
197
        begin
198
            $display("FAIL. Check the results.");
199
            $finish;
200
        end
201
 
202
        $display("ALU_OPCODE for SLTU... OK.");
203
 
204
        funct7 = `FUNCT7_AND;
205
        FUNCT7_5 = funct7[5];
206
        FUNCT3 = `FUNCT3_AND;
207
        #10;
208
        if(ALU_OPCODE != `ALU_AND)
209
        begin
210
            $display("FAIL. Check the results.");
211
            $finish;
212
        end
213
 
214
        $display("ALU_OPCODE for AND... OK.");
215
 
216
        funct7 = `FUNCT7_OR;
217
        FUNCT7_5 = funct7[5];
218
        FUNCT3 = `FUNCT3_OR;
219
        #10;
220
        if(ALU_OPCODE != `ALU_OR)
221
        begin
222
            $display("FAIL. Check the results.");
223
            $finish;
224
        end
225
 
226
        $display("ALU_OPCODE for OR... OK.");
227
 
228
        funct7 = `FUNCT7_XOR;
229
        FUNCT7_5 = funct7[5];
230
        FUNCT3 = `FUNCT3_XOR;
231
        #10;
232
        if(ALU_OPCODE != `ALU_XOR)
233
        begin
234
            $display("FAIL. Check the results.");
235
            $finish;
236
        end
237
 
238
        $display("ALU_OPCODE for XOR... OK.");
239
 
240
        funct7 = `FUNCT7_SLL;
241
        FUNCT7_5 = funct7[5];
242
        FUNCT3 = `FUNCT3_SLL;
243
        #10;
244
        if(ALU_OPCODE != `ALU_SLL)
245
        begin
246
            $display("FAIL. Check the results.");
247
            $finish;
248
        end
249
 
250
        $display("ALU_OPCODE for SLL... OK.");
251
 
252
        funct7 = `FUNCT7_SRL;
253
        FUNCT7_5 = funct7[5];
254
        FUNCT3 = `FUNCT3_SRL;
255
        #10;
256
        if(ALU_OPCODE != `ALU_SRL)
257
        begin
258
            $display("FAIL. Check the results.");
259
            $finish;
260
        end
261
 
262
        $display("ALU_OPCODE for SRL... OK.");
263
 
264
        funct7 = `FUNCT7_SRA;
265
        FUNCT7_5 = funct7[5];
266
        FUNCT3 = `FUNCT3_SRA;
267
        #10;
268
        if(ALU_OPCODE != `ALU_SRA)
269
        begin
270
            $display("FAIL. Check the results.");
271
            $finish;
272
        end
273
 
274
        $display("ALU_OPCODE for SRA... OK.");
275
 
276
        $display("ALU_OPCODE signal generation for OP opcode successfully tested.");
277
 
278
        $display("OP control signals successfully tested.");
279
 
280
        $display("Testing OP-IMM opcode control signals...");
281
 
282
        $display("Testing signals common to all instructions...");
283
 
284
        opcode_6_to_2 = `OPCODE_OP_IMM;
285
        OPCODE = {opcode_6_to_2, 2'b11};
286
 
287
        #10;
288
        if(MEM_WR_REQ != 1'b0)
289
        begin
290
            $display("FAIL. Check the results.");
291
            $finish;
292
        end
293
        if(MISALIGNED_LOAD != 1'b0)
294
        begin
295
            $display("FAIL. Check the results.");
296
            $finish;
297
        end
298
        if(MISALIGNED_STORE != 1'b0)
299
        begin
300
            $display("FAIL. Check the results.");
301
            $finish;
302
        end
303
        if(ALU_SRC != 1'b0)
304
        begin
305
            $display("FAIL. Check the results.");
306
            $finish;
307
        end
308
        if(ILLEGAL_INSTR != 1'b0)
309
        begin
310
            $display("FAIL. Check the results.");
311
            $finish;
312
        end
313
        if(RF_WR_EN != 1'b1)
314
        begin
315
            $display("FAIL. Check the results.");
316
            $finish;
317
        end
318
        if(CSR_WR_EN != 1'b0)
319
        begin
320
            $display("FAIL. Check the results.");
321
            $finish;
322
        end
323
        if(WB_MUX_SEL != `WB_ALU)
324
        begin
325
            $display("FAIL. Check the results.");
326
            $finish;
327
        end
328
        if(IMM_TYPE != `I_TYPE)
329
        begin
330
            $display("FAIL. Check the results.");
331
            $finish;
332
        end
333
 
334
        $display("OP-IMM control signals common to all instructions successfully tested.");
335
 
336
        $display("Testing ALU_OPCODE signal generation for OP-IMM opcode...");
337
 
338
        FUNCT7_5 = 1'b0;
339
        FUNCT3 = `FUNCT3_ADD;
340
        #10;
341
        if(ALU_OPCODE != `ALU_ADD)
342
        begin
343
            $display("FAIL. Check the results.");
344
            $finish;
345
        end
346
 
347
        FUNCT7_5 = 1'b1;
348
        FUNCT3 = `FUNCT3_ADD;
349
        #10;
350
        if(ALU_OPCODE != `ALU_ADD)
351
        begin
352
            $display("FAIL. Check the results.");
353
            $finish;
354
        end
355
 
356
        $display("ALU_OPCODE for ADDI... OK.");
357
 
358
        FUNCT7_5 = 1'b0;
359
        FUNCT3 = `FUNCT3_SLT;
360
        #10;
361
        if(ALU_OPCODE != `ALU_SLT)
362
        begin
363
            $display("FAIL. Check the results.");
364
            $finish;
365
        end
366
 
367
        FUNCT7_5 = 1'b1;
368
        FUNCT3 = `FUNCT3_SLT;
369
        #10;
370
        if(ALU_OPCODE != `ALU_SLT)
371
        begin
372
            $display("FAIL. Check the results.");
373
            $finish;
374
        end
375
 
376
        $display("ALU_OPCODE for SLTI... OK.");
377
 
378
        FUNCT7_5 = 1'b0;
379
        FUNCT3 = `FUNCT3_SLTU;
380
        #10;
381
        if(ALU_OPCODE != `ALU_SLTU)
382
        begin
383
            $display("FAIL. Check the results.");
384
            $finish;
385
        end
386
 
387
        FUNCT7_5 = 1'b1;
388
        FUNCT3 = `FUNCT3_SLTU;
389
        #10;
390
        if(ALU_OPCODE != `ALU_SLTU)
391
        begin
392
            $display("FAIL. Check the results.");
393
            $finish;
394
        end
395
 
396
        $display("ALU_OPCODE for SLTIU... OK.");
397
 
398
        FUNCT7_5 = 1'b0;
399
        FUNCT3 = `FUNCT3_AND;
400
        #10;
401
        if(ALU_OPCODE != `ALU_AND)
402
        begin
403
            $display("FAIL. Check the results.");
404
            $finish;
405
        end
406
 
407
        FUNCT7_5 = 1'b1;
408
        FUNCT3 = `FUNCT3_AND;
409
        #10;
410
        if(ALU_OPCODE != `ALU_AND)
411
        begin
412
            $display("FAIL. Check the results.");
413
            $finish;
414
        end
415
 
416
        $display("ALU_OPCODE for ANDI... OK.");
417
 
418
        FUNCT7_5 = 1'b0;
419
        FUNCT3 = `FUNCT3_OR;
420
        #10;
421
        if(ALU_OPCODE != `ALU_OR)
422
        begin
423
            $display("FAIL. Check the results.");
424
            $finish;
425
        end
426
 
427
        FUNCT7_5 = 1'b1;
428
        FUNCT3 = `FUNCT3_OR;
429
        #10;
430
        if(ALU_OPCODE != `ALU_OR)
431
        begin
432
            $display("FAIL. Check the results.");
433
            $finish;
434
        end
435
 
436
        $display("ALU_OPCODE for ORI... OK.");
437
 
438
        FUNCT7_5 = 1'b0;
439
        FUNCT3 = `FUNCT3_XOR;
440
        #10;
441
        if(ALU_OPCODE != `ALU_XOR)
442
        begin
443
            $display("FAIL. Check the results.");
444
            $finish;
445
        end
446
 
447
        FUNCT7_5 = 1'b1;
448
        FUNCT3 = `FUNCT3_XOR;
449
        #10;
450
        if(ALU_OPCODE != `ALU_XOR)
451
        begin
452
            $display("FAIL. Check the results.");
453
            $finish;
454
        end
455
 
456
        $display("ALU_OPCODE for XORI... OK.");
457
 
458
        funct7 = `FUNCT7_SLL;
459
        FUNCT7_5 = funct7[5];
460
        FUNCT3 = `FUNCT3_SLL;
461
        #10;
462
        if(ALU_OPCODE != `ALU_SLL)
463
        begin
464
            $display("FAIL. Check the results.");
465
            $finish;
466
        end
467
 
468
        $display("ALU_OPCODE for SLLI... OK.");
469
 
470
        funct7 = `FUNCT7_SRL;
471
        FUNCT7_5 = funct7[5];
472
        FUNCT3 = `FUNCT3_SRL;
473
        #10;
474
        if(ALU_OPCODE != `ALU_SRL)
475
        begin
476
            $display("FAIL. Check the results.");
477
            $finish;
478
        end
479
 
480
        $display("ALU_OPCODE for SRLI... OK.");
481
 
482
        funct7 = `FUNCT7_SRA;
483
        FUNCT7_5 = funct7[5];
484
        FUNCT3 = `FUNCT3_SRA;
485
        #10;
486
        if(ALU_OPCODE != `ALU_SRA)
487
        begin
488
            $display("FAIL. Check the results.");
489
            $finish;
490
        end
491
 
492
        $display("ALU_OPCODE for SRAI... OK.");
493
 
494
        $display("ALU_OPCODE signal generation for OP-IMM opcode successfully tested.");
495
 
496
        $display("OP-IMM control signals successfully tested.");
497
 
498
        $display("Testing LOAD opcode control signals...");
499
 
500
        $display("Testing signals common to all instructions...");
501
 
502
        opcode_6_to_2 = `OPCODE_LOAD;
503
        OPCODE = {opcode_6_to_2, 2'b11};
504
 
505
        #10;
506
        if(MEM_WR_REQ != 1'b0)
507
        begin
508
            $display("FAIL. Check the results.");
509
            $finish;
510
        end
511
        if(MISALIGNED_LOAD != 1'b0)
512
        begin
513
            $display("FAIL. Check the results.");
514
            $finish;
515
        end
516
        if(MISALIGNED_STORE != 1'b0)
517
        begin
518
            $display("FAIL. Check the results.");
519
            $finish;
520
        end
521
        if(ILLEGAL_INSTR != 1'b0)
522
        begin
523
            $display("FAIL. Check the results.");
524
            $finish;
525
        end
526
        if(RF_WR_EN != 1'b1)
527
        begin
528
            $display("FAIL. Check the results.");
529
            $finish;
530
        end
531
        if(WB_MUX_SEL != `WB_LU)
532
        begin
533
            $display("FAIL. Check the results.");
534
            $finish;
535
        end
536
        if(IADDER_SRC != 1'b1)
537
        begin
538
            $display("FAIL. Check the results.");
539
            $finish;
540
        end
541
        if(CSR_WR_EN != 1'b0)
542
        begin
543
            $display("FAIL. Check the results.");
544
            $finish;
545
        end
546
        if(IMM_TYPE != `I_TYPE)
547
        begin
548
            $display("FAIL. Check the results.");
549
            $finish;
550
        end
551
 
552
        $display("LOAD control signals common to all instructions successfully tested.");
553
 
554
        $display("Testing load unit control signals generation...");
555
 
556
        FUNCT3 = `FUNCT3_BYTE;
557
        #10;
558
        if(LOAD_SIZE != `LOAD_BYTE)
559
        begin
560
            $display("FAIL. Check the results.");
561
            $finish;
562
        end
563
        if(LOAD_UNSIGNED != 1'b0)
564
        begin
565
            $display("FAIL. Check the results.");
566
            $finish;
567
        end
568
        if(MISALIGNED_LOAD != 1'b0)
569
        begin
570
            $display("FAIL. Check the results.");
571
            $finish;
572
        end
573
 
574
        $display("Load unit signals for LB... OK.");
575
 
576
        $display("Testing signal MISALIGNED_LOAD for LB...");
577
 
578
        FUNCT3 = `FUNCT3_BYTE;
579
        IADDER_OUT_1_TO_0 = 2'b01;
580
        #10;
581
        if(MISALIGNED_LOAD != 1'b0)
582
        begin
583
            $display("FAIL. Check the results.");
584
            $finish;
585
        end
586
        FUNCT3 = `FUNCT3_BYTE;
587
        IADDER_OUT_1_TO_0 = 2'b10;
588
        #10;
589
        if(MISALIGNED_LOAD != 1'b0)
590
        begin
591
            $display("FAIL. Check the results.");
592
            $finish;
593
        end
594
        FUNCT3 = `FUNCT3_BYTE;
595
        IADDER_OUT_1_TO_0 = 2'b11;
596
        #10;
597
        if(MISALIGNED_LOAD != 1'b0)
598
        begin
599
            $display("FAIL. Check the results.");
600
            $finish;
601
        end
602
 
603
        $display("MISALIGNED_LOAD generation for LB OK.");
604
 
605
        FUNCT3 = `FUNCT3_HALF;
606
        IADDER_OUT_1_TO_0 = 2'b00;
607
        #10;
608
        if(LOAD_SIZE != `LOAD_HALF)
609
        begin
610
            $display("FAIL. Check the results.");
611
            $finish;
612
        end
613
        if(LOAD_UNSIGNED != 1'b0)
614
        begin
615
            $display("FAIL. Check the results.");
616
            $finish;
617
        end
618
        if(MISALIGNED_LOAD != 1'b0)
619
        begin
620
            $display("FAIL. Check the results.");
621
            $finish;
622
        end
623
 
624
        $display("Load unit signals for LH... OK.");
625
 
626
        $display("Testing signal MISALIGNED_LOAD for LH...");
627
 
628
        FUNCT3 = `FUNCT3_HALF;
629
        IADDER_OUT_1_TO_0 = 2'b01;
630
        #10;
631
        if(MISALIGNED_LOAD != 1'b1)
632
        begin
633
            $display("FAIL. Check the results.");
634
            $finish;
635
        end
636
        FUNCT3 = `FUNCT3_HALF;
637
        IADDER_OUT_1_TO_0 = 2'b10;
638
        #10;
639
        if(MISALIGNED_LOAD != 1'b0)
640
        begin
641
            $display("FAIL. Check the results.");
642
            $finish;
643
        end
644
        FUNCT3 = `FUNCT3_HALF;
645
        IADDER_OUT_1_TO_0 = 2'b11;
646
        #10;
647
        if(MISALIGNED_LOAD != 1'b1)
648
        begin
649
            $display("FAIL. Check the results.");
650
            $finish;
651
        end
652
 
653
        $display("MISALIGNED_LOAD generation for LH OK.");
654
 
655
        FUNCT3 = `FUNCT3_WORD;
656
        IADDER_OUT_1_TO_0 = 2'b00;
657
        #10;
658
        if(LOAD_SIZE != `LOAD_WORD)
659
        begin
660
            $display("FAIL. Check the results.");
661
            $finish;
662
        end
663
        if(LOAD_UNSIGNED != 1'b0)
664
        begin
665
            $display("FAIL. Check the results.");
666
            $finish;
667
        end
668
        if(MISALIGNED_LOAD != 1'b0)
669
        begin
670
            $display("FAIL. Check the results.");
671
            $finish;
672
        end
673
 
674
        $display("Load unit signals for LW... OK.");
675
 
676
        $display("Testing signal MISALIGNED_LOAD for LW...");
677
 
678
        FUNCT3 = `FUNCT3_WORD;
679
        IADDER_OUT_1_TO_0 = 2'b01;
680
        #10;
681
        if(MISALIGNED_LOAD != 1'b1)
682
        begin
683
            $display("FAIL. Check the results.");
684
            $finish;
685
        end
686
        FUNCT3 = `FUNCT3_WORD;
687
        IADDER_OUT_1_TO_0 = 2'b10;
688
        #10;
689
        if(MISALIGNED_LOAD != 1'b1)
690
        begin
691
            $display("FAIL. Check the results.");
692
            $finish;
693
        end
694
        FUNCT3 = `FUNCT3_WORD;
695
        IADDER_OUT_1_TO_0 = 2'b11;
696
        #10;
697
        if(MISALIGNED_LOAD != 1'b1)
698
        begin
699
            $display("FAIL. Check the results.");
700
            $finish;
701
        end
702
 
703
        $display("MISALIGNED_LOAD generation for LW OK.");
704
 
705
        FUNCT3 = `FUNCT3_BYTE_U;
706
        IADDER_OUT_1_TO_0 = 2'b00;
707
        #10;
708
        if(LOAD_SIZE != `LOAD_BYTE)
709
        begin
710
            $display("FAIL. Check the results.");
711
            $finish;
712
        end
713
        if(LOAD_UNSIGNED != 1'b1)
714
        begin
715
            $display("FAIL. Check the results.");
716
            $finish;
717
        end
718
        if(MISALIGNED_LOAD != 1'b0)
719
        begin
720
            $display("FAIL. Check the results.");
721
            $finish;
722
        end
723
 
724
        $display("Load unit signals for LBU... OK.");
725
 
726
        $display("Testing signal MISALIGNED_LOAD for LBU...");
727
 
728
        FUNCT3 = `FUNCT3_BYTE_U;
729
        IADDER_OUT_1_TO_0 = 2'b01;
730
        #10;
731
        if(MISALIGNED_LOAD != 1'b0)
732
        begin
733
            $display("FAIL. Check the results.");
734
            $finish;
735
        end
736
        FUNCT3 = `FUNCT3_BYTE_U;
737
        IADDER_OUT_1_TO_0 = 2'b10;
738
        #10;
739
        if(MISALIGNED_LOAD != 1'b0)
740
        begin
741
            $display("FAIL. Check the results.");
742
            $finish;
743
        end
744
        FUNCT3 = `FUNCT3_BYTE_U;
745
        IADDER_OUT_1_TO_0 = 2'b11;
746
        #10;
747
        if(MISALIGNED_LOAD != 1'b0)
748
        begin
749
            $display("FAIL. Check the results.");
750
            $finish;
751
        end
752
 
753
        $display("MISALIGNED_LOAD generation for LBU OK.");
754
 
755
        FUNCT3 = `FUNCT3_HALF_U;
756
        IADDER_OUT_1_TO_0 = 2'b00;
757
        #10;
758
        if(LOAD_SIZE != `LOAD_HALF)
759
        begin
760
            $display("FAIL. Check the results.");
761
            $finish;
762
        end
763
        if(LOAD_UNSIGNED != 1'b1)
764
        begin
765
            $display("FAIL. Check the results.");
766
            $finish;
767
        end
768
        if(MISALIGNED_LOAD != 1'b0)
769
        begin
770
            $display("FAIL. Check the results.");
771
            $finish;
772
        end
773
 
774
        $display("Load unit signals for LHU... OK.");
775
 
776
        $display("Testing signal MISALIGNED_LOAD for LHU...");
777
 
778
        FUNCT3 = `FUNCT3_HALF_U;
779
        IADDER_OUT_1_TO_0 = 2'b01;
780
        #10;
781
        if(MISALIGNED_LOAD != 1'b1)
782
        begin
783
            $display("FAIL. Check the results.");
784
            $finish;
785
        end
786
        FUNCT3 = `FUNCT3_HALF_U;
787
        IADDER_OUT_1_TO_0 = 2'b10;
788
        #10;
789
        if(MISALIGNED_LOAD != 1'b0)
790
        begin
791
            $display("FAIL. Check the results.");
792
            $finish;
793
        end
794
        FUNCT3 = `FUNCT3_HALF_U;
795
        IADDER_OUT_1_TO_0 = 2'b11;
796
        #10;
797
        if(MISALIGNED_LOAD != 1'b1)
798
        begin
799
            $display("FAIL. Check the results.");
800
            $finish;
801
        end
802
 
803
        $display("MISALIGNED_LOAD generation for LHU OK.");
804
 
805
        $display("Signals for load unit successfuly tested.");
806
 
807
        $display("LOAD opcode successfully tested.");
808
 
809
        $display("Testing STORE opcode operation...");
810
 
811
        $display("Testing signals common to all instructions...");
812
 
813
        opcode_6_to_2 = `OPCODE_STORE;
814
        OPCODE = {opcode_6_to_2, 2'b11};
815
        IADDER_OUT_1_TO_0 = 2'b00;
816
 
817
        #10;
818
        if(MEM_WR_REQ != 1'b1)
819
        begin
820
            $display("FAIL. Check the results.");
821
            $finish;
822
        end
823
        if(MISALIGNED_LOAD != 1'b0)
824
        begin
825
            $display("FAIL. Check the results.");
826
            $finish;
827
        end
828
        if(MISALIGNED_STORE != 1'b0)
829
        begin
830
            $display("FAIL. Check the results.");
831
            $finish;
832
        end
833
        if(ILLEGAL_INSTR != 1'b0)
834
        begin
835
            $display("FAIL. Check the results.");
836
            $finish;
837
        end
838
        if(RF_WR_EN != 1'b0)
839
        begin
840
            $display("FAIL. Check the results.");
841
            $finish;
842
        end
843
        if(IADDER_SRC != 1'b1)
844
        begin
845
            $display("FAIL. Check the results.");
846
            $finish;
847
        end
848
        if(CSR_WR_EN != 1'b0)
849
        begin
850
            $display("FAIL. Check the results.");
851
            $finish;
852
        end
853
        if(IMM_TYPE != `S_TYPE)
854
        begin
855
            $display("FAIL. Check the results.");
856
            $finish;
857
        end
858
 
859
        TRAP_TAKEN = 1'b1;
860
        #10;
861
        if(MEM_WR_REQ != 1'b0)
862
        begin
863
            $display("FAIL. Check the results.");
864
            $finish;
865
        end
866
        TRAP_TAKEN = 1'b0;
867
 
868
        $display("STORE control signals common to all instructions successfully tested.");
869
 
870
        $display("Testing signal MISALIGNED_STORE for SB...");
871
 
872
        FUNCT3 = `FUNCT3_BYTE;
873
        IADDER_OUT_1_TO_0 = 2'b00;
874
        #10;
875
        if(MISALIGNED_STORE != 1'b0)
876
        begin
877
            $display("FAIL. Check the results.");
878
            $finish;
879
        end
880
        FUNCT3 = `FUNCT3_BYTE;
881
        IADDER_OUT_1_TO_0 = 2'b01;
882
        #10;
883
        if(MISALIGNED_STORE != 1'b0)
884
        begin
885
            $display("FAIL. Check the results.");
886
            $finish;
887
        end
888
        FUNCT3 = `FUNCT3_BYTE;
889
        IADDER_OUT_1_TO_0 = 2'b10;
890
        #10;
891
        if(MISALIGNED_STORE != 1'b0)
892
        begin
893
            $display("FAIL. Check the results.");
894
            $finish;
895
        end
896
        FUNCT3 = `FUNCT3_BYTE;
897
        IADDER_OUT_1_TO_0 = 2'b11;
898
        #10;
899
        if(MISALIGNED_STORE != 1'b0)
900
        begin
901
            $display("FAIL. Check the results.");
902
            $finish;
903
        end
904
 
905
        $display("MISALIGNED_STORE generation for SB OK.");
906
 
907
        $display("Testing signal MISALIGNED_STORE for SH...");
908
 
909
        FUNCT3 = `FUNCT3_HALF;
910
        IADDER_OUT_1_TO_0 = 2'b00;
911
        #10;
912
        if(MISALIGNED_STORE != 1'b0)
913
        begin
914
            $display("FAIL. Check the results.");
915
            $finish;
916
        end
917
        FUNCT3 = `FUNCT3_HALF;
918
        IADDER_OUT_1_TO_0 = 2'b01;
919
        #10;
920
        if(MISALIGNED_STORE != 1'b1)
921
        begin
922
            $display("FAIL. Check the results.");
923
            $finish;
924
        end
925
        FUNCT3 = `FUNCT3_HALF;
926
        IADDER_OUT_1_TO_0 = 2'b10;
927
        #10;
928
        if(MISALIGNED_STORE != 1'b0)
929
        begin
930
            $display("FAIL. Check the results.");
931
            $finish;
932
        end
933
        FUNCT3 = `FUNCT3_HALF;
934
        IADDER_OUT_1_TO_0 = 2'b11;
935
        #10;
936
        if(MISALIGNED_STORE != 1'b1)
937
        begin
938
            $display("FAIL. Check the results.");
939
            $finish;
940
        end
941
 
942
        $display("MISALIGNED_STORE generation for SH OK.");
943
 
944
        $display("Testing signal MISALIGNED_STORE for SW...");
945
 
946
        FUNCT3 = `FUNCT3_WORD;
947
        IADDER_OUT_1_TO_0 = 2'b00;
948
        #10;
949
        if(MISALIGNED_STORE != 1'b0)
950
        begin
951
            $display("FAIL. Check the results.");
952
            $finish;
953
        end
954
        FUNCT3 = `FUNCT3_WORD;
955
        IADDER_OUT_1_TO_0 = 2'b01;
956
        #10;
957
        if(MISALIGNED_STORE != 1'b1)
958
        begin
959
            $display("FAIL. Check the results.");
960
            $finish;
961
        end
962
        FUNCT3 = `FUNCT3_WORD;
963
        IADDER_OUT_1_TO_0 = 2'b10;
964
        #10;
965
        if(MISALIGNED_STORE != 1'b1)
966
        begin
967
            $display("FAIL. Check the results.");
968
            $finish;
969
        end
970
        FUNCT3 = `FUNCT3_WORD;
971
        IADDER_OUT_1_TO_0 = 2'b11;
972
        #10;
973
        if(MISALIGNED_STORE != 1'b1)
974
        begin
975
            $display("FAIL. Check the results.");
976
            $finish;
977
        end
978
 
979
        $display("MISALIGNED_STORE generation for SW OK.");
980
 
981
        $display("STORE operation successfully tested.");
982
 
983
        $display("Testing BRANCH opcode signals generation...");
984
 
985
        opcode_6_to_2 = `OPCODE_BRANCH;
986
        OPCODE = {opcode_6_to_2, 2'b11};
987
        IADDER_OUT_1_TO_0 = 2'b00;
988
 
989
        #10;
990
        if(MEM_WR_REQ != 1'b0)
991
        begin
992
            $display("FAIL. Check the results.");
993
            $finish;
994
        end
995
        if(ILLEGAL_INSTR != 1'b0)
996
        begin
997
            $display("FAIL. Check the results.");
998
            $finish;
999
        end
1000
        if(RF_WR_EN != 1'b0)
1001
        begin
1002
            $display("FAIL. Check the results.");
1003
            $finish;
1004
        end
1005
        if(IADDER_SRC != 1'b0)
1006
        begin
1007
            $display("FAIL. Check the results.");
1008
            $finish;
1009
        end
1010
        if(CSR_WR_EN != 1'b0)
1011
        begin
1012
            $display("FAIL. Check the results.");
1013
            $finish;
1014
        end
1015
        if(IMM_TYPE != `B_TYPE)
1016
        begin
1017
            $display("FAIL. Check the results.");
1018
            $finish;
1019
        end
1020
 
1021
        $display("BRANCH control signals successfully tested.");
1022
 
1023
        $display("Testing JAL control signals generation...");
1024
 
1025
        opcode_6_to_2 = `OPCODE_JAL;
1026
        OPCODE = {opcode_6_to_2, 2'b11};
1027
 
1028
        #10;
1029
        if(MEM_WR_REQ != 1'b0)
1030
        begin
1031
            $display("FAIL. Check the results.");
1032
            $finish;
1033
        end
1034
        if(ILLEGAL_INSTR != 1'b0)
1035
        begin
1036
            $display("FAIL. Check the results.");
1037
            $finish;
1038
        end
1039
        if(RF_WR_EN != 1'b1)
1040
        begin
1041
            $display("FAIL. Check the results.");
1042
            $finish;
1043
        end
1044
        if(IADDER_SRC != 1'b0)
1045
        begin
1046
            $display("FAIL. Check the results.");
1047
            $finish;
1048
        end
1049
        if(WB_MUX_SEL != `WB_PC_PLUS)
1050
        begin
1051
            $display("FAIL. Check the results.");
1052
            $finish;
1053
        end
1054
        if(CSR_WR_EN != 1'b0)
1055
        begin
1056
            $display("FAIL. Check the results.");
1057
            $finish;
1058
        end
1059
        if(IMM_TYPE != `J_TYPE)
1060
        begin
1061
            $display("FAIL. Check the results.");
1062
            $finish;
1063
        end
1064
 
1065
        $display("JAL control signals successfully tested.");
1066
 
1067
        $display("Testing JALR control signals generation...");
1068
 
1069
        opcode_6_to_2 = `OPCODE_JALR;
1070
        OPCODE = {opcode_6_to_2, 2'b11};
1071
 
1072
        #10;
1073
        if(MEM_WR_REQ != 1'b0)
1074
        begin
1075
            $display("FAIL. Check the results.");
1076
            $finish;
1077
        end
1078
        if(ILLEGAL_INSTR != 1'b0)
1079
        begin
1080
            $display("FAIL. Check the results.");
1081
            $finish;
1082
        end
1083
        if(RF_WR_EN != 1'b1)
1084
        begin
1085
            $display("FAIL. Check the results.");
1086
            $finish;
1087
        end
1088
 
1089
        if(WB_MUX_SEL != `WB_PC_PLUS)
1090
        begin
1091
            $display("FAIL. Check the results.");
1092
            $finish;
1093
        end
1094
        if(IADDER_SRC != 1'b1)
1095
        begin
1096
            $display("FAIL. Check the results.");
1097
            $finish;
1098
        end
1099
        if(CSR_WR_EN != 1'b0)
1100
        begin
1101
            $display("FAIL. Check the results.");
1102
            $finish;
1103
        end
1104
        if(IMM_TYPE != `I_TYPE)
1105
        begin
1106
            $display("FAIL. Check the results.");
1107
            $finish;
1108
        end
1109
 
1110
        $display("JALR control signals successfully tested.");
1111
 
1112
        $display("Testing LUI opcode operation...");
1113
 
1114
        opcode_6_to_2 = `OPCODE_LUI;
1115
        OPCODE = {opcode_6_to_2, 2'b11};
1116
 
1117
        #10;
1118
        if(MEM_WR_REQ != 1'b0)
1119
        begin
1120
            $display("FAIL. Check the results.");
1121
            $finish;
1122
        end
1123
        if(ILLEGAL_INSTR != 1'b0)
1124
        begin
1125
            $display("FAIL. Check the results.");
1126
            $finish;
1127
        end
1128
        if(RF_WR_EN != 1'b1)
1129
        begin
1130
            $display("FAIL. Check the results.");
1131
            $finish;
1132
        end
1133
 
1134
        if(WB_MUX_SEL != `WB_IMM)
1135
        begin
1136
            $display("FAIL. Check the results.");
1137
            $finish;
1138
        end
1139
        if(CSR_WR_EN != 1'b0)
1140
        begin
1141
            $display("FAIL. Check the results.");
1142
            $finish;
1143
        end
1144
        if(IMM_TYPE != `U_TYPE)
1145
        begin
1146
            $display("FAIL. Check the results.");
1147
            $finish;
1148
        end
1149
 
1150
        $display("LUI control signals successfully tested.");
1151
 
1152
        $display("Testing AUIPC control signals generation...");
1153
 
1154
        opcode_6_to_2 = `OPCODE_AUIPC;
1155
        OPCODE = {opcode_6_to_2, 2'b11};
1156
 
1157
        #10;
1158
        if(MEM_WR_REQ != 1'b0)
1159
        begin
1160
            $display("FAIL. Check the results.");
1161
            $finish;
1162
        end
1163
        if(ILLEGAL_INSTR != 1'b0)
1164
        begin
1165
            $display("FAIL. Check the results.");
1166
            $finish;
1167
        end
1168
        if(RF_WR_EN != 1'b1)
1169
        begin
1170
            $display("FAIL. Check the results.");
1171
            $finish;
1172
        end
1173
        if(WB_MUX_SEL != `WB_IADDER_OUT)
1174
        begin
1175
            $display("FAIL. Check the results.");
1176
            $finish;
1177
        end
1178
        if(IADDER_SRC != 1'b0)
1179
        begin
1180
            $display("FAIL. Check the results.");
1181
            $finish;
1182
        end
1183
        if(CSR_WR_EN != 1'b0)
1184
        begin
1185
            $display("FAIL. Check the results.");
1186
            $finish;
1187
        end
1188
        if(IMM_TYPE != `U_TYPE)
1189
        begin
1190
            $display("FAIL. Check the results.");
1191
            $finish;
1192
        end
1193
 
1194
        $display("AUIPC control signals successfully tested.");
1195
 
1196
        $display("Testing MISC-MEM control signals generation...");
1197
 
1198
        opcode_6_to_2 = `OPCODE_MISC_MEM;
1199
        OPCODE = {opcode_6_to_2, 2'b11};
1200
 
1201
        #10;
1202
        if(MEM_WR_REQ != 1'b0)
1203
        begin
1204
            $display("FAIL. Check the results.");
1205
            $finish;
1206
        end
1207
        if(ILLEGAL_INSTR != 1'b0)
1208
        begin
1209
            $display("FAIL. Check the results.");
1210
            $finish;
1211
        end
1212
        if(RF_WR_EN != 1'b0)
1213
        begin
1214
            $display("FAIL. Check the results.");
1215
            $finish;
1216
        end
1217
        if(CSR_WR_EN != 1'b0)
1218
        begin
1219
            $display("FAIL. Check the results.");
1220
            $finish;
1221
        end
1222
 
1223
        $display("MISM-MEM control signals successfully tested.");
1224
 
1225
        $display("Testing SYSteel Core control signals operation...");
1226
 
1227
        $display("Testing ECALL, EBREAK, MRET and WFI instructions...");
1228
 
1229
        opcode_6_to_2 = `OPCODE_SYSTEM;
1230
        OPCODE = {opcode_6_to_2, 2'b11};
1231
        FUNCT3 = 3'b000;
1232
 
1233
        #10;
1234
        if(MEM_WR_REQ != 1'b0)
1235
        begin
1236
            $display("FAIL. Check the results.");
1237
            $finish;
1238
        end
1239
        if(ILLEGAL_INSTR != 1'b0)
1240
        begin
1241
            $display("FAIL. Check the results.");
1242
            $finish;
1243
        end
1244
        if(RF_WR_EN != 1'b0)
1245
        begin
1246
            $display("FAIL. Check the results.");
1247
            $finish;
1248
        end
1249
        if(CSR_WR_EN != 1'b0)
1250
        begin
1251
            $display("FAIL. Check the results.");
1252
            $finish;
1253
        end
1254
 
1255
        $display("ECALL, EBREAK, MRET and WFI successfully tested.");
1256
 
1257
        $display("Testing CSRRW...");
1258
 
1259
        FUNCT3 = 3'b001;
1260
        #10;
1261
        if(ILLEGAL_INSTR != 1'b0)
1262
        begin
1263
            $display("FAIL. Check the results.");
1264
            $finish;
1265
        end
1266
        if(RF_WR_EN != 1'b1)
1267
        begin
1268
            $display("FAIL. Check the results.");
1269
            $finish;
1270
        end
1271
        if(CSR_WR_EN != 1'b1)
1272
        begin
1273
            $display("FAIL. Check the results.");
1274
            $finish;
1275
        end
1276
        if(IMM_TYPE != `CSR_TYPE)
1277
        begin
1278
            $display("FAIL. Check the results.");
1279
            $finish;
1280
        end
1281
        if(CSR_OP != FUNCT3)
1282
        begin
1283
            $display("FAIL. Check the results.");
1284
            $finish;
1285
        end
1286
 
1287
        $display("CSRRW successfully tested.");
1288
 
1289
        $display("Testing CSRRS...");
1290
 
1291
        FUNCT3 = 3'b010;
1292
        #10;
1293
        if(ILLEGAL_INSTR != 1'b0)
1294
        begin
1295
            $display("FAIL. Check the results.");
1296
            $finish;
1297
        end
1298
        if(RF_WR_EN != 1'b1)
1299
        begin
1300
            $display("FAIL. Check the results.");
1301
            $finish;
1302
        end
1303
        if(CSR_WR_EN != 1'b1)
1304
        begin
1305
            $display("FAIL. Check the results.");
1306
            $finish;
1307
        end
1308
        if(IMM_TYPE != `CSR_TYPE)
1309
        begin
1310
            $display("FAIL. Check the results.");
1311
            $finish;
1312
        end
1313
        if(CSR_OP != FUNCT3)
1314
        begin
1315
            $display("FAIL. Check the results.");
1316
            $finish;
1317
        end
1318
 
1319
        $display("CSRRS successfully tested.");
1320
 
1321
        $display("Testing CSRRC...");
1322
 
1323
        FUNCT3 = 3'b011;
1324
        #10;
1325
        if(ILLEGAL_INSTR != 1'b0)
1326
        begin
1327
            $display("FAIL. Check the results.");
1328
            $finish;
1329
        end
1330
        if(RF_WR_EN != 1'b1)
1331
        begin
1332
            $display("FAIL. Check the results.");
1333
            $finish;
1334
        end
1335
        if(CSR_WR_EN != 1'b1)
1336
        begin
1337
            $display("FAIL. Check the results.");
1338
            $finish;
1339
        end
1340
        if(IMM_TYPE != `CSR_TYPE)
1341
        begin
1342
            $display("FAIL. Check the results.");
1343
            $finish;
1344
        end
1345
        if(CSR_OP != FUNCT3)
1346
        begin
1347
            $display("FAIL. Check the results.");
1348
            $finish;
1349
        end
1350
 
1351
        $display("CSRRC successfully tested.");
1352
 
1353
        $display("Testing CSRRWI...");
1354
 
1355
        FUNCT3 = 3'b101;
1356
        #10;
1357
        if(ILLEGAL_INSTR != 1'b0)
1358
        begin
1359
            $display("FAIL. Check the results.");
1360
            $finish;
1361
        end
1362
        if(RF_WR_EN != 1'b1)
1363
        begin
1364
            $display("FAIL. Check the results.");
1365
            $finish;
1366
        end
1367
        if(CSR_WR_EN != 1'b1)
1368
        begin
1369
            $display("FAIL. Check the results.");
1370
            $finish;
1371
        end
1372
        if(IMM_TYPE != `CSR_TYPE)
1373
        begin
1374
            $display("FAIL. Check the results.");
1375
            $finish;
1376
        end
1377
        if(CSR_OP != FUNCT3)
1378
        begin
1379
            $display("FAIL. Check the results.");
1380
            $finish;
1381
        end
1382
 
1383
        $display("CSRRWI successfully tested.");
1384
 
1385
        $display("Testing CSRRSI...");
1386
 
1387
        FUNCT3 = 3'b110;
1388
        #10;
1389
        if(ILLEGAL_INSTR != 1'b0)
1390
        begin
1391
            $display("FAIL. Check the results.");
1392
            $finish;
1393
        end
1394
        if(RF_WR_EN != 1'b1)
1395
        begin
1396
            $display("FAIL. Check the results.");
1397
            $finish;
1398
        end
1399
        if(CSR_WR_EN != 1'b1)
1400
        begin
1401
            $display("FAIL. Check the results.");
1402
            $finish;
1403
        end
1404
        if(IMM_TYPE != `CSR_TYPE)
1405
        begin
1406
            $display("FAIL. Check the results.");
1407
            $finish;
1408
        end
1409
        if(CSR_OP != FUNCT3)
1410
        begin
1411
            $display("FAIL. Check the results.");
1412
            $finish;
1413
        end
1414
 
1415
        $display("CSRRSI successfully tested.");
1416
 
1417
        $display("Steel Core control signals successfully tested.");
1418
 
1419
        $display("Testing illegal instructions...");
1420
 
1421
        OPCODE = {`OPCODE_OP,2'b10};
1422
        #10;
1423
        if(ILLEGAL_INSTR != 1'b1)
1424
        begin
1425
            $display("FAIL. Check the results.");
1426
            $finish;
1427
        end
1428
 
1429
        OPCODE = {`OPCODE_OP,2'b01};
1430
        #10;
1431
        if(ILLEGAL_INSTR != 1'b1)
1432
        begin
1433
            $display("FAIL. Check the results.");
1434
            $finish;
1435
        end
1436
 
1437
        OPCODE = {5'b11111,2'b11};
1438
        #10;
1439
        if(ILLEGAL_INSTR != 1'b1)
1440
        begin
1441
            $display("FAIL. Check the results.");
1442
            $finish;
1443
        end
1444
 
1445
        $display("Illegal instructions successfully tested.");
1446
 
1447
        $display("Decoder successfully tested.");
1448
 
1449
    end
1450
 
1451
endmodule

powered by: WebSVN 2.1.0

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