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

Subversion Repositories steelcore

[/] [rtl/] [bench/] [tb_csr_file.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: 30.04.2020 21:30:47
5
// Module Name: tb_csr_file
6
// Project Name: Steel Core
7
// Description: CSR File testbench
8
// 
9
// Dependencies: globals.vh
10
//               csr_file.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_csr_file();
46
 
47
    reg CLK;
48
    reg RESET;
49
 
50
    reg WR_EN;
51
    reg [11:0] CSR_ADDR;
52
    reg [2:0] CSR_OP;
53
    reg [4:0] CSR_UIMM;
54
    reg [31:0] CSR_DATA_IN;
55
    wire [31:0] CSR_DATA_OUT;
56
 
57
    reg [31:0] PC;
58
 
59
    reg E_IRQ;
60
    reg T_IRQ;
61
    reg S_IRQ;
62
 
63
    reg I_OR_E;
64
    reg SET_CAUSE;
65
    reg [3:0] CAUSE_IN;
66
    reg SET_EPC;
67
    reg INSTRET_INC;
68
    reg MIE_CLEAR;
69
    reg MIE_SET;
70
    wire MIE;
71
    wire MEIE_OUT;
72
    wire MTIE_OUT;
73
    wire MSIE_OUT;
74
    wire MEIP_OUT;
75
    wire MTIP_OUT;
76
    wire MSIP_OUT;
77
 
78
    reg [63:0] REAL_TIME;
79
 
80
    wire [31:0] EPC_OUT;
81
    wire [31:0] TRAP_ADDRESS;
82
 
83
    csr_file dut(
84
 
85
        .CLK(CLK),
86
        .RESET(RESET),
87
 
88
        .WR_EN(WR_EN),
89
        .CSR_ADDR(CSR_ADDR),
90
        .CSR_OP(CSR_OP),
91
        .CSR_UIMM(CSR_UIMM),
92
        .CSR_DATA_IN(CSR_DATA_IN),
93
        .CSR_DATA_OUT(CSR_DATA_OUT),
94
 
95
        .PC(PC),
96
 
97
        .E_IRQ(E_IRQ),
98
        .T_IRQ(T_IRQ),
99
        .S_IRQ(S_IRQ),
100
 
101
        .I_OR_E(I_OR_E),
102
        .SET_CAUSE(SET_CAUSE),
103
        .CAUSE_IN(CAUSE_IN),
104
        .SET_EPC(SET_EPC),
105
        .INSTRET_INC(INSTRET_INC),
106
        .MIE_CLEAR(MIE_CLEAR),
107
        .MIE_SET(MIE_SET),
108
        .MIE(MIE),
109
        .MEIE_OUT(MEIE_OUT),
110
        .MTIE_OUT(MTIE_OUT),
111
        .MSIE_OUT(MSIE_OUT),
112
        .MEIP_OUT(MEIP_OUT),
113
        .MTIP_OUT(MTIP_OUT),
114
        .MSIP_OUT(MSIP_OUT),
115
 
116
        .REAL_TIME(REAL_TIME),
117
 
118
        .EPC_OUT(EPC_OUT),
119
        .TRAP_ADDRESS(TRAP_ADDRESS)
120
 
121
    );
122
 
123
    reg [31:0] base_offset;
124
 
125
    always
126
    begin
127
        #10 CLK = !CLK;
128
    end
129
 
130
    initial
131
    begin
132
 
133
        $display("Testing CSR Register File...");
134
 
135
        CLK = 1'b0;
136
        RESET = 1'b0;
137
 
138
        WR_EN = 1'b0;
139
        CSR_ADDR = 5'b00000;
140
        CSR_OP = `CSR_NOP;
141
        CSR_UIMM = 5'b00000;
142
        CSR_DATA_IN = 32'h00000000;
143
        PC = 32'h00000000;
144
        E_IRQ = 1'b0;
145
        T_IRQ = 1'b0;
146
        S_IRQ = 1'b0;
147
        I_OR_E = 1'b0;
148
        SET_CAUSE = 1'b0;
149
        CAUSE_IN = 4'b0000;
150
        SET_EPC = 1'b0;
151
        INSTRET_INC = 1'b0;
152
        MIE_CLEAR = 1'b0;
153
        MIE_SET = 1'b0;
154
        REAL_TIME = 64'h0000000000000000;
155
 
156
        //----------------------------------------------------------------------
157
        // RESET VALUES TEST
158
        //----------------------------------------------------------------------
159
 
160
        $display("Testing values after reset...");
161
 
162
        #5;
163
        RESET = 1'b1;
164
        #15;
165
        RESET = 1'b0;
166
        CSR_ADDR = `CYCLE;
167
        #5;
168
        if(CSR_DATA_OUT != `MCYCLE_RESET)
169
        begin
170
            $display("FAIL. Check the results.");
171
            $finish;
172
        end
173
        $display("CYCLE reset value OK.");
174
 
175
        #20;
176
        RESET = 1'b1;
177
        #15;
178
        RESET = 1'b0;
179
        CSR_ADDR = `CYCLEH;
180
        #5;
181
        if(CSR_DATA_OUT != `MCYCLEH_RESET)
182
        begin
183
            $display("FAIL. Check the results.");
184
            $finish;
185
        end
186
        $display("CYCLEH reset value OK.");
187
 
188
        #20;
189
        RESET = 1'b1;
190
        #15;
191
        RESET = 1'b0;
192
        CSR_ADDR = `TIME;
193
        #5;
194
        if(CSR_DATA_OUT != `TIME_RESET)
195
        begin
196
            $display("FAIL. Check the results.");
197
            $finish;
198
        end
199
        $display("TIME reset value OK.");
200
 
201
        #20;
202
        RESET = 1'b1;
203
        #15;
204
        RESET = 1'b0;
205
        CSR_ADDR = `TIMEH;
206
        #5;
207
        if(CSR_DATA_OUT != `TIMEH_RESET)
208
        begin
209
            $display("FAIL. Check the results.");
210
            $finish;
211
        end
212
        $display("TIMEH reset value OK.");
213
 
214
        #20;
215
        RESET = 1'b1;
216
        #15;
217
        RESET = 1'b0;
218
        CSR_ADDR = `INSTRET;
219
        #5;
220
        if(CSR_DATA_OUT != `MINSTRET_RESET)
221
        begin
222
            $display("FAIL. Check the results.");
223
            $finish;
224
        end
225
        $display("INSTRET reset value OK.");
226
 
227
        #20;
228
        RESET = 1'b1;
229
        #15;
230
        RESET = 1'b0;
231
        CSR_ADDR = `INSTRETH;
232
        #5;
233
        if(CSR_DATA_OUT != `MINSTRETH_RESET)
234
        begin
235
            $display("FAIL. Check the results.");
236
            $finish;
237
        end
238
        $display("INSTRETH reset value OK.");
239
 
240
        #20;
241
        RESET = 1'b1;
242
        #15;
243
        RESET = 1'b0;
244
        CSR_ADDR = `MSTATUS;
245
        #5;
246
        if(CSR_DATA_OUT != {19'b0, 2'b11, 3'b0, 1'b1, 3'b0 , 1'b0, 3'b0})
247
        begin
248
            $display("FAIL. Check the results.");
249
            $finish;
250
        end
251
        $display("MSTATUS reset value OK.");
252
 
253
        #20;
254
        RESET = 1'b1;
255
        #15;
256
        RESET = 1'b0;
257
        CSR_ADDR = `MISA;
258
        #5;
259
        if(CSR_DATA_OUT != 32'b01000000000000000000000100000000)
260
        begin
261
            $display("FAIL. Check the results.");
262
            $finish;
263
        end
264
        $display("MISA reset value OK.");
265
 
266
        #20;
267
        RESET = 1'b1;
268
        #15;
269
        RESET = 1'b0;
270
        CSR_ADDR = `MIE;
271
        #5;
272
        if(CSR_DATA_OUT != 32'h00000000)
273
        begin
274
            $display("FAIL. Check the results.");
275
            $finish;
276
        end
277
        $display("MIE reset value OK.");
278
 
279
        #20;
280
        RESET = 1'b1;
281
        #15;
282
        RESET = 1'b0;
283
        CSR_ADDR = `MTVEC;
284
        #5;
285
        if(CSR_DATA_OUT != {`MTVEC_BASE_RESET, `MTVEC_MODE_RESET})
286
        begin
287
            $display("FAIL. Check the results.");
288
            $finish;
289
        end
290
        $display("MTVEC reset value OK.");
291
 
292
        #20;
293
        RESET = 1'b1;
294
        #15;
295
        RESET = 1'b0;
296
        CSR_ADDR = `MSCRATCH;
297
        #5;
298
        if(CSR_DATA_OUT != `MSCRATCH_RESET)
299
        begin
300
            $display("FAIL. Check the results.");
301
            $finish;
302
        end
303
        $display("MSCRATCH reset value OK.");
304
 
305
        #20;
306
        RESET = 1'b1;
307
        #15;
308
        RESET = 1'b0;
309
        CSR_ADDR = `MEPC;
310
        #5;
311
        if(CSR_DATA_OUT != `MEPC_RESET)
312
        begin
313
            $display("FAIL. Check the results.");
314
            $finish;
315
        end
316
        $display("MEPC reset value OK.");
317
 
318
        #20;
319
        RESET = 1'b1;
320
        #15;
321
        RESET = 1'b0;
322
        CSR_ADDR = `MTVAL;
323
        #5;
324
        if(CSR_DATA_OUT != 32'b0)
325
        begin
326
            $display("FAIL. Check the results.");
327
            $finish;
328
        end
329
        $display("MTVAL reset value OK.");
330
 
331
        #20;
332
        RESET = 1'b1;
333
        #15;
334
        RESET = 1'b0;
335
        CSR_ADDR = `MIP;
336
        #5;
337
        if(CSR_DATA_OUT != 32'b0)
338
        begin
339
            $display("FAIL. Check the results.");
340
            $finish;
341
        end
342
        $display("MIP reset value OK.");
343
 
344
        #20;
345
        RESET = 1'b1;
346
        #15;
347
        RESET = 1'b0;
348
        CSR_ADDR = `MCYCLE;
349
        #5;
350
        if(CSR_DATA_OUT != `MCYCLE_RESET)
351
        begin
352
            $display("FAIL. Check the results.");
353
            $finish;
354
        end
355
        $display("CYCLE reset value OK.");
356
 
357
        #20;
358
        RESET = 1'b1;
359
        #15;
360
        RESET = 1'b0;
361
        CSR_ADDR = `MCYCLEH;
362
        #5;
363
        if(CSR_DATA_OUT != `MCYCLEH_RESET)
364
        begin
365
            $display("FAIL. Check the results.");
366
            $finish;
367
        end
368
        $display("CYCLEH reset value OK.");
369
 
370
        #20;
371
        RESET = 1'b1;
372
        #15;
373
        RESET = 1'b0;
374
        CSR_ADDR = `MINSTRET;
375
        #5;
376
        if(CSR_DATA_OUT != `MINSTRET_RESET)
377
        begin
378
            $display("FAIL. Check the results.");
379
            $finish;
380
        end
381
        $display("INSTRET reset value OK.");
382
 
383
        #20;
384
        RESET = 1'b1;
385
        #15;
386
        RESET = 1'b0;
387
        CSR_ADDR = `MINSTRETH;
388
        #5;
389
        if(CSR_DATA_OUT != `MINSTRETH_RESET)
390
        begin
391
            $display("FAIL. Check the results.");
392
            $finish;
393
        end
394
        $display("INSTRETH reset value OK.");
395
 
396
        #20;
397
        RESET = 1'b1;
398
        #15;
399
        RESET = 1'b0;
400
        CSR_ADDR = `MCOUNTINHIBIT;
401
        #5;
402
        if(CSR_DATA_OUT != {29'b0, `MCOUNTINHIBIT_IR_RESET, 1'b0, `MCOUNTINHIBIT_CY_RESET})
403
        begin
404
            $display("FAIL. Check the results.");
405
            $finish;
406
        end
407
        $display("MCOUNTINHIBIT reset value OK.");
408
 
409
        $display("Reset values successfully tested.");
410
 
411
        #35;
412
 
413
        //----------------------------------------------------------------------
414
        // WRITE OPERATION TEST
415
        //----------------------------------------------------------------------
416
 
417
        $display("Testing write operation for each CSR...");
418
 
419
        WR_EN = 1'b1;
420
        CSR_OP = {1'b0, `CSR_RW};
421
        CSR_UIMM = 5'b11111;
422
        CSR_DATA_IN = 32'hFFFFFFFF;
423
 
424
        CSR_ADDR = `CYCLE;
425
        #20;
426
        if(CSR_DATA_OUT == 32'hFFFFFFFF)
427
        begin
428
            $display("FAIL. Check the results.");
429
            $finish;
430
        end
431
        $display("Attempt to write the read-only register CYCLE unsuccessful. Result OK.");
432
 
433
        CSR_ADDR = `CYCLEH;
434
        #20;
435
        if(CSR_DATA_OUT == 32'hFFFFFFFF)
436
        begin
437
            $display("FAIL. Check the results.");
438
            $finish;
439
        end
440
        $display("Attempt to write the read-only register CYCLEH unsuccessful. Result OK.");
441
 
442
        CSR_ADDR = `TIME;
443
        #20;
444
        if(CSR_DATA_OUT == 32'hFFFFFFFF)
445
        begin
446
            $display("FAIL. Check the results.");
447
            $finish;
448
        end
449
        $display("Attempt to write the read-only register TIME unsuccessful. Result OK.");
450
 
451
        CSR_ADDR = `TIMEH;
452
        #20;
453
        if(CSR_DATA_OUT == 32'hFFFFFFFF)
454
        begin
455
            $display("FAIL. Check the results.");
456
            $finish;
457
        end
458
        $display("Attempt to write the read-only register TIMEH unsuccessful. Result OK.");
459
 
460
        CSR_ADDR = `INSTRET;
461
        #20;
462
        if(CSR_DATA_OUT == 32'hFFFFFFFF)
463
        begin
464
            $display("FAIL. Check the results.");
465
            $finish;
466
        end
467
        $display("Attempt to write the read-only register INSTRET unsuccessful. Result OK.");
468
 
469
        CSR_ADDR = `INSTRETH;
470
        #20;
471
        if(CSR_DATA_OUT == 32'hFFFFFFFF)
472
        begin
473
            $display("FAIL. Check the results.");
474
            $finish;
475
        end
476
        $display("Attempt to write the read-only register INSTRETH unsuccessful. Result OK.");
477
 
478
        CSR_ADDR = `MSTATUS;
479
        #20;
480
        if(CSR_DATA_OUT != {19'b0, 2'b11, 3'b0, 1'b1, 3'b0 , 1'b1, 3'b0})
481
        begin
482
            $display("FAIL. Check the results.");
483
            $finish;
484
        end
485
        $display("Attempt to write the read-write register MSTATUS successful. Result OK.");
486
 
487
        CSR_ADDR = `MISA;
488
        #20;
489
        if(CSR_DATA_OUT != {2'b01, 4'b0, 26'b00000000000000000100000000})
490
        begin
491
            $display("FAIL. Check the results.");
492
            $finish;
493
        end
494
        $display("Attempt to write the read-only register MISA unsuccessful. Result OK.");
495
 
496
        CSR_ADDR = `MIE;
497
        #20;
498
        if(CSR_DATA_OUT != {20'b0, 1'b1, 3'b0, 1'b1, 3'b0, 1'b1, 3'b0})
499
        begin
500
            $display("FAIL. Check the results.");
501
            $finish;
502
        end
503
        $display("Attempt to write the read-write register MIE successful. Result OK.");
504
 
505
        CSR_ADDR = `MTVEC;
506
        #20;
507
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
508
        begin
509
            $display("FAIL. Check the results.");
510
            $finish;
511
        end
512
        $display("Attempt to write the read-write register MTVEC successful. Result OK.");
513
 
514
        CSR_ADDR = `MSCRATCH;
515
        #20;
516
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
517
        begin
518
            $display("FAIL. Check the results.");
519
            $finish;
520
        end
521
        $display("Attempt to write the read-write register MSCRATCH successful. Result OK.");
522
 
523
        CSR_ADDR = `MEPC;
524
        #20;
525
        if(CSR_DATA_OUT != 32'hFFFFFFFC)
526
        begin
527
            $display("FAIL. Check the results.");
528
            $finish;
529
        end
530
        $display("Attempt to write the read-write register MEPC successful. Result OK.");
531
 
532
        CSR_ADDR = `MCAUSE;
533
        #20;
534
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
535
        begin
536
            $display("FAIL. Check the results.");
537
            $finish;
538
        end
539
        $display("Attempt to write the read-only register MCAUSE unsuccessful. Result OK.");
540
 
541
        CSR_ADDR = `MTVAL;
542
        #20;
543
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
544
        begin
545
            $display("FAIL. Check the results.");
546
            $finish;
547
        end
548
        $display("Attempt to write the read-only register MTVAL unsuccessful. Result OK.");
549
 
550
        CSR_ADDR = `MIP;
551
        #20;
552
        if(CSR_DATA_OUT != 32'h00000000)
553
        begin
554
            $display("FAIL. Check the results.");
555
            $finish;
556
        end
557
        $display("Attempt to write the read-only register MIP unsuccessful. Result OK.");
558
 
559
        CSR_ADDR = `MCYCLE;
560
        #20;
561
        if(CSR_DATA_OUT != 32'h00000000)
562
        begin
563
            $display("FAIL. Check the results.");
564
            $finish;
565
        end
566
        $display("Attempt to write the read-write register MCYCLE successful. Result OK.");
567
 
568
        CSR_ADDR = `MCYCLEH;
569
        #20;
570
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
571
        begin
572
            $display("FAIL. Check the results.");
573
            $finish;
574
        end
575
        $display("Attempt to write the read-write register MCYCLEH successful. Result OK.");
576
 
577
        CSR_ADDR = `MINSTRET;
578
        #20;
579
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
580
        begin
581
            $display("FAIL. Check the results.");
582
            $finish;
583
        end
584
        $display("Attempt to write the read-write register MINSTRET successful. Result OK.");
585
 
586
        CSR_ADDR = `MINSTRETH;
587
        #20;
588
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
589
        begin
590
            $display("FAIL. Check the results.");
591
            $finish;
592
        end
593
        $display("Attempt to write the read-write register MINSTRETH successful. Result OK.");
594
 
595
        CSR_ADDR = `MCOUNTINHIBIT;
596
        #20;
597
        if(CSR_DATA_OUT != {29'b0, 1'b1, 1'b0, 1'b1})
598
        begin
599
            $display("FAIL. Check the results.");
600
            $finish;
601
        end
602
        $display("Attempt to write the read-write register MCOUNTINHIBIT successful. Result OK.");
603
 
604
        $display("Write operation successfully tested.");
605
 
606
        //----------------------------------------------------------------------
607
        // SET OPERATION TEST
608
        //----------------------------------------------------------------------
609
 
610
        #5;
611
        RESET = 1'b1;
612
        #15;
613
        RESET = 1'b0;
614
 
615
        $display("Testing set operation for each CSR...");
616
 
617
        WR_EN = 1'b1;
618
        CSR_OP = {1'b0, `CSR_RS};
619
        CSR_UIMM = 5'b11111;
620
        CSR_DATA_IN = 32'hFFFFFFFF;
621
 
622
        CSR_ADDR = `CYCLE;
623
        #20;
624
        if(CSR_DATA_OUT == 32'hFFFFFFFF)
625
        begin
626
            $display("FAIL. Check the results.");
627
            $finish;
628
        end
629
        $display("Attempt to set the read-only register CYCLE unsuccessful. Result OK.");
630
 
631
        CSR_ADDR = `CYCLEH;
632
        #20;
633
        if(CSR_DATA_OUT == 32'hFFFFFFFF)
634
        begin
635
            $display("FAIL. Check the results.");
636
            $finish;
637
        end
638
        $display("Attempt to set the read-only register CYCLEH unsuccessful. Result OK.");
639
 
640
        CSR_ADDR = `TIME;
641
        #20;
642
        if(CSR_DATA_OUT == 32'hFFFFFFFF)
643
        begin
644
            $display("FAIL. Check the results.");
645
            $finish;
646
        end
647
        $display("Attempt to set the read-only register TIME unsuccessful. Result OK.");
648
 
649
        CSR_ADDR = `TIMEH;
650
        #20;
651
        if(CSR_DATA_OUT == 32'hFFFFFFFF)
652
        begin
653
            $display("FAIL. Check the results.");
654
            $finish;
655
        end
656
        $display("Attempt to set the read-only register TIMEH unsuccessful. Result OK.");
657
 
658
        CSR_ADDR = `INSTRET;
659
        #20;
660
        if(CSR_DATA_OUT == 32'hFFFFFFFF)
661
        begin
662
            $display("FAIL. Check the results.");
663
            $finish;
664
        end
665
        $display("Attempt to set the read-only register INSTRET unsuccessful. Result OK.");
666
 
667
        CSR_ADDR = `INSTRETH;
668
        #20;
669
        if(CSR_DATA_OUT == 32'hFFFFFFFF)
670
        begin
671
            $display("FAIL. Check the results.");
672
            $finish;
673
        end
674
        $display("Attempt to set the read-only register INSTRETH unsuccessful. Result OK.");
675
 
676
        CSR_ADDR = `MSTATUS;
677
        #20;
678
        if(CSR_DATA_OUT != {19'b0, 2'b11, 3'b0, 1'b1, 3'b0 , 1'b1, 3'b0})
679
        begin
680
            $display("FAIL. Check the results.");
681
            $finish;
682
        end
683
        $display("Attempt to set the read-write register MSTATUS successful. Result OK.");
684
 
685
        CSR_ADDR = `MISA;
686
        #20;
687
        if(CSR_DATA_OUT != {2'b01, 4'b0, 26'b00000000000000000100000000})
688
        begin
689
            $display("FAIL. Check the results.");
690
            $finish;
691
        end
692
        $display("Attempt to set the read-only register MISA unsuccessful. Result OK.");
693
 
694
        CSR_ADDR = `MIE;
695
        #20;
696
        if(CSR_DATA_OUT != {20'b0, 1'b1, 3'b0, 1'b1, 3'b0, 1'b1, 3'b0})
697
        begin
698
            $display("FAIL. Check the results.");
699
            $finish;
700
        end
701
        $display("Attempt to set the read-write register MIE successful. Result OK.");
702
 
703
        CSR_ADDR = `MTVEC;
704
        #20;
705
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
706
        begin
707
            $display("FAIL. Check the results.");
708
            $finish;
709
        end
710
        $display("Attempt to set the read-write register MTVEC successful. Result OK.");
711
 
712
        CSR_ADDR = `MSCRATCH;
713
        #20;
714
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
715
        begin
716
            $display("FAIL. Check the results.");
717
            $finish;
718
        end
719
        $display("Attempt to set the read-write register MSCRATCH successful. Result OK.");
720
 
721
        CSR_ADDR = `MEPC;
722
        #20;
723
        if(CSR_DATA_OUT != 32'hFFFFFFFC)
724
        begin
725
            $display("FAIL. Check the results.");
726
            $finish;
727
        end
728
        $display("Attempt to set the read-write register MEPC successful. Result OK.");
729
 
730
        CSR_ADDR = `MCAUSE;
731
        #20;
732
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
733
        begin
734
            $display("FAIL. Check the results.");
735
            $finish;
736
        end
737
        $display("Attempt to set the read-only register MCAUSE unsuccessful. Result OK.");
738
 
739
        CSR_ADDR = `MTVAL;
740
        #20;
741
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
742
        begin
743
            $display("FAIL. Check the results.");
744
            $finish;
745
        end
746
        $display("Attempt to set the read-only register MTVAL unsuccessful. Result OK.");
747
 
748
        CSR_ADDR = `MIP;
749
        #20;
750
        if(CSR_DATA_OUT != 32'h00000000)
751
        begin
752
            $display("FAIL. Check the results.");
753
            $finish;
754
        end
755
        $display("Attempt to set the read-only register MIP unsuccessful. Result OK.");
756
 
757
        CSR_ADDR = `MCYCLE;
758
        #20;
759
        if(CSR_DATA_OUT != 32'h00000000)
760
        begin
761
            $display("FAIL. Check the results.");
762
            $finish;
763
        end
764
        $display("Attempt to set the read-write register MCYCLE successful. Result OK.");
765
 
766
        CSR_ADDR = `MCYCLEH;
767
        #20;
768
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
769
        begin
770
            $display("FAIL. Check the results.");
771
            $finish;
772
        end
773
        $display("Attempt to set the read-write register MCYCLEH successful. Result OK.");
774
 
775
        CSR_ADDR = `MINSTRET;
776
        #20;
777
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
778
        begin
779
            $display("FAIL. Check the results.");
780
            $finish;
781
        end
782
        $display("Attempt to set the read-write register MINSTRET successful. Result OK.");
783
 
784
        CSR_ADDR = `MINSTRETH;
785
        #20;
786
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
787
        begin
788
            $display("FAIL. Check the results.");
789
            $finish;
790
        end
791
        $display("Attempt to set the read-write register MINSTRETH successful. Result OK.");
792
 
793
        CSR_ADDR = `MCOUNTINHIBIT;
794
        #20;
795
        if(CSR_DATA_OUT != {29'b0, 1'b1, 1'b0, 1'b1})
796
        begin
797
            $display("FAIL. Check the results.");
798
            $finish;
799
        end
800
        $display("Attempt to set the read-write register MCOUNTINHIBIT successful. Result OK.");
801
 
802
        $display("Set operation successfully tested.");
803
 
804
        //----------------------------------------------------------------------
805
        // CLEAR OPERATION TEST
806
        //----------------------------------------------------------------------
807
 
808
        $display("Testing clear operation for each CSR...");
809
 
810
        WR_EN = 1'b1;
811
        CSR_OP = {1'b0, `CSR_RC};
812
        CSR_UIMM = 5'b11111;
813
        CSR_DATA_IN = 32'hFFFFFFFF;
814
 
815
        CSR_ADDR = `CYCLE;
816
        #20;
817
        if(CSR_DATA_OUT == 32'h00000000)
818
        begin
819
            $display("FAIL. Check the results.");
820
            $finish;
821
        end
822
        $display("Attempt to clear the read-only register CYCLE unsuccessful. Result OK.");
823
 
824
        CSR_ADDR = `CYCLEH;
825
        #20;
826
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
827
        begin
828
            $display("FAIL. Check the results.");
829
            $finish;
830
        end
831
        $display("Attempt to clear the read-only register CYCLEH unsuccessful. Result OK.");
832
 
833
        CSR_ADDR = `TIME;
834
        #20;
835
        if(CSR_DATA_OUT != 32'h00000000)
836
        begin
837
            $display("FAIL. Check the results.");
838
            $finish;
839
        end
840
        $display("Attempt to clear the read-only register TIME unsuccessful. Result OK.");
841
 
842
        CSR_ADDR = `TIMEH;
843
        #20;
844
        if(CSR_DATA_OUT != 32'h00000000)
845
        begin
846
            $display("FAIL. Check the results.");
847
            $finish;
848
        end
849
        $display("Attempt to clear the read-only register TIMEH unsuccessful. Result OK.");
850
 
851
        CSR_ADDR = `INSTRET;
852
        #20;
853
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
854
        begin
855
            $display("FAIL. Check the results.");
856
            $finish;
857
        end
858
        $display("Attempt to clear the read-only register INSTRET unsuccessful. Result OK.");
859
 
860
        CSR_ADDR = `INSTRETH;
861
        #20;
862
        if(CSR_DATA_OUT != 32'hFFFFFFFF)
863
        begin
864
            $display("FAIL. Check the results.");
865
            $finish;
866
        end
867
        $display("Attempt to clear the read-only register INSTRETH unsuccessful. Result OK.");
868
 
869
        CSR_ADDR = `MSTATUS;
870
        #20;
871
        if(CSR_DATA_OUT != {19'b0, 2'b11, 3'b0, 1'b0, 3'b0 , 1'b0, 3'b0})
872
        begin
873
            $display("FAIL. Check the results.");
874
            $finish;
875
        end
876
        $display("Attempt to clear the read-write register MSTATUS successful. Result OK.");
877
 
878
        CSR_ADDR = `MISA;
879
        #20;
880
        if(CSR_DATA_OUT != {2'b01, 4'b0, 26'b00000000000000000100000000})
881
        begin
882
            $display("FAIL. Check the results.");
883
            $finish;
884
        end
885
        $display("Attempt to clear the read-only register MISA unsuccessful. Result OK.");
886
 
887
        CSR_ADDR = `MIE;
888
        #20;
889
        if(CSR_DATA_OUT != {20'b0, 1'b0, 3'b0, 1'b0, 3'b0, 1'b0, 3'b0})
890
        begin
891
            $display("FAIL. Check the results.");
892
            $finish;
893
        end
894
        $display("Attempt to clear the read-write register MIE successful. Result OK.");
895
 
896
        CSR_ADDR = `MTVEC;
897
        #20;
898
        if(CSR_DATA_OUT != 32'h00000000)
899
        begin
900
            $display("FAIL. Check the results.");
901
            $finish;
902
        end
903
        $display("Attempt to clear the read-write register MTVEC successful. Result OK.");
904
 
905
        CSR_ADDR = `MSCRATCH;
906
        #20;
907
        if(CSR_DATA_OUT != 32'h00000000)
908
        begin
909
            $display("FAIL. Check the results.");
910
            $finish;
911
        end
912
        $display("Attempt to clear the read-write register MSCRATCH successful. Result OK.");
913
 
914
        CSR_ADDR = `MEPC;
915
        #20;
916
        if(CSR_DATA_OUT != 32'h00000000)
917
        begin
918
            $display("FAIL. Check the results.");
919
            $finish;
920
        end
921
        $display("Attempt to clear the read-write register MEPC successful. Result OK.");
922
 
923
        CSR_ADDR = `MCAUSE;
924
        #20;
925
        if(CSR_DATA_OUT != 32'h00000000)
926
        begin
927
            $display("FAIL. Check the results.");
928
            $finish;
929
        end
930
        $display("Attempt to clear the read-only register MCAUSE unsuccessful. Result OK.");
931
 
932
        CSR_ADDR = `MTVAL;
933
        #20;
934
        if(CSR_DATA_OUT != 32'h00000000)
935
        begin
936
            $display("FAIL. Check the results.");
937
            $finish;
938
        end
939
        $display("Attempt to clear the read-only register MTVAL unsuccessful. Result OK.");
940
 
941
        CSR_ADDR = `MIP;
942
        #20;
943
        if(CSR_DATA_OUT != 32'h00000000)
944
        begin
945
            $display("FAIL. Check the results.");
946
            $finish;
947
        end
948
        $display("Attempt to clear the read-only register MIP unsuccessful. Result OK.");
949
 
950
        CSR_ADDR = `MCYCLE;
951
        #20;
952
        if(CSR_DATA_OUT != 32'h00000000)
953
        begin
954
            $display("FAIL. Check the results.");
955
            $finish;
956
        end
957
        $display("Attempt to clear the read-write register MCYCLE successful. Result OK.");
958
 
959
        CSR_ADDR = `MCYCLEH;
960
        #20;
961
        if(CSR_DATA_OUT != 32'h00000000)
962
        begin
963
            $display("FAIL. Check the results.");
964
            $finish;
965
        end
966
        $display("Attempt to clear the read-write register MCYCLEH successful. Result OK.");
967
 
968
        CSR_ADDR = `MINSTRET;
969
        #20;
970
        if(CSR_DATA_OUT != 32'h00000000)
971
        begin
972
            $display("FAIL. Check the results.");
973
            $finish;
974
        end
975
        $display("Attempt to clear the read-write register MINSTRET successful. Result OK.");
976
 
977
        CSR_ADDR = `MINSTRETH;
978
        #20;
979
        if(CSR_DATA_OUT != 32'h00000000)
980
        begin
981
            $display("FAIL. Check the results.");
982
            $finish;
983
        end
984
        $display("Attempt to clear the read-write register MINSTRETH successful. Result OK.");
985
 
986
        CSR_ADDR = `MCOUNTINHIBIT;
987
        #20;
988
        if(CSR_DATA_OUT != {29'b0, 1'b0, 1'b0, 1'b0})
989
        begin
990
            $display("FAIL. Check the results.");
991
            $finish;
992
        end
993
        $display("Attempt to clear the read-write register MCOUNTINHIBIT successful. Result OK.");
994
 
995
        $display("Clear operation successfully tested.");
996
 
997
        //----------------------------------------------------------------------
998
        // WRITE IMMEDIATE OPERATION TEST
999
        //----------------------------------------------------------------------
1000
 
1001
        $display("Testing write immediate operation for each CSR...");
1002
 
1003
        WR_EN = 1'b1;
1004
        CSR_OP = {1'b1, `CSR_RW};
1005
        CSR_UIMM = 5'b11111;
1006
        CSR_DATA_IN = 32'hFFFFFFFF;
1007
 
1008
        CSR_ADDR = `CYCLE;
1009
        #20;
1010
        if(CSR_DATA_OUT == 32'h0000001F)
1011
        begin
1012
            $display("FAIL. Check the results.");
1013
            $finish;
1014
        end
1015
        $display("Attempt to write the read-only register CYCLE unsuccessful. Result OK.");
1016
 
1017
        CSR_ADDR = `CYCLEH;
1018
        #20;
1019
        if(CSR_DATA_OUT == 32'h0000001F)
1020
        begin
1021
            $display("FAIL. Check the results.");
1022
            $finish;
1023
        end
1024
        $display("Attempt to write the read-only register CYCLEH unsuccessful. Result OK.");
1025
 
1026
        CSR_ADDR = `TIME;
1027
        #20;
1028
        if(CSR_DATA_OUT == 32'h0000001F)
1029
        begin
1030
            $display("FAIL. Check the results.");
1031
            $finish;
1032
        end
1033
        $display("Attempt to write the read-only register TIME unsuccessful. Result OK.");
1034
 
1035
        CSR_ADDR = `TIMEH;
1036
        #20;
1037
        if(CSR_DATA_OUT == 32'h0000001F)
1038
        begin
1039
            $display("FAIL. Check the results.");
1040
            $finish;
1041
        end
1042
        $display("Attempt to write the read-only register TIMEH unsuccessful. Result OK.");
1043
 
1044
        CSR_ADDR = `INSTRET;
1045
        #20;
1046
        if(CSR_DATA_OUT == 32'h0000001F)
1047
        begin
1048
            $display("FAIL. Check the results.");
1049
            $finish;
1050
        end
1051
        $display("Attempt to write the read-only register INSTRET unsuccessful. Result OK.");
1052
 
1053
        CSR_ADDR = `INSTRETH;
1054
        #20;
1055
        if(CSR_DATA_OUT == 32'h0000001F)
1056
        begin
1057
            $display("FAIL. Check the results.");
1058
            $finish;
1059
        end
1060
        $display("Attempt to write the read-only register INSTRETH unsuccessful. Result OK.");
1061
 
1062
        CSR_ADDR = `MSTATUS;
1063
        #20;
1064
        if(CSR_DATA_OUT != {19'b0, 2'b11, 3'b0, 1'b0, 3'b0 , 1'b1, 3'b0})
1065
        begin
1066
            $display("FAIL. Check the results.");
1067
            $finish;
1068
        end
1069
        $display("Attempt to write the read-write register MSTATUS successful. Result OK.");
1070
 
1071
        CSR_ADDR = `MISA;
1072
        #20;
1073
        if(CSR_DATA_OUT != {2'b01, 4'b0, 26'b00000000000000000100000000})
1074
        begin
1075
            $display("FAIL. Check the results.");
1076
            $finish;
1077
        end
1078
        $display("Attempt to write the read-only register MISA unsuccessful. Result OK.");
1079
 
1080
        CSR_ADDR = `MIE;
1081
        #20;
1082
        if(CSR_DATA_OUT != {20'b0, 1'b0, 3'b0, 1'b0, 3'b0, 1'b1, 3'b0})
1083
        begin
1084
            $display("FAIL. Check the results.");
1085
            $finish;
1086
        end
1087
        $display("Attempt to write the read-write register MIE successful. Result OK.");
1088
 
1089
        CSR_ADDR = `MTVEC;
1090
        #20;
1091
        if(CSR_DATA_OUT != 32'h0000001F)
1092
        begin
1093
            $display("FAIL. Check the results.");
1094
            $finish;
1095
        end
1096
        $display("Attempt to write the read-write register MTVEC successful. Result OK.");
1097
 
1098
        CSR_ADDR = `MSCRATCH;
1099
        #20;
1100
        if(CSR_DATA_OUT != 32'h0000001F)
1101
        begin
1102
            $display("FAIL. Check the results.");
1103
            $finish;
1104
        end
1105
        $display("Attempt to write the read-write register MSCRATCH successful. Result OK.");
1106
 
1107
        CSR_ADDR = `MEPC;
1108
        #20;
1109
        if(CSR_DATA_OUT != 32'h0000001C)
1110
        begin
1111
            $display("FAIL. Check the results.");
1112
            $finish;
1113
        end
1114
        $display("Attempt to write the read-write register MEPC successful. Result OK.");
1115
 
1116
        CSR_ADDR = `MCAUSE;
1117
        #20;
1118
        if(CSR_DATA_OUT != 32'h0000001F)
1119
        begin
1120
            $display("FAIL. Check the results.");
1121
            $finish;
1122
        end
1123
        $display("Attempt to write the read-only register MCAUSE unsuccessful. Result OK.");
1124
 
1125
        CSR_ADDR = `MTVAL;
1126
        #20;
1127
        if(CSR_DATA_OUT != 32'h0000001F)
1128
        begin
1129
            $display("FAIL. Check the results.");
1130
            $finish;
1131
        end
1132
        $display("Attempt to write the read-only register MTVAL unsuccessful. Result OK.");
1133
 
1134
        CSR_ADDR = `MIP;
1135
        #20;
1136
        if(CSR_DATA_OUT != 32'h00000000)
1137
        begin
1138
            $display("FAIL. Check the results.");
1139
            $finish;
1140
        end
1141
        $display("Attempt to write the read-only register MIP unsuccessful. Result OK.");
1142
 
1143
        CSR_ADDR = `MCYCLE;
1144
        #20;
1145
        if(CSR_DATA_OUT != 32'h00000020)
1146
        begin
1147
            $display("FAIL. Check the results.");
1148
            $finish;
1149
        end
1150
        $display("Attempt to write the read-write register MCYCLE successful. Result OK.");
1151
 
1152
        CSR_ADDR = `MCYCLEH;
1153
        #20;
1154
        if(CSR_DATA_OUT != 32'h0000001F)
1155
        begin
1156
            $display("FAIL. Check the results.");
1157
            $finish;
1158
        end
1159
        $display("Attempt to write the read-write register MCYCLEH successful. Result OK.");
1160
 
1161
        CSR_ADDR = `MINSTRET;
1162
        #20;
1163
        if(CSR_DATA_OUT != 32'h0000001F)
1164
        begin
1165
            $display("FAIL. Check the results.");
1166
            $finish;
1167
        end
1168
        $display("Attempt to write the read-write register MINSTRET successful. Result OK.");
1169
 
1170
        CSR_ADDR = `MINSTRETH;
1171
        #20;
1172
        if(CSR_DATA_OUT != 32'h0000001F)
1173
        begin
1174
            $display("FAIL. Check the results.");
1175
            $finish;
1176
        end
1177
        $display("Attempt to write the read-write register MINSTRETH successful. Result OK.");
1178
 
1179
        CSR_ADDR = `MCOUNTINHIBIT;
1180
        #20;
1181
        if(CSR_DATA_OUT != {29'b0, 1'b1, 1'b0, 1'b1})
1182
        begin
1183
            $display("FAIL. Check the results.");
1184
            $finish;
1185
        end
1186
        $display("Attempt to write the read-write register MCOUNTINHIBIT successful. Result OK.");
1187
 
1188
        $display("Write operation successfully tested.");
1189
 
1190
        //----------------------------------------------------------------------
1191
        // SET IMMEDIATE OPERATION TEST
1192
        //----------------------------------------------------------------------
1193
 
1194
        #5;
1195
        RESET = 1'b1;
1196
        #15;
1197
        RESET = 1'b0;
1198
 
1199
        $display("Testing set immediate operation for each CSR...");
1200
 
1201
        WR_EN = 1'b1;
1202
        CSR_OP = {1'b1, `CSR_RS};
1203
        CSR_UIMM = 5'b11111;
1204
        CSR_DATA_IN = 32'hFFFFFFFF;
1205
 
1206
        CSR_ADDR = `CYCLE;
1207
        #20;
1208
        if(CSR_DATA_OUT == 32'h0000001F)
1209
        begin
1210
            $display("FAIL. Check the results.");
1211
            $finish;
1212
        end
1213
        $display("Attempt to set the read-only register CYCLE unsuccessful. Result OK.");
1214
 
1215
        CSR_ADDR = `CYCLEH;
1216
        #20;
1217
        if(CSR_DATA_OUT == 32'h0000001F)
1218
        begin
1219
            $display("FAIL. Check the results.");
1220
            $finish;
1221
        end
1222
        $display("Attempt to set the read-only register CYCLEH unsuccessful. Result OK.");
1223
 
1224
        CSR_ADDR = `TIME;
1225
        #20;
1226
        if(CSR_DATA_OUT == 32'h0000001F)
1227
        begin
1228
            $display("FAIL. Check the results.");
1229
            $finish;
1230
        end
1231
        $display("Attempt to set the read-only register TIME unsuccessful. Result OK.");
1232
 
1233
        CSR_ADDR = `TIMEH;
1234
        #20;
1235
        if(CSR_DATA_OUT == 32'h0000001F)
1236
        begin
1237
            $display("FAIL. Check the results.");
1238
            $finish;
1239
        end
1240
        $display("Attempt to set the read-only register TIMEH unsuccessful. Result OK.");
1241
 
1242
        CSR_ADDR = `INSTRET;
1243
        #20;
1244
        if(CSR_DATA_OUT == 32'h0000001F)
1245
        begin
1246
            $display("FAIL. Check the results.");
1247
            $finish;
1248
        end
1249
        $display("Attempt to set the read-only register INSTRET unsuccessful. Result OK.");
1250
 
1251
        CSR_ADDR = `INSTRETH;
1252
        #20;
1253
        if(CSR_DATA_OUT == 32'h0000001F)
1254
        begin
1255
            $display("FAIL. Check the results.");
1256
            $finish;
1257
        end
1258
        $display("Attempt to set the read-only register INSTRETH unsuccessful. Result OK.");
1259
 
1260
        CSR_ADDR = `MSTATUS;
1261
        #20;
1262
        if(CSR_DATA_OUT != {19'b0, 2'b11, 3'b0, 1'b1, 3'b0 , 1'b1, 3'b0})
1263
        begin
1264
            $display("FAIL. Check the results.");
1265
            $finish;
1266
        end
1267
        $display("Attempt to set the read-write register MSTATUS successful. Result OK.");
1268
 
1269
        CSR_ADDR = `MISA;
1270
        #20;
1271
        if(CSR_DATA_OUT != {2'b01, 4'b0, 26'b00000000000000000100000000})
1272
        begin
1273
            $display("FAIL. Check the results.");
1274
            $finish;
1275
        end
1276
        $display("Attempt to set the read-only register MISA unsuccessful. Result OK.");
1277
 
1278
        CSR_ADDR = `MIE;
1279
        #20;
1280
        if(CSR_DATA_OUT != {20'b0, 1'b0, 3'b0, 1'b0, 3'b0, 1'b1, 3'b0})
1281
        begin
1282
            $display("FAIL. Check the results.");
1283
            $finish;
1284
        end
1285
        $display("Attempt to set the read-write register MIE successful. Result OK.");
1286
 
1287
        CSR_ADDR = `MTVEC;
1288
        #20;
1289
        if(CSR_DATA_OUT != 32'h0000001F)
1290
        begin
1291
            $display("FAIL. Check the results.");
1292
            $finish;
1293
        end
1294
        $display("Attempt to set the read-write register MTVEC successful. Result OK.");
1295
 
1296
        CSR_ADDR = `MSCRATCH;
1297
        #20;
1298
        if(CSR_DATA_OUT != 32'h0000001F)
1299
        begin
1300
            $display("FAIL. Check the results.");
1301
            $finish;
1302
        end
1303
        $display("Attempt to set the read-write register MSCRATCH successful. Result OK.");
1304
 
1305
        CSR_ADDR = `MEPC;
1306
        #20;
1307
        if(CSR_DATA_OUT != 32'h0000001C)
1308
        begin
1309
            $display("FAIL. Check the results.");
1310
            $finish;
1311
        end
1312
        $display("Attempt to set the read-write register MEPC successful. Result OK.");
1313
 
1314
        CSR_ADDR = `MCAUSE;
1315
        #20;
1316
        if(CSR_DATA_OUT != 32'h0000001F)
1317
        begin
1318
            $display("FAIL. Check the results.");
1319
            $finish;
1320
        end
1321
        $display("Attempt to set the read-only register MCAUSE unsuccessful. Result OK.");
1322
 
1323
        CSR_ADDR = `MTVAL;
1324
        #20;
1325
        if(CSR_DATA_OUT != 32'h0000001F)
1326
        begin
1327
            $display("FAIL. Check the results.");
1328
            $finish;
1329
        end
1330
        $display("Attempt to set the read-only register MTVAL unsuccessful. Result OK.");
1331
 
1332
        CSR_ADDR = `MIP;
1333
        #20;
1334
        if(CSR_DATA_OUT != 32'h00000000)
1335
        begin
1336
            $display("FAIL. Check the results.");
1337
            $finish;
1338
        end
1339
        $display("Attempt to set the read-only register MIP unsuccessful. Result OK.");
1340
 
1341
        CSR_ADDR = `MCYCLE;
1342
        #20;
1343
        if(CSR_DATA_OUT != 32'h00000020)
1344
        begin
1345
            $display("FAIL. Check the results.");
1346
            $finish;
1347
        end
1348
        $display("Attempt to set the read-write register MCYCLE successful. Result OK.");
1349
 
1350
        CSR_ADDR = `MCYCLEH;
1351
        #20;
1352
        if(CSR_DATA_OUT != 32'h0000001F)
1353
        begin
1354
            $display("FAIL. Check the results.");
1355
            $finish;
1356
        end
1357
        $display("Attempt to set the read-write register MCYCLEH successful. Result OK.");
1358
 
1359
        CSR_ADDR = `MINSTRET;
1360
        #20;
1361
        if(CSR_DATA_OUT != 32'h0000001F)
1362
        begin
1363
            $display("FAIL. Check the results.");
1364
            $finish;
1365
        end
1366
        $display("Attempt to set the read-write register MINSTRET successful. Result OK.");
1367
 
1368
        CSR_ADDR = `MINSTRETH;
1369
        #20;
1370
        if(CSR_DATA_OUT != 32'h0000001F)
1371
        begin
1372
            $display("FAIL. Check the results.");
1373
            $finish;
1374
        end
1375
        $display("Attempt to set the read-write register MINSTRETH successful. Result OK.");
1376
 
1377
        CSR_ADDR = `MCOUNTINHIBIT;
1378
        #20;
1379
        if(CSR_DATA_OUT != {29'b0, 1'b1, 1'b0, 1'b1})
1380
        begin
1381
            $display("FAIL. Check the results.");
1382
            $finish;
1383
        end
1384
        $display("Attempt to set the read-write register MCOUNTINHIBIT successful. Result OK.");
1385
 
1386
        $display("Set operation successfully tested.");
1387
 
1388
        //----------------------------------------------------------------------
1389
        // CLEAR IMMEDIATE OPERATION TEST
1390
        //----------------------------------------------------------------------
1391
 
1392
        $display("Testing clear immediate operation for each CSR...");
1393
 
1394
        WR_EN = 1'b1;
1395
        CSR_OP = {1'b1, `CSR_RC};
1396
        CSR_UIMM = 5'b11111;
1397
        CSR_DATA_IN = 32'hFFFFFFFF;
1398
 
1399
        CSR_ADDR = `CYCLE;
1400
        #20;
1401
        if(CSR_DATA_OUT == 32'h00000000)
1402
        begin
1403
            $display("FAIL. Check the results.");
1404
            $finish;
1405
        end
1406
        $display("Attempt to clear the read-only register CYCLE unsuccessful. Result OK.");
1407
 
1408
        CSR_ADDR = `CYCLEH;
1409
        #20;
1410
        if(CSR_DATA_OUT != 32'h0000001F)
1411
        begin
1412
            $display("FAIL. Check the results.");
1413
            $finish;
1414
        end
1415
        $display("Attempt to clear the read-only register CYCLEH unsuccessful. Result OK.");
1416
 
1417
        CSR_ADDR = `TIME;
1418
        #20;
1419
        if(CSR_DATA_OUT != 32'h00000000)
1420
        begin
1421
            $display("FAIL. Check the results.");
1422
            $finish;
1423
        end
1424
        $display("Attempt to clear the read-only register TIME unsuccessful. Result OK.");
1425
 
1426
        CSR_ADDR = `TIMEH;
1427
        #20;
1428
        if(CSR_DATA_OUT != 32'h00000000)
1429
        begin
1430
            $display("FAIL. Check the results.");
1431
            $finish;
1432
        end
1433
        $display("Attempt to clear the read-only register TIMEH unsuccessful. Result OK.");
1434
 
1435
        CSR_ADDR = `INSTRET;
1436
        #20;
1437
        if(CSR_DATA_OUT != 32'h0000001F)
1438
        begin
1439
            $display("FAIL. Check the results.");
1440
            $finish;
1441
        end
1442
        $display("Attempt to clear the read-only register INSTRET unsuccessful. Result OK.");
1443
 
1444
        CSR_ADDR = `INSTRETH;
1445
        #20;
1446
        if(CSR_DATA_OUT != 32'h0000001F)
1447
        begin
1448
            $display("FAIL. Check the results.");
1449
            $finish;
1450
        end
1451
        $display("Attempt to clear the read-only register INSTRETH unsuccessful. Result OK.");
1452
 
1453
        CSR_ADDR = `MSTATUS;
1454
        #20;
1455
        if(CSR_DATA_OUT != {19'b0, 2'b11, 3'b0, 1'b1, 3'b0 , 1'b0, 3'b0})
1456
        begin
1457
            $display("FAIL. Check the results.");
1458
            $finish;
1459
        end
1460
        $display("Attempt to clear the read-write register MSTATUS successful. Result OK.");
1461
 
1462
        CSR_ADDR = `MISA;
1463
        #20;
1464
        if(CSR_DATA_OUT != {2'b01, 4'b0, 26'b00000000000000000100000000})
1465
        begin
1466
            $display("FAIL. Check the results.");
1467
            $finish;
1468
        end
1469
        $display("Attempt to clear the read-only register MISA unsuccessful. Result OK.");
1470
 
1471
        CSR_ADDR = `MIE;
1472
        #20;
1473
        if(CSR_DATA_OUT != {20'b0, 1'b0, 3'b0, 1'b0, 3'b0, 1'b0, 3'b0})
1474
        begin
1475
            $display("FAIL. Check the results.");
1476
            $finish;
1477
        end
1478
        $display("Attempt to clear the read-write register MIE successful. Result OK.");
1479
 
1480
        CSR_ADDR = `MTVEC;
1481
        #20;
1482
        if(CSR_DATA_OUT != 32'h00000000)
1483
        begin
1484
            $display("FAIL. Check the results.");
1485
            $finish;
1486
        end
1487
        $display("Attempt to clear the read-write register MTVEC successful. Result OK.");
1488
 
1489
        CSR_ADDR = `MSCRATCH;
1490
        #20;
1491
        if(CSR_DATA_OUT != 32'h00000000)
1492
        begin
1493
            $display("FAIL. Check the results.");
1494
            $finish;
1495
        end
1496
        $display("Attempt to clear the read-write register MSCRATCH successful. Result OK.");
1497
 
1498
        CSR_ADDR = `MEPC;
1499
        #20;
1500
        if(CSR_DATA_OUT != 32'h00000000)
1501
        begin
1502
            $display("FAIL. Check the results.");
1503
            $finish;
1504
        end
1505
        $display("Attempt to clear the read-write register MEPC successful. Result OK.");
1506
 
1507
        CSR_ADDR = `MCAUSE;
1508
        #20;
1509
        if(CSR_DATA_OUT != 32'h00000000)
1510
        begin
1511
            $display("FAIL. Check the results.");
1512
            $finish;
1513
        end
1514
        $display("Attempt to clear the read-only register MCAUSE unsuccessful. Result OK.");
1515
 
1516
        CSR_ADDR = `MTVAL;
1517
        #20;
1518
        if(CSR_DATA_OUT != 32'h00000000)
1519
        begin
1520
            $display("FAIL. Check the results.");
1521
            $finish;
1522
        end
1523
        $display("Attempt to clear the read-only register MTVAL unsuccessful. Result OK.");
1524
 
1525
        CSR_ADDR = `MIP;
1526
        #20;
1527
        if(CSR_DATA_OUT != 32'h00000000)
1528
        begin
1529
            $display("FAIL. Check the results.");
1530
            $finish;
1531
        end
1532
        $display("Attempt to clear the read-only register MIP unsuccessful. Result OK.");
1533
 
1534
        CSR_ADDR = `MCYCLE;
1535
        #20;
1536
        if(CSR_DATA_OUT != 32'h00000020)
1537
        begin
1538
            $display("FAIL. Check the results.");
1539
            $finish;
1540
        end
1541
        $display("Attempt to clear the read-write register MCYCLE successful. Result OK.");
1542
 
1543
        CSR_ADDR = `MCYCLEH;
1544
        #20;
1545
        if(CSR_DATA_OUT != 32'h00000000)
1546
        begin
1547
            $display("FAIL. Check the results.");
1548
            $finish;
1549
        end
1550
        $display("Attempt to clear the read-write register MCYCLEH successful. Result OK.");
1551
 
1552
        CSR_ADDR = `MINSTRET;
1553
        #20;
1554
        if(CSR_DATA_OUT != 32'h00000000)
1555
        begin
1556
            $display("FAIL. Check the results.");
1557
            $finish;
1558
        end
1559
        $display("Attempt to clear the read-write register MINSTRET successful. Result OK.");
1560
 
1561
        CSR_ADDR = `MINSTRETH;
1562
        #20;
1563
        if(CSR_DATA_OUT != 32'h00000000)
1564
        begin
1565
            $display("FAIL. Check the results.");
1566
            $finish;
1567
        end
1568
        $display("Attempt to clear the read-write register MINSTRETH successful. Result OK.");
1569
 
1570
        CSR_ADDR = `MCOUNTINHIBIT;
1571
        #20;
1572
        if(CSR_DATA_OUT != {29'b0, 1'b0, 1'b0, 1'b0})
1573
        begin
1574
            $display("FAIL. Check the results.");
1575
            $finish;
1576
        end
1577
        $display("Attempt to clear the read-write register MCOUNTINHIBIT successful. Result OK.");
1578
 
1579
        $display("Clear operation successfully tested.");
1580
 
1581
        //----------------------------------------------------------------------
1582
        // INTERRUPT PENDING BITS TEST
1583
        //----------------------------------------------------------------------
1584
 
1585
        #5;
1586
        RESET = 1'b1;
1587
        #15;
1588
        RESET = 1'b0;
1589
 
1590
        $display("Testing interrupt pending bits setup...");
1591
 
1592
        E_IRQ = 1'b1;
1593
        T_IRQ = 1'b1;
1594
        S_IRQ = 1'b1;
1595
        #20;
1596
 
1597
        if(MEIP_OUT != 1'b1)
1598
        begin
1599
            $display("FAIL. Check the results.");
1600
            $finish;
1601
        end
1602
        if(MTIP_OUT != 1'b1)
1603
        begin
1604
            $display("FAIL. Check the results.");
1605
            $finish;
1606
        end
1607
        if(MSIP_OUT != 1'b1)
1608
        begin
1609
            $display("FAIL. Check the results.");
1610
            $finish;
1611
        end
1612
 
1613
        $display("Interrupt pending bits successfully tested.");
1614
 
1615
        //----------------------------------------------------------------------
1616
        // INTERRUPT ENABLE BITS TEST
1617
        //----------------------------------------------------------------------
1618
 
1619
        $display("Testing interrupt enable bits setup...");
1620
 
1621
        WR_EN = 1'b1;
1622
        CSR_ADDR = `MSTATUS;
1623
        CSR_DATA_IN = 32'hFFFFFFFF;
1624
        CSR_OP = {1'b0, `CSR_RW};
1625
        #20;
1626
        WR_EN = 1'b1;
1627
        CSR_ADDR = `MIE;
1628
        CSR_DATA_IN = 32'hFFFFFFFF;
1629
        CSR_OP = {1'b0, `CSR_RW};
1630
        #20;
1631
 
1632
        if(MIE != 1'b1)
1633
        begin
1634
            $display("FAIL. Check the results.");
1635
            $finish;
1636
        end
1637
        if(MEIE_OUT != 1'b1)
1638
        begin
1639
            $display("FAIL. Check the results.");
1640
            $finish;
1641
        end
1642
        if(MTIE_OUT != 1'b1)
1643
        begin
1644
            $display("FAIL. Check the results.");
1645
            $finish;
1646
        end
1647
        if(MSIE_OUT != 1'b1)
1648
        begin
1649
            $display("FAIL. Check the results.");
1650
            $finish;
1651
        end
1652
 
1653
        $display("Interrupt enable bits successfully tested.");
1654
 
1655
        //----------------------------------------------------------------------
1656
        // EPC SET TEST
1657
        //----------------------------------------------------------------------
1658
 
1659
        $display("Testing EPC setup...");
1660
 
1661
        SET_EPC = 1'b1;
1662
        PC = $random;
1663
        CSR_ADDR = `MEPC;
1664
        #20;
1665
        SET_EPC = 1'b0;
1666
 
1667
        if(CSR_DATA_OUT != PC)
1668
        begin
1669
            $display("FAIL. Check the results.");
1670
            $finish;
1671
        end
1672
        if(EPC_OUT != PC)
1673
        begin
1674
            $display("FAIL. Check the results.");
1675
            $finish;
1676
        end
1677
 
1678
        $display("EPC setup successfully tested.");
1679
 
1680
        //----------------------------------------------------------------------
1681
        // MCAUSE SET TEST
1682
        //----------------------------------------------------------------------
1683
 
1684
        $display("Testing MCAUSE setup...");
1685
 
1686
        SET_CAUSE = 1'b1;
1687
        CAUSE_IN = $random;
1688
        I_OR_E = 1'b1;
1689
        CSR_ADDR = `MCAUSE;
1690
        #20;
1691
 
1692
        if(CSR_DATA_OUT != {I_OR_E, 27'b0, CAUSE_IN})
1693
        begin
1694
            $display("FAIL. Check the results.");
1695
            $finish;
1696
        end
1697
 
1698
        $display("MCAUSE setup successfully tested.");
1699
 
1700
        //----------------------------------------------------------------------
1701
        // TRAP ADDRESS GENERATION TEST
1702
        //----------------------------------------------------------------------
1703
 
1704
        $display("Testing TRAP ADDRESS generation...");
1705
 
1706
        $display("Testing exceptions in Direct Mode...");
1707
        WR_EN =1'b1;
1708
        CSR_ADDR = `MTVEC;
1709
        CSR_OP = {1'b0, `CSR_RW};
1710
        CSR_DATA_IN = $random;
1711
        CSR_DATA_IN[1:0] = 2'b00;
1712
        SET_CAUSE = 1'b1;
1713
        CAUSE_IN = $random;
1714
        I_OR_E = 1'b0;
1715
        #20;
1716
 
1717
        if(CSR_DATA_OUT != {CSR_DATA_IN[31:2], 2'b00})
1718
        begin
1719
            $display("FAIL. Check the results.");
1720
            $finish;
1721
        end
1722
        if(TRAP_ADDRESS != {CSR_DATA_IN[31:2], 2'b00})
1723
        begin
1724
            $display("FAIL. Check the results.");
1725
            $finish;
1726
        end
1727
 
1728
        $display("Exceptions in Direct Mode OK.");
1729
 
1730
        $display("Testing interrupts in Direct Mode...");
1731
        WR_EN =1'b1;
1732
        CSR_ADDR = `MTVEC;
1733
        CSR_OP = {1'b0, `CSR_RW};
1734
        CSR_DATA_IN = $random;
1735
        CSR_DATA_IN[1:0] = 2'b00;
1736
        SET_CAUSE = 1'b1;
1737
        CAUSE_IN = $random;
1738
        I_OR_E = 1'b1;
1739
        #20;
1740
 
1741
        if(CSR_DATA_OUT != {CSR_DATA_IN[31:2], 2'b00})
1742
        begin
1743
            $display("FAIL. Check the results.");
1744
            $finish;
1745
        end
1746
        if(TRAP_ADDRESS != {CSR_DATA_IN[31:2], 2'b00})
1747
        begin
1748
            $display("FAIL. Check the results.");
1749
            $finish;
1750
        end
1751
 
1752
        $display("Interrupts in Direct Mode OK.");
1753
 
1754
        $display("Testing exceptions in Vectored Mode...");
1755
        WR_EN =1'b1;
1756
        CSR_ADDR = `MTVEC;
1757
        CSR_OP = {1'b0, `CSR_RW};
1758
        CSR_DATA_IN = $random;
1759
        CSR_DATA_IN[1:0] = 2'b01;
1760
        SET_CAUSE = 1'b1;
1761
        CAUSE_IN = $random;
1762
        I_OR_E = 1'b0;
1763
        #20;
1764
 
1765
        if(CSR_DATA_OUT != {CSR_DATA_IN[31:2], 2'b01})
1766
        begin
1767
            $display("FAIL. Check the results.");
1768
            $finish;
1769
        end
1770
        if(TRAP_ADDRESS != {CSR_DATA_IN[31:2], 2'b00})
1771
        begin
1772
            $display("FAIL. Check the results.");
1773
            $finish;
1774
        end
1775
 
1776
        $display("Exceptions in Vectored Mode OK.");
1777
 
1778
        $display("Testing interrupts in Vectored Mode...");
1779
        WR_EN =1'b1;
1780
        CSR_ADDR = `MTVEC;
1781
        CSR_OP = {1'b0, `CSR_RW};
1782
        CSR_DATA_IN = $random;
1783
        CSR_DATA_IN[1:0] = 2'b01;
1784
        SET_CAUSE = 1'b1;
1785
        CAUSE_IN = $random;
1786
        I_OR_E = 1'b1;
1787
        #20;
1788
 
1789
        if(CSR_DATA_OUT != {CSR_DATA_IN[31:2], 2'b01})
1790
        begin
1791
            $display("FAIL. Check the results.");
1792
            $finish;
1793
        end
1794
        base_offset = CAUSE_IN << 2;
1795
        if(TRAP_ADDRESS != ({CSR_DATA_IN[31:2],2'b00} + base_offset))
1796
        begin
1797
            $display("FAIL. Check the results.");
1798
            $finish;
1799
        end
1800
 
1801
        $display("Interrupts in Vectored Mode OK.");
1802
 
1803
        $display("TRAP ADDRESS generation successfully tested.");
1804
 
1805
        //----------------------------------------------------------------------
1806
        // MIE CLEAR & SET TEST
1807
        //----------------------------------------------------------------------
1808
 
1809
        WR_EN =1'b0;
1810
 
1811
        $display("Testing MIE clear operation...");
1812
 
1813
        MIE_CLEAR = 1'b1;
1814
        CSR_ADDR = `MSTATUS;
1815
        #20;
1816
        MIE_CLEAR = 1'b0;
1817
 
1818
        if(MIE != 1'b0)
1819
        begin
1820
            $display("FAIL. Check the results.");
1821
            $finish;
1822
        end
1823
        if(CSR_DATA_OUT != {19'b0, 2'b11, 3'b0, 1'b1, 3'b0 , 1'b0, 3'b0})
1824
        begin
1825
            $display("FAIL. Check the results.");
1826
            $finish;
1827
        end
1828
 
1829
        MIE_SET = 1'b1;
1830
        CSR_ADDR = `MSTATUS;
1831
        #20;
1832
        MIE_SET = 1'b0;
1833
 
1834
        if(MIE != 1'b1)
1835
        begin
1836
            $display("FAIL. Check the results.");
1837
            $finish;
1838
        end
1839
        if(CSR_DATA_OUT != {19'b0, 2'b11, 3'b0, 1'b1, 3'b0 , 1'b1, 3'b0})
1840
        begin
1841
            $display("FAIL. Check the results.");
1842
            $finish;
1843
        end
1844
 
1845
        $display("MIE CLEAR & SET operation successfully tested.");
1846
 
1847
        //----------------------------------------------------------------------
1848
        // CYCLE & INSTRET COUNTING TEST
1849
        //----------------------------------------------------------------------
1850
 
1851
        WR_EN =1'b0;
1852
        #5;
1853
        RESET = 1'b1;
1854
        #15;
1855
        RESET = 1'b0;
1856
 
1857
        $display("Testing CYCLE and INSTRET counting...");
1858
 
1859
        INSTRET_INC = 1'b1;
1860
        CSR_ADDR = `CYCLE;
1861
        #15;
1862
 
1863
        if(CSR_DATA_OUT != `MCYCLE_RESET + 1)
1864
        begin
1865
            $display("FAIL. Check the results.");
1866
            $finish;
1867
        end
1868
        CSR_ADDR = `INSTRET;
1869
        #5;
1870
        if(CSR_DATA_OUT != `MINSTRET_RESET + 1)
1871
        begin
1872
            $display("FAIL. Check the results.");
1873
            $finish;
1874
        end
1875
 
1876
        INSTRET_INC = 1'b0;
1877
        CSR_ADDR = `CYCLE;
1878
        #15;
1879
 
1880
        if(CSR_DATA_OUT != `MCYCLE_RESET + 2)
1881
        begin
1882
            $display("FAIL. Check the results.");
1883
            $finish;
1884
        end
1885
        CSR_ADDR = `INSTRET;
1886
        #5;
1887
        if(CSR_DATA_OUT != `MINSTRET_RESET + 1)
1888
        begin
1889
            $display("FAIL. Check the results.");
1890
            $finish;
1891
        end
1892
 
1893
        WR_EN = 1'b1;
1894
        INSTRET_INC = 1'b1;
1895
        CSR_OP = {1'b0, CSR_OP};
1896
        CSR_ADDR = `MCOUNTINHIBIT;
1897
        CSR_DATA_IN = {29'b0, 3'b101};
1898
        #20;
1899
 
1900
        WR_EN = 1'b0;
1901
        CSR_ADDR = `CYCLE;
1902
        #15;
1903
 
1904
        if(CSR_DATA_OUT != `MCYCLE_RESET + 3)
1905
        begin
1906
            $display("FAIL. Check the results.");
1907
            $finish;
1908
        end
1909
        CSR_ADDR = `INSTRET;
1910
        #5;
1911
        if(CSR_DATA_OUT != `MINSTRET_RESET + 2)
1912
        begin
1913
            $display("FAIL. Check the results.");
1914
            $finish;
1915
        end
1916
 
1917
        WR_EN = 1'b1;
1918
        CSR_OP = {1'b0, CSR_OP};
1919
        CSR_ADDR = `MCOUNTINHIBIT;
1920
        CSR_DATA_IN = {29'b0, 3'b000};
1921
        #20;
1922
 
1923
        WR_EN = 1'b0;
1924
        CSR_ADDR = `CYCLE;
1925
        #15;
1926
 
1927
        if(CSR_DATA_OUT != `MCYCLE_RESET + 4)
1928
        begin
1929
            $display("FAIL. Check the results.");
1930
            $finish;
1931
        end
1932
        CSR_ADDR = `INSTRET;
1933
        #5;
1934
        if(CSR_DATA_OUT != `MINSTRET_RESET + 3)
1935
        begin
1936
            $display("FAIL. Check the results.");
1937
            $finish;
1938
        end
1939
 
1940
        $display("CYCLE & INSTRET counting successfully tested.");
1941
 
1942
        $display("CSR Register File successfully tested.");
1943
 
1944
    end
1945
 
1946
endmodule
1947
 

powered by: WebSVN 2.1.0

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