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

Subversion Repositories steelcore

[/] [rtl/] [bench/] [tb_machine_mode.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: 02.05.2020 15:45:27
5
// Module Name: tb_machine_mode
6
// Project Name: Steel Core
7
// Description: M-mode operation testbench
8
// 
9
// Dependencies: globals.vh
10
//               machine_control.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
module tb_machine_mode();
46
 
47
    reg CLK;
48
    reg RESET;
49
 
50
    reg ILLEGAL_INSTR;
51
    reg MISALIGNED_INSTR;
52
    reg MISALIGNED_LOAD;
53
    reg MISALIGNED_STORE;
54
 
55
    reg [6:2] OPCODE_6_TO_2;
56
    reg [2:0] FUNCT3;
57
    reg [6:0] FUNCT7;
58
    reg [4:0] RS1_ADDR;
59
    reg [4:0] RS2_ADDR;
60
    reg [4:0] RD_ADDR;
61
 
62
    reg E_IRQ;
63
    reg T_IRQ;
64
    reg S_IRQ;
65
 
66
    reg MIE;
67
    reg MEIE;
68
    reg MTIE;
69
    reg MSIE;
70
    reg MEIP;
71
    reg MTIP;
72
    reg MSIP;
73
 
74
    wire I_OR_E;
75
    wire SET_EPC;
76
    wire SET_CAUSE;
77
    wire [3:0] CAUSE;
78
    wire INSTRET_INC;
79
    wire MIE_CLEAR;
80
    wire MIE_SET;
81
 
82
    wire [1:0] PC_SRC;
83
 
84
    wire FLUSH;
85
 
86
    wire TRAP_TAKEN;
87
 
88
    machine_control dut(
89
 
90
        .CLK(CLK),
91
        .RESET(RESET),
92
 
93
        .ILLEGAL_INSTR(ILLEGAL_INSTR),
94
        .MISALIGNED_INSTR(MISALIGNED_INSTR),
95
        .MISALIGNED_LOAD(MISALIGNED_LOAD),
96
        .MISALIGNED_STORE(MISALIGNED_STORE),
97
 
98
        .OPCODE_6_TO_2(OPCODE_6_TO_2),
99
        .FUNCT3(FUNCT3),
100
        .FUNCT7(FUNCT7),
101
        .RS1_ADDR(RS1_ADDR),
102
        .RS2_ADDR(RS2_ADDR),
103
        .RD_ADDR(RD_ADDR),
104
 
105
        .E_IRQ(E_IRQ),
106
        .T_IRQ(T_IRQ),
107
        .S_IRQ(S_IRQ),
108
 
109
        .I_OR_E(I_OR_E),
110
        .SET_CAUSE(SET_CAUSE),
111
        .CAUSE(CAUSE),
112
        .SET_EPC(SET_EPC),
113
        .INSTRET_INC(INSTRET_INC),
114
        .MIE_CLEAR(MIE_CLEAR),
115
        .MIE_SET(MIE_SET),
116
        .MIE(MIE),
117
        .MEIE(MEIE),
118
        .MTIE(MTIE),
119
        .MSIE(MSIE),
120
        .MEIP(MEIP),
121
        .MTIP(MTIP),
122
        .MSIP(MSIP),
123
 
124
        .PC_SRC(PC_SRC),
125
 
126
        .FLUSH(FLUSH),
127
 
128
        .TRAP_TAKEN(TRAP_TAKEN)
129
 
130
    );
131
 
132
    always
133
    begin
134
        #10 CLK = !CLK;
135
    end
136
 
137
    initial
138
    begin
139
 
140
        $display("Testing Machine Mode Control module...");
141
 
142
        CLK = 1'b0;
143
        RESET = 1'b0;
144
 
145
        ILLEGAL_INSTR = 1'b0;
146
        MISALIGNED_INSTR = 1'b0;
147
        MISALIGNED_LOAD = 1'b0;
148
        MISALIGNED_STORE = 1'b0;
149
 
150
        OPCODE_6_TO_2 = `OPCODE_OP;
151
        FUNCT3 = `FUNCT3_ADD;
152
        FUNCT7 = `FUNCT7_ADD;
153
        RS1_ADDR = 5'b00000;
154
        RS2_ADDR = 5'b00000;
155
        RD_ADDR = 5'b00000;
156
 
157
        E_IRQ = 1'b0;
158
        T_IRQ = 1'b0;
159
        S_IRQ = 1'b0;
160
 
161
        MIE = 1'b0;
162
        MEIE = 1'b0;
163
        MTIE = 1'b0;
164
        MSIE = 1'b0;
165
        MEIP = 1'b0;
166
        MTIP = 1'b0;
167
        MSIP = 1'b0;
168
 
169
        $display("Testing RESET state...");
170
 
171
        #5;
172
        RESET = 1'b1;
173
        #15;
174
        RESET = 1'b0;
175
 
176
        if(PC_SRC != `PC_BOOT)
177
        begin
178
            $display("FAIL. Check the results.");
179
            $finish;
180
        end
181
        if(I_OR_E != 1'b0)
182
        begin
183
            $display("FAIL. Check the results.");
184
            $finish;
185
        end
186
        if(SET_CAUSE != 1'b0)
187
        begin
188
            $display("FAIL. Check the results.");
189
            $finish;
190
        end
191
        if(SET_EPC != 1'b0)
192
        begin
193
            $display("FAIL. Check the results.");
194
            $finish;
195
        end
196
        if(MIE_CLEAR != 1'b0)
197
        begin
198
            $display("FAIL. Check the results.");
199
            $finish;
200
        end
201
        if(MIE_SET != 1'b0)
202
        begin
203
            $display("FAIL. Check the results.");
204
            $finish;
205
        end
206
        if(FLUSH != 1'b1)
207
        begin
208
            $display("FAIL. Check the results.");
209
            $finish;
210
        end
211
        if(INSTRET_INC != 1'b0)
212
        begin
213
            $display("FAIL. Check the results.");
214
            $finish;
215
        end
216
        $display("RESET state values OK.");
217
 
218
        #20;
219
 
220
        /************************************************************
221
        *************************************************************
222
        ************************************************************/
223
 
224
        $display("Testing OPERATING state...");
225
 
226
        if(PC_SRC != `PC_NEXT)
227
        begin
228
            $display("FAIL. Check the results.");
229
            $finish;
230
        end
231
        if(I_OR_E != 1'b0)
232
        begin
233
            $display("FAIL. Check the results.");
234
            $finish;
235
        end
236
        if(SET_CAUSE != 1'b0)
237
        begin
238
            $display("FAIL. Check the results.");
239
            $finish;
240
        end
241
        if(SET_EPC != 1'b0)
242
        begin
243
            $display("FAIL. Check the results.");
244
            $finish;
245
        end
246
        if(MIE_CLEAR != 1'b0)
247
        begin
248
            $display("FAIL. Check the results.");
249
            $finish;
250
        end
251
        if(MIE_SET != 1'b0)
252
        begin
253
            $display("FAIL. Check the results.");
254
            $finish;
255
        end
256
        if(FLUSH != 1'b0)
257
        begin
258
            $display("FAIL. Check the results.");
259
            $finish;
260
        end
261
        if(INSTRET_INC != 1'b1)
262
        begin
263
            $display("FAIL. Check the results.");
264
            $finish;
265
        end
266
        $display("OPERATING state values OK.");
267
 
268
        /************************************************************
269
        *************************************************************
270
        ************************************************************/
271
 
272
        $display("Testing if the machine keeps in operating state when MIE=0 for all kinds of interrupt...");
273
 
274
        E_IRQ = 1'b1;
275
        #20;
276
        if(PC_SRC != `PC_NEXT)
277
        begin
278
            $display("FAIL. Check the results.");
279
            $finish;
280
        end
281
        E_IRQ = 1'b0;
282
 
283
        T_IRQ = 1'b1;
284
        #20;
285
        if(PC_SRC != `PC_NEXT)
286
        begin
287
            $display("FAIL. Check the results.");
288
            $finish;
289
        end
290
        T_IRQ = 1'b0;
291
 
292
        S_IRQ = 1'b1;
293
        #20;
294
        if(PC_SRC != `PC_NEXT)
295
        begin
296
            $display("FAIL. Check the results.");
297
            $finish;
298
        end
299
        S_IRQ = 1'b0;
300
 
301
        $display("Test OK.");
302
 
303
        /************************************************************
304
        *************************************************************
305
        ************************************************************/
306
 
307
        $display("Testing if the machine changes it state when MIE=0 for all kinds of exceptions.");
308
 
309
        MIE = 1'b0;
310
        ILLEGAL_INSTR = 1'b1;
311
        #20;
312
        if(PC_SRC != `PC_TRAP)
313
        begin
314
            $display("FAIL. Check the results.");
315
            $finish;
316
        end
317
        if(MIE_CLEAR != 1'b1)
318
        begin
319
            $display("FAIL. Check the results.");
320
            $finish;
321
        end
322
        if(SET_EPC != 1'b1)
323
        begin
324
            $display("FAIL. Check the results.");
325
            $finish;
326
        end
327
        if(SET_CAUSE != 1'b1)
328
        begin
329
            $display("FAIL. Check the results.");
330
            $finish;
331
        end
332
        if(CAUSE != 4'b0010)
333
        begin
334
            $display("FAIL. Check the results.");
335
            $finish;
336
        end
337
        if(I_OR_E != 1'b0)
338
        begin
339
            $display("FAIL. Check the results.");
340
            $finish;
341
        end
342
        if(FLUSH != 1'b1)
343
        begin
344
            $display("FAIL. Check the results.");
345
            $finish;
346
        end
347
        if(INSTRET_INC != 1'b0)
348
        begin
349
            $display("FAIL. Check the results.");
350
            $finish;
351
        end
352
        ILLEGAL_INSTR = 1'b0;
353
        #20;
354
        if(PC_SRC != `PC_NEXT)
355
        begin
356
            $display("FAIL. Check the results.");
357
            $finish;
358
        end
359
 
360
        MISALIGNED_INSTR = 1'b1;
361
        #20;
362
        if(PC_SRC != `PC_TRAP)
363
        begin
364
            $display("FAIL. Check the results.");
365
            $finish;
366
        end
367
        if(MIE_CLEAR != 1'b1)
368
        begin
369
            $display("FAIL. Check the results.");
370
            $finish;
371
        end
372
        if(SET_EPC != 1'b1)
373
        begin
374
            $display("FAIL. Check the results.");
375
            $finish;
376
        end
377
        if(SET_CAUSE != 1'b1)
378
        begin
379
            $display("FAIL. Check the results.");
380
            $finish;
381
        end
382
        if(CAUSE != 4'b0000)
383
        begin
384
            $display("FAIL. Check the results.");
385
            $finish;
386
        end
387
        if(I_OR_E != 1'b0)
388
        begin
389
            $display("FAIL. Check the results.");
390
            $finish;
391
        end
392
        if(FLUSH != 1'b1)
393
        begin
394
            $display("FAIL. Check the results.");
395
            $finish;
396
        end
397
        if(INSTRET_INC != 1'b0)
398
        begin
399
            $display("FAIL. Check the results.");
400
            $finish;
401
        end
402
        MISALIGNED_INSTR = 1'b0;
403
        #20;
404
        if(PC_SRC != `PC_NEXT)
405
        begin
406
            $display("FAIL. Check the results.");
407
            $finish;
408
        end
409
 
410
        MISALIGNED_LOAD = 1'b1;
411
        #20;
412
        if(PC_SRC != `PC_TRAP)
413
        begin
414
            $display("FAIL. Check the results.");
415
            $finish;
416
        end
417
        if(MIE_CLEAR != 1'b1)
418
        begin
419
            $display("FAIL. Check the results.");
420
            $finish;
421
        end
422
        if(SET_EPC != 1'b1)
423
        begin
424
            $display("FAIL. Check the results.");
425
            $finish;
426
        end
427
        if(SET_CAUSE != 1'b1)
428
        begin
429
            $display("FAIL. Check the results.");
430
            $finish;
431
        end
432
        if(CAUSE != 4'b0100)
433
        begin
434
            $display("FAIL. Check the results.");
435
            $finish;
436
        end
437
        if(I_OR_E != 1'b0)
438
        begin
439
            $display("FAIL. Check the results.");
440
            $finish;
441
        end
442
        if(FLUSH != 1'b1)
443
        begin
444
            $display("FAIL. Check the results.");
445
            $finish;
446
        end
447
        if(INSTRET_INC != 1'b0)
448
        begin
449
            $display("FAIL. Check the results.");
450
            $finish;
451
        end
452
        MISALIGNED_LOAD = 1'b0;
453
        #20;
454
        if(PC_SRC != `PC_NEXT)
455
        begin
456
            $display("FAIL. Check the results.");
457
            $finish;
458
        end
459
 
460
        MISALIGNED_STORE = 1'b1;
461
        #20;
462
        if(PC_SRC != `PC_TRAP)
463
        begin
464
            $display("FAIL. Check the results.");
465
            $finish;
466
        end
467
        if(MIE_CLEAR != 1'b1)
468
        begin
469
            $display("FAIL. Check the results.");
470
            $finish;
471
        end
472
        if(SET_EPC != 1'b1)
473
        begin
474
            $display("FAIL. Check the results.");
475
            $finish;
476
        end
477
        if(SET_CAUSE != 1'b1)
478
        begin
479
            $display("FAIL. Check the results.");
480
            $finish;
481
        end
482
        if(CAUSE != 4'b0110)
483
        begin
484
            $display("FAIL. Check the results.");
485
            $finish;
486
        end
487
        if(I_OR_E != 1'b0)
488
        begin
489
            $display("FAIL. Check the results.");
490
            $finish;
491
        end
492
        if(FLUSH != 1'b1)
493
        begin
494
            $display("FAIL. Check the results.");
495
            $finish;
496
        end
497
        if(INSTRET_INC != 1'b0)
498
        begin
499
            $display("FAIL. Check the results.");
500
            $finish;
501
        end
502
        MISALIGNED_STORE = 1'b0;
503
        #20;
504
        if(PC_SRC != `PC_NEXT)
505
        begin
506
            $display("FAIL. Check the results.");
507
            $finish;
508
        end
509
 
510
        OPCODE_6_TO_2 = `OPCODE_SYSTEM;
511
        FUNCT3 = `FUNCT3_ECALL;
512
        FUNCT7 = `FUNCT7_ECALL;
513
        RS1_ADDR = `RS1_ECALL;
514
        RS2_ADDR = `RS2_ECALL;
515
        RD_ADDR = `RD_ECALL;
516
        #20;
517
        if(PC_SRC != `PC_TRAP)
518
        begin
519
            $display("FAIL. Check the results.");
520
            $finish;
521
        end
522
        if(MIE_CLEAR != 1'b1)
523
        begin
524
            $display("FAIL. Check the results.");
525
            $finish;
526
        end
527
        if(SET_EPC != 1'b1)
528
        begin
529
            $display("FAIL. Check the results.");
530
            $finish;
531
        end
532
        if(SET_CAUSE != 1'b1)
533
        begin
534
            $display("FAIL. Check the results.");
535
            $finish;
536
        end
537
        if(CAUSE != 4'b1011)
538
        begin
539
            $display("FAIL. Check the results.");
540
            $finish;
541
        end
542
        if(I_OR_E != 1'b0)
543
        begin
544
            $display("FAIL. Check the results.");
545
            $finish;
546
        end
547
        if(FLUSH != 1'b1)
548
        begin
549
            $display("FAIL. Check the results.");
550
            $finish;
551
        end
552
        if(INSTRET_INC != 1'b0)
553
        begin
554
            $display("FAIL. Check the results.");
555
            $finish;
556
        end
557
        OPCODE_6_TO_2 = `OPCODE_OP;
558
        FUNCT3 = `FUNCT3_ADD;
559
        FUNCT7 = `FUNCT7_ADD;
560
        RS1_ADDR = 5'b00000;
561
        RS2_ADDR = 5'b00000;
562
        RD_ADDR = 5'b00000;
563
        #20;
564
        if(PC_SRC != `PC_NEXT)
565
        begin
566
            $display("FAIL. Check the results.");
567
            $finish;
568
        end
569
 
570
        OPCODE_6_TO_2 = `OPCODE_SYSTEM;
571
        FUNCT3 = `FUNCT3_EBREAK;
572
        FUNCT7 = `FUNCT7_EBREAK;
573
        RS1_ADDR = `RS1_EBREAK;
574
        RS2_ADDR = `RS2_EBREAK;
575
        RD_ADDR = `RD_EBREAK;
576
        #20;
577
        if(PC_SRC != `PC_TRAP)
578
        begin
579
            $display("FAIL. Check the results.");
580
            $finish;
581
        end
582
        if(MIE_CLEAR != 1'b1)
583
        begin
584
            $display("FAIL. Check the results.");
585
            $finish;
586
        end
587
        if(SET_EPC != 1'b1)
588
        begin
589
            $display("FAIL. Check the results.");
590
            $finish;
591
        end
592
        if(SET_CAUSE != 1'b1)
593
        begin
594
            $display("FAIL. Check the results.");
595
            $finish;
596
        end
597
        if(CAUSE != 4'b0011)
598
        begin
599
            $display("FAIL. Check the results.");
600
            $finish;
601
        end
602
        if(I_OR_E != 1'b0)
603
        begin
604
            $display("FAIL. Check the results.");
605
            $finish;
606
        end
607
        if(FLUSH != 1'b1)
608
        begin
609
            $display("FAIL. Check the results.");
610
            $finish;
611
        end
612
        if(INSTRET_INC != 1'b0)
613
        begin
614
            $display("FAIL. Check the results.");
615
            $finish;
616
        end
617
        OPCODE_6_TO_2 = `OPCODE_OP;
618
        FUNCT3 = `FUNCT3_ADD;
619
        FUNCT7 = `FUNCT7_ADD;
620
        RS1_ADDR = 5'b00000;
621
        RS2_ADDR = 5'b00000;
622
        RD_ADDR = 5'b00000;
623
        #20;
624
        if(PC_SRC != `PC_NEXT)
625
        begin
626
            $display("FAIL. Check the results.");
627
            $finish;
628
        end
629
 
630
        $display("Test OK.");
631
 
632
        /************************************************************
633
        *************************************************************
634
        ************************************************************/
635
 
636
        $display("Testing if the machine keeps in operating state when MIE=1 for all types of interrupt when MTIE=0, MSIE=0 and MEIE=0...");
637
 
638
        MIE = 1'b1;
639
        E_IRQ = 1'b1;
640
        #20;
641
        if(PC_SRC != `PC_NEXT)
642
        begin
643
            $display("FAIL. Check the results.");
644
            $finish;
645
        end
646
        E_IRQ = 1'b0;
647
 
648
        T_IRQ = 1'b1;
649
        #20;
650
        if(PC_SRC != `PC_NEXT)
651
        begin
652
            $display("FAIL. Check the results.");
653
            $finish;
654
        end
655
        T_IRQ = 1'b0;
656
 
657
        S_IRQ = 1'b1;
658
        #20;
659
        if(PC_SRC != `PC_NEXT)
660
        begin
661
            $display("FAIL. Check the results.");
662
            $finish;
663
        end
664
        S_IRQ = 1'b0;
665
 
666
        $display("Test OK.");
667
 
668
        /************************************************************
669
        *************************************************************
670
        ************************************************************/
671
 
672
        $display("Testing if the machine change its state only for external interrupts in operating state when MIE=1 and MTIE=0, MSIE=0 and MEIE=1...");
673
 
674
        MIE = 1'b1;
675
        MEIE = 1'b1;
676
        E_IRQ = 1'b1;
677
        #20;
678
        if(PC_SRC != `PC_TRAP)
679
        begin
680
            $display("FAIL. Check the results.");
681
            $finish;
682
        end
683
        if(MIE_CLEAR != 1'b1)
684
        begin
685
            $display("FAIL. Check the results.");
686
            $finish;
687
        end
688
        if(SET_EPC != 1'b1)
689
        begin
690
            $display("FAIL. Check the results.");
691
            $finish;
692
        end
693
        if(SET_CAUSE != 1'b1)
694
        begin
695
            $display("FAIL. Check the results.");
696
            $finish;
697
        end
698
        if(CAUSE != 4'b1011)
699
        begin
700
            $display("FAIL. Check the results.");
701
            $finish;
702
        end
703
        if(I_OR_E != 1'b1)
704
        begin
705
            $display("FAIL. Check the results.");
706
            $finish;
707
        end
708
        if(FLUSH != 1'b1)
709
        begin
710
            $display("FAIL. Check the results.");
711
            $finish;
712
        end
713
        if(INSTRET_INC != 1'b0)
714
        begin
715
            $display("FAIL. Check the results.");
716
            $finish;
717
        end
718
        E_IRQ = 1'b0;
719
        #20;
720
        if(PC_SRC != `PC_NEXT)
721
        begin
722
            $display("FAIL. Check the results.");
723
            $finish;
724
        end
725
 
726
        T_IRQ = 1'b1;
727
        #20;
728
        if(PC_SRC != `PC_NEXT)
729
        begin
730
            $display("FAIL. Check the results.");
731
            $finish;
732
        end
733
        T_IRQ = 1'b0;
734
 
735
        S_IRQ = 1'b1;
736
        #20;
737
        if(PC_SRC != `PC_NEXT)
738
        begin
739
            $display("FAIL. Check the results.");
740
            $finish;
741
        end
742
        S_IRQ = 1'b0;
743
 
744
        MEIE = 1'b0;
745
 
746
        $display("Test OK.");
747
 
748
        /************************************************************
749
        *************************************************************
750
        ************************************************************/
751
 
752
        $display("Testing if the machine change its state only for timer interrupts in operating state when MIE=1 and MTIE=1, MSIE=0 and MEIE=0...");
753
 
754
        MIE = 1'b1;
755
        MTIE = 1'b1;
756
        T_IRQ = 1'b1;
757
        #20;
758
        if(PC_SRC != `PC_TRAP)
759
        begin
760
            $display("FAIL. Check the results.");
761
            $finish;
762
        end
763
        if(MIE_CLEAR != 1'b1)
764
        begin
765
            $display("FAIL. Check the results.");
766
            $finish;
767
        end
768
        if(SET_EPC != 1'b1)
769
        begin
770
            $display("FAIL. Check the results.");
771
            $finish;
772
        end
773
        if(SET_CAUSE != 1'b1)
774
        begin
775
            $display("FAIL. Check the results.");
776
            $finish;
777
        end
778
        if(CAUSE != 4'b0111)
779
        begin
780
            $display("FAIL. Check the results.");
781
            $finish;
782
        end
783
        if(I_OR_E != 1'b1)
784
        begin
785
            $display("FAIL. Check the results.");
786
            $finish;
787
        end
788
        if(FLUSH != 1'b1)
789
        begin
790
            $display("FAIL. Check the results.");
791
            $finish;
792
        end
793
        if(INSTRET_INC != 1'b0)
794
        begin
795
            $display("FAIL. Check the results.");
796
            $finish;
797
        end
798
        T_IRQ = 1'b0;
799
        #20;
800
        if(PC_SRC != `PC_NEXT)
801
        begin
802
            $display("FAIL. Check the results.");
803
            $finish;
804
        end
805
 
806
        E_IRQ = 1'b1;
807
        #20;
808
        if(PC_SRC != `PC_NEXT)
809
        begin
810
            $display("FAIL. Check the results.");
811
            $finish;
812
        end
813
        E_IRQ = 1'b0;
814
 
815
        S_IRQ = 1'b1;
816
        #20;
817
        if(PC_SRC != `PC_NEXT)
818
        begin
819
            $display("FAIL. Check the results.");
820
            $finish;
821
        end
822
        S_IRQ = 1'b0;
823
 
824
        MTIE = 1'b0;
825
 
826
        $display("Test OK.");
827
 
828
        /************************************************************
829
        *************************************************************
830
        ************************************************************/
831
 
832
        $display("Testing if the machine change its state only for software interrupts in operating state when MIE=1 and MTIE=0, MSIE=1 and MEIE=0...");
833
 
834
        MIE = 1'b1;
835
        MSIE = 1'b1;
836
        S_IRQ = 1'b1;
837
        #20;
838
        if(PC_SRC != `PC_TRAP)
839
        begin
840
            $display("FAIL. Check the results.");
841
            $finish;
842
        end
843
        if(MIE_CLEAR != 1'b1)
844
        begin
845
            $display("FAIL. Check the results.");
846
            $finish;
847
        end
848
        if(SET_EPC != 1'b1)
849
        begin
850
            $display("FAIL. Check the results.");
851
            $finish;
852
        end
853
        if(SET_CAUSE != 1'b1)
854
        begin
855
            $display("FAIL. Check the results.");
856
            $finish;
857
        end
858
        if(CAUSE != 4'b0011)
859
        begin
860
            $display("FAIL. Check the results.");
861
            $finish;
862
        end
863
        if(I_OR_E != 1'b1)
864
        begin
865
            $display("FAIL. Check the results.");
866
            $finish;
867
        end
868
        if(FLUSH != 1'b1)
869
        begin
870
            $display("FAIL. Check the results.");
871
            $finish;
872
        end
873
        if(INSTRET_INC != 1'b0)
874
        begin
875
            $display("FAIL. Check the results.");
876
            $finish;
877
        end
878
        S_IRQ = 1'b0;
879
        #20;
880
        if(PC_SRC != `PC_NEXT)
881
        begin
882
            $display("FAIL. Check the results.");
883
            $finish;
884
        end
885
 
886
        T_IRQ = 1'b1;
887
        #20;
888
        if(PC_SRC != `PC_NEXT)
889
        begin
890
            $display("FAIL. Check the results.");
891
            $finish;
892
        end
893
        T_IRQ = 1'b0;
894
 
895
        E_IRQ = 1'b1;
896
        #20;
897
        if(PC_SRC != `PC_NEXT)
898
        begin
899
            $display("FAIL. Check the results.");
900
            $finish;
901
        end
902
        E_IRQ = 1'b0;
903
 
904
        MSIE = 1'b0;
905
 
906
        $display("Test OK.");
907
 
908
        /************************************************************
909
        *************************************************************
910
        ************************************************************/
911
 
912
        $display("Testing if the machine change its state only for MEIP in operating state when MIE=1 and MTIE=0, MSIE=0 and MEIE=1...");
913
 
914
        MIE = 1'b1;
915
        MEIE = 1'b1;
916
        MEIP = 1'b1;
917
        #20;
918
        if(PC_SRC != `PC_TRAP)
919
        begin
920
            $display("FAIL. Check the results.");
921
            $finish;
922
        end
923
        if(MIE_CLEAR != 1'b1)
924
        begin
925
            $display("FAIL. Check the results.");
926
            $finish;
927
        end
928
        if(SET_EPC != 1'b1)
929
        begin
930
            $display("FAIL. Check the results.");
931
            $finish;
932
        end
933
        if(SET_CAUSE != 1'b1)
934
        begin
935
            $display("FAIL. Check the results.");
936
            $finish;
937
        end
938
        if(CAUSE != 4'b1011)
939
        begin
940
            $display("FAIL. Check the results.");
941
            $finish;
942
        end
943
        if(I_OR_E != 1'b1)
944
        begin
945
            $display("FAIL. Check the results.");
946
            $finish;
947
        end
948
        if(FLUSH != 1'b1)
949
        begin
950
            $display("FAIL. Check the results.");
951
            $finish;
952
        end
953
        if(INSTRET_INC != 1'b0)
954
        begin
955
            $display("FAIL. Check the results.");
956
            $finish;
957
        end
958
        MEIP = 1'b0;
959
        #20;
960
        if(PC_SRC != `PC_NEXT)
961
        begin
962
            $display("FAIL. Check the results.");
963
            $finish;
964
        end
965
 
966
        MTIP = 1'b1;
967
        #20;
968
        if(PC_SRC != `PC_NEXT)
969
        begin
970
            $display("FAIL. Check the results.");
971
            $finish;
972
        end
973
        MTIP = 1'b0;
974
 
975
        MSIP = 1'b1;
976
        #20;
977
        if(PC_SRC != `PC_NEXT)
978
        begin
979
            $display("FAIL. Check the results.");
980
            $finish;
981
        end
982
        MSIP = 1'b0;
983
 
984
        MEIE = 1'b0;
985
 
986
        $display("Test OK.");
987
 
988
        /************************************************************
989
        *************************************************************
990
        ************************************************************/
991
 
992
        $display("Testing if the machine change its state only for MTIP in operating state when MIE=1 and MTIE=1, MSIE=0 and MEIE=0...");
993
 
994
        MIE = 1'b1;
995
        MTIE = 1'b1;
996
        MTIP = 1'b1;
997
        #20;
998
        if(PC_SRC != `PC_TRAP)
999
        begin
1000
            $display("FAIL. Check the results.");
1001
            $finish;
1002
        end
1003
        if(MIE_CLEAR != 1'b1)
1004
        begin
1005
            $display("FAIL. Check the results.");
1006
            $finish;
1007
        end
1008
        if(SET_EPC != 1'b1)
1009
        begin
1010
            $display("FAIL. Check the results.");
1011
            $finish;
1012
        end
1013
        if(SET_CAUSE != 1'b1)
1014
        begin
1015
            $display("FAIL. Check the results.");
1016
            $finish;
1017
        end
1018
        if(CAUSE != 4'b0111)
1019
        begin
1020
            $display("FAIL. Check the results.");
1021
            $finish;
1022
        end
1023
        if(I_OR_E != 1'b1)
1024
        begin
1025
            $display("FAIL. Check the results.");
1026
            $finish;
1027
        end
1028
        if(FLUSH != 1'b1)
1029
        begin
1030
            $display("FAIL. Check the results.");
1031
            $finish;
1032
        end
1033
        if(INSTRET_INC != 1'b0)
1034
        begin
1035
            $display("FAIL. Check the results.");
1036
            $finish;
1037
        end
1038
        MTIP = 1'b0;
1039
        #20;
1040
        if(PC_SRC != `PC_NEXT)
1041
        begin
1042
            $display("FAIL. Check the results.");
1043
            $finish;
1044
        end
1045
 
1046
        MEIP = 1'b1;
1047
        #20;
1048
        if(PC_SRC != `PC_NEXT)
1049
        begin
1050
            $display("FAIL. Check the results.");
1051
            $finish;
1052
        end
1053
        MEIP = 1'b0;
1054
 
1055
        MSIP = 1'b1;
1056
        #20;
1057
        if(PC_SRC != `PC_NEXT)
1058
        begin
1059
            $display("FAIL. Check the results.");
1060
            $finish;
1061
        end
1062
        MSIP = 1'b0;
1063
 
1064
        MTIE = 1'b0;
1065
 
1066
        $display("Test OK.");
1067
 
1068
        /************************************************************
1069
        *************************************************************
1070
        ************************************************************/
1071
 
1072
        $display("Testing if the machine change its state only for MSIP in operating state when MIE=1 and MTIE=0, MSIE=1 and MEIE=0...");
1073
 
1074
        MIE = 1'b1;
1075
        MSIE = 1'b1;
1076
        MSIP = 1'b1;
1077
        #20;
1078
        if(PC_SRC != `PC_TRAP)
1079
        begin
1080
            $display("FAIL. Check the results.");
1081
            $finish;
1082
        end
1083
        if(MIE_CLEAR != 1'b1)
1084
        begin
1085
            $display("FAIL. Check the results.");
1086
            $finish;
1087
        end
1088
        if(SET_EPC != 1'b1)
1089
        begin
1090
            $display("FAIL. Check the results.");
1091
            $finish;
1092
        end
1093
        if(SET_CAUSE != 1'b1)
1094
        begin
1095
            $display("FAIL. Check the results.");
1096
            $finish;
1097
        end
1098
        if(CAUSE != 4'b0011)
1099
        begin
1100
            $display("FAIL. Check the results.");
1101
            $finish;
1102
        end
1103
        if(I_OR_E != 1'b1)
1104
        begin
1105
            $display("FAIL. Check the results.");
1106
            $finish;
1107
        end
1108
        if(FLUSH != 1'b1)
1109
        begin
1110
            $display("FAIL. Check the results.");
1111
            $finish;
1112
        end
1113
        if(INSTRET_INC != 1'b0)
1114
        begin
1115
            $display("FAIL. Check the results.");
1116
            $finish;
1117
        end
1118
        MSIP = 1'b0;
1119
        #20;
1120
        if(PC_SRC != `PC_NEXT)
1121
        begin
1122
            $display("FAIL. Check the results.");
1123
            $finish;
1124
        end
1125
 
1126
        MTIP = 1'b1;
1127
        #20;
1128
        if(PC_SRC != `PC_NEXT)
1129
        begin
1130
            $display("FAIL. Check the results.");
1131
            $finish;
1132
        end
1133
        MTIP = 1'b0;
1134
 
1135
        MEIP = 1'b1;
1136
        #20;
1137
        if(PC_SRC != `PC_NEXT)
1138
        begin
1139
            $display("FAIL. Check the results.");
1140
            $finish;
1141
        end
1142
        MEIP = 1'b0;
1143
 
1144
        MSIE = 1'b0;
1145
 
1146
        $display("Test OK.");
1147
 
1148
        /************************************************************
1149
        *************************************************************
1150
        ************************************************************/
1151
 
1152
        $display("Testing transition from OPERATING to TRAP RETURN...");
1153
 
1154
        OPCODE_6_TO_2 = `OPCODE_SYSTEM;
1155
        FUNCT7 = `FUNCT7_MRET;
1156
        FUNCT3 = `FUNCT3_MRET;
1157
        RS1_ADDR = `RS1_MRET;
1158
        RS2_ADDR = `RS2_MRET;
1159
        RD_ADDR = `RD_MRET;
1160
        #20;
1161
 
1162
        if(PC_SRC != `PC_EPC)
1163
        begin
1164
            $display("FAIL. Check the results.");
1165
            $finish;
1166
        end
1167
        if(SET_CAUSE != 1'b0)
1168
        begin
1169
            $display("FAIL. Check the results.");
1170
            $finish;
1171
        end
1172
        if(SET_EPC != 1'b0)
1173
        begin
1174
            $display("FAIL. Check the results.");
1175
            $finish;
1176
        end
1177
        if(MIE_CLEAR != 1'b0)
1178
        begin
1179
            $display("FAIL. Check the results.");
1180
            $finish;
1181
        end
1182
        if(MIE_SET != 1'b1)
1183
        begin
1184
            $display("FAIL. Check the results.");
1185
            $finish;
1186
        end
1187
        if(FLUSH != 1'b1)
1188
        begin
1189
            $display("FAIL. Check the results.");
1190
            $finish;
1191
        end
1192
        if(INSTRET_INC != 1'b0)
1193
        begin
1194
            $display("FAIL. Check the results.");
1195
            $finish;
1196
        end
1197
 
1198
        $display("Test OK.");
1199
 
1200
        OPCODE_6_TO_2 = `OPCODE_OP;
1201
        FUNCT3 = `FUNCT3_ADD;
1202
        FUNCT7 = `FUNCT7_ADD;
1203
        RS1_ADDR = 5'b00000;
1204
        RS2_ADDR = 5'b00000;
1205
        RD_ADDR = 5'b00000;
1206
        #20;
1207
 
1208
        /************************************************************
1209
        *************************************************************
1210
        ************************************************************/
1211
 
1212
        $display("Testing transition from TRAP RETURN to OPERATING...");
1213
 
1214
        if(PC_SRC != `PC_NEXT)
1215
        begin
1216
            $display("FAIL. Check the results.");
1217
            $finish;
1218
        end
1219
        if(SET_CAUSE != 1'b0)
1220
        begin
1221
            $display("FAIL. Check the results.");
1222
            $finish;
1223
        end
1224
        if(SET_EPC != 1'b0)
1225
        begin
1226
            $display("FAIL. Check the results.");
1227
            $finish;
1228
        end
1229
        if(MIE_CLEAR != 1'b0)
1230
        begin
1231
            $display("FAIL. Check the results.");
1232
            $finish;
1233
        end
1234
        if(MIE_SET != 1'b0)
1235
        begin
1236
            $display("FAIL. Check the results.");
1237
            $finish;
1238
        end
1239
        if(FLUSH != 1'b0)
1240
        begin
1241
            $display("FAIL. Check the results.");
1242
            $finish;
1243
        end
1244
        if(INSTRET_INC != 1'b1)
1245
        begin
1246
            $display("FAIL. Check the results.");
1247
            $finish;
1248
        end
1249
 
1250
        $display("Test OK.");
1251
 
1252
        $display("Testing TRAP_TAKEN signal...");
1253
 
1254
        OPCODE_6_TO_2 = `OPCODE_OP;
1255
        FUNCT3 = `FUNCT3_ADD;
1256
        FUNCT7 = `FUNCT7_ADD;
1257
        RS1_ADDR = 5'b00000;
1258
        RS2_ADDR = 5'b00000;
1259
        RD_ADDR = 5'b00000;
1260
        #20;
1261
 
1262
        if(TRAP_TAKEN != 1'b0)
1263
        begin
1264
            $display("FAIL. Check the results.");
1265
            $finish;
1266
        end
1267
 
1268
        OPCODE_6_TO_2 = `OPCODE_SYSTEM;
1269
        FUNCT3 = `FUNCT3_EBREAK;
1270
        FUNCT7 = `FUNCT7_EBREAK;
1271
        RS1_ADDR = `RS1_EBREAK;
1272
        RS2_ADDR = `RS2_EBREAK;
1273
        RD_ADDR = `RD_EBREAK;
1274
        #20;
1275
 
1276
        if(TRAP_TAKEN != 1'b1)
1277
        begin
1278
            $display("FAIL. Check the results.");
1279
            $finish;
1280
        end
1281
 
1282
        OPCODE_6_TO_2 = `OPCODE_OP;
1283
        FUNCT3 = `FUNCT3_ADD;
1284
        FUNCT7 = `FUNCT7_ADD;
1285
        RS1_ADDR = 5'b00000;
1286
        RS2_ADDR = 5'b00000;
1287
        RD_ADDR = 5'b00000;
1288
        #20;
1289
 
1290
        if(TRAP_TAKEN != 1'b0)
1291
        begin
1292
            $display("FAIL. Check the results.");
1293
            $finish;
1294
        end
1295
 
1296
        OPCODE_6_TO_2 = `OPCODE_SYSTEM;
1297
        FUNCT3 = `FUNCT3_ECALL;
1298
        FUNCT7 = `FUNCT7_ECALL;
1299
        RS1_ADDR = `RS1_ECALL;
1300
        RS2_ADDR = `RS2_ECALL;
1301
        RD_ADDR = `RD_ECALL;
1302
        #20;
1303
 
1304
        if(TRAP_TAKEN != 1'b1)
1305
        begin
1306
            $display("FAIL. Check the results.");
1307
            $finish;
1308
        end
1309
 
1310
        OPCODE_6_TO_2 = `OPCODE_OP;
1311
        FUNCT3 = `FUNCT3_ADD;
1312
        FUNCT7 = `FUNCT7_ADD;
1313
        RS1_ADDR = 5'b00000;
1314
        RS2_ADDR = 5'b00000;
1315
        RD_ADDR = 5'b00000;
1316
        #20;
1317
 
1318
        if(TRAP_TAKEN != 1'b0)
1319
        begin
1320
            $display("FAIL. Check the results.");
1321
            $finish;
1322
        end
1323
 
1324
        ILLEGAL_INSTR = 1'b1;
1325
        #20;
1326
 
1327
        if(TRAP_TAKEN != 1'b1)
1328
        begin
1329
            $display("FAIL. Check the results.");
1330
            $finish;
1331
        end
1332
        ILLEGAL_INSTR = 1'b0;
1333
        #20;
1334
 
1335
        if(TRAP_TAKEN != 1'b0)
1336
        begin
1337
            $display("FAIL. Check the results.");
1338
            $finish;
1339
        end
1340
 
1341
        MISALIGNED_INSTR = 1'b1;
1342
        #20;
1343
 
1344
        if(TRAP_TAKEN != 1'b1)
1345
        begin
1346
            $display("FAIL. Check the results.");
1347
            $finish;
1348
        end
1349
        MISALIGNED_INSTR = 1'b0;
1350
        #20;
1351
 
1352
        if(TRAP_TAKEN != 1'b0)
1353
        begin
1354
            $display("FAIL. Check the results.");
1355
            $finish;
1356
        end
1357
 
1358
        MISALIGNED_LOAD = 1'b1;
1359
        #20;
1360
 
1361
        if(TRAP_TAKEN != 1'b1)
1362
        begin
1363
            $display("FAIL. Check the results.");
1364
            $finish;
1365
        end
1366
        MISALIGNED_LOAD = 1'b0;
1367
        #20;
1368
 
1369
        if(TRAP_TAKEN != 1'b0)
1370
        begin
1371
            $display("FAIL. Check the results.");
1372
            $finish;
1373
        end
1374
 
1375
        MISALIGNED_STORE = 1'b1;
1376
        #20;
1377
 
1378
        if(TRAP_TAKEN != 1'b1)
1379
        begin
1380
            $display("FAIL. Check the results.");
1381
            $finish;
1382
        end
1383
        MISALIGNED_STORE = 1'b0;
1384
        #20;
1385
 
1386
        if(TRAP_TAKEN != 1'b0)
1387
        begin
1388
            $display("FAIL. Check the results.");
1389
            $finish;
1390
        end
1391
 
1392
        MIE = 1'b1;
1393
        MEIE = 1'b1;
1394
        MTIE = 1'b1;
1395
        MSIE = 1'b1;
1396
 
1397
        E_IRQ = 1'b1;
1398
        #20;
1399
 
1400
        if(TRAP_TAKEN != 1'b1)
1401
        begin
1402
            $display("FAIL. Check the results.");
1403
            $finish;
1404
        end
1405
        E_IRQ = 1'b0;
1406
        #20;
1407
 
1408
        if(TRAP_TAKEN != 1'b0)
1409
        begin
1410
            $display("FAIL. Check the results.");
1411
            $finish;
1412
        end
1413
 
1414
        T_IRQ = 1'b1;
1415
        #20;
1416
 
1417
        if(TRAP_TAKEN != 1'b1)
1418
        begin
1419
            $display("FAIL. Check the results.");
1420
            $finish;
1421
        end
1422
        T_IRQ = 1'b0;
1423
        #20;
1424
 
1425
        if(TRAP_TAKEN != 1'b0)
1426
        begin
1427
            $display("FAIL. Check the results.");
1428
            $finish;
1429
        end
1430
 
1431
        S_IRQ = 1'b1;
1432
        #20;
1433
 
1434
        if(TRAP_TAKEN != 1'b1)
1435
        begin
1436
            $display("FAIL. Check the results.");
1437
            $finish;
1438
        end
1439
        S_IRQ = 1'b0;
1440
        #20;
1441
 
1442
        if(TRAP_TAKEN != 1'b0)
1443
        begin
1444
            $display("FAIL. Check the results.");
1445
            $finish;
1446
        end
1447
 
1448
        MEIP = 1'b1;
1449
        #20;
1450
 
1451
        if(TRAP_TAKEN != 1'b1)
1452
        begin
1453
            $display("FAIL. Check the results.");
1454
            $finish;
1455
        end
1456
        MEIP = 1'b0;
1457
        #20;
1458
 
1459
        if(TRAP_TAKEN != 1'b0)
1460
        begin
1461
            $display("FAIL. Check the results.");
1462
            $finish;
1463
        end
1464
 
1465
        MTIP = 1'b1;
1466
        #20;
1467
 
1468
        if(TRAP_TAKEN != 1'b1)
1469
        begin
1470
            $display("FAIL. Check the results.");
1471
            $finish;
1472
        end
1473
        MTIP = 1'b0;
1474
        #20;
1475
 
1476
        if(TRAP_TAKEN != 1'b0)
1477
        begin
1478
            $display("FAIL. Check the results.");
1479
            $finish;
1480
        end
1481
 
1482
        MSIP = 1'b1;
1483
        #20;
1484
 
1485
        if(TRAP_TAKEN != 1'b1)
1486
        begin
1487
            $display("FAIL. Check the results.");
1488
            $finish;
1489
        end
1490
        MSIP = 1'b0;
1491
        #20;
1492
 
1493
        if(TRAP_TAKEN != 1'b0)
1494
        begin
1495
            $display("FAIL. Check the results.");
1496
            $finish;
1497
        end
1498
 
1499
        $display("Machine Mode Control module successfully tested.");
1500
 
1501
    end
1502
 
1503
endmodule
1504
 

powered by: WebSVN 2.1.0

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