1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
|
# See LICENSE for license details.
#*****************************************************************************
# ipi.S
#-----------------------------------------------------------------------------
#
# Test interprocessor interrupts.
#
#include "riscv_test.h"
#include "test_macros.h"
RVTEST_RV64S
RVTEST_CODE_BEGIN
# clear pending IPIs then enable interrupts
li s8, 0 # number of taken timer interrupts
li s9, 10 # how many interrupts to run for
la a0, handler
csrw evec, a0
csrw compare, 1
csrw count, 0
li a0, SR_EI | (1 << (IRQ_TIMER + SR_IM_SHIFT))
csrs status, a0
# advance an LFSR 1000 times
li s0, 1023
li s4, 0
1:srl s2,s0,3
xor s2,s2,s0
and s2,s2,1
srl s0,s0,1
sll s2,s2,9
or s0,s2,s0
sll s0,s0,54
srl s0,s0,54
add s4, s4, 1
bltu s8, s9, 1b
csrc status, SR_EI
# make sure the LFSR was computed correctly
li s1, 1023
remu s4, s4, s1
la s1, lfsr
sll s4, s4, 2
add s1, s1, s4
lw s1, (s1)
li TESTNUM, 2
bne s0, s1, fail
RVTEST_PASS
TEST_PASSFAIL
handler:
csrr t0, cause
li t1, 0x8000000000000007
li TESTNUM, 3
bne t0, t1, fail
csrr t0, count
addi t0, t0, 999
csrw compare, t0
add s8, s8, 1
sret
.data
lfsr:
.word 1023
.word 511
.word 255
.word 127
.word 63
.word 31
.word 15
.word 7
.word 515
.word 769
.word 896
.word 448
.word 224
.word 112
.word 56
.word 540
.word 782
.word 903
.word 963
.word 993
.word 1008
.word 504
.word 764
.word 894
.word 959
.word 479
.word 239
.word 119
.word 571
.word 285
.word 142
.word 583
.word 803
.word 913
.word 968
.word 996
.word 498
.word 249
.word 124
.word 574
.word 799
.word 399
.word 199
.word 611
.word 817
.word 920
.word 972
.word 998
.word 499
.word 761
.word 380
.word 702
.word 863
.word 431
.word 215
.word 619
.word 309
.word 666
.word 845
.word 422
.word 211
.word 617
.word 308
.word 154
.word 589
.word 294
.word 147
.word 585
.word 292
.word 146
.word 73
.word 36
.word 18
.word 9
.word 4
.word 2
.word 1
.word 512
.word 256
.word 128
.word 64
.word 32
.word 16
.word 8
.word 516
.word 258
.word 129
.word 576
.word 288
.word 144
.word 72
.word 548
.word 274
.word 137
.word 68
.word 34
.word 17
.word 520
.word 772
.word 386
.word 193
.word 608
.word 304
.word 152
.word 588
.word 806
.word 403
.word 713
.word 356
.word 178
.word 89
.word 44
.word 534
.word 267
.word 133
.word 578
.word 289
.word 656
.word 328
.word 676
.word 338
.word 169
.word 84
.word 42
.word 533
.word 778
.word 901
.word 962
.word 481
.word 752
.word 376
.word 700
.word 862
.word 943
.word 471
.word 747
.word 373
.word 698
.word 861
.word 430
.word 727
.word 875
.word 437
.word 730
.word 877
.word 438
.word 219
.word 109
.word 54
.word 27
.word 13
.word 6
.word 3
.word 513
.word 768
.word 384
.word 192
.word 96
.word 48
.word 24
.word 524
.word 774
.word 387
.word 705
.word 864
.word 432
.word 216
.word 620
.word 822
.word 411
.word 205
.word 102
.word 51
.word 537
.word 268
.word 646
.word 323
.word 673
.word 848
.word 424
.word 724
.word 362
.word 693
.word 858
.word 941
.word 470
.word 235
.word 117
.word 570
.word 797
.word 398
.word 711
.word 867
.word 945
.word 984
.word 1004
.word 1014
.word 507
.word 253
.word 126
.word 575
.word 287
.word 143
.word 71
.word 547
.word 785
.word 904
.word 964
.word 482
.word 241
.word 632
.word 828
.word 926
.word 975
.word 487
.word 755
.word 889
.word 444
.word 734
.word 879
.word 439
.word 731
.word 365
.word 182
.word 91
.word 45
.word 22
.word 11
.word 5
.word 514
.word 257
.word 640
.word 320
.word 160
.word 80
.word 40
.word 532
.word 266
.word 645
.word 834
.word 417
.word 720
.word 360
.word 692
.word 346
.word 685
.word 342
.word 171
.word 85
.word 554
.word 789
.word 906
.word 965
.word 994
.word 497
.word 760
.word 892
.word 958
.word 991
.word 495
.word 247
.word 635
.word 317
.word 158
.word 591
.word 295
.word 659
.word 841
.word 420
.word 210
.word 105
.word 52
.word 26
.word 525
.word 262
.word 131
.word 577
.word 800
.word 400
.word 200
.word 612
.word 306
.word 153
.word 76
.word 550
.word 275
.word 649
.word 324
.word 162
.word 81
.word 552
.word 788
.word 394
.word 709
.word 866
.word 433
.word 728
.word 876
.word 950
.word 475
.word 237
.word 118
.word 59
.word 29
.word 14
.word 519
.word 771
.word 897
.word 960
.word 480
.word 240
.word 120
.word 572
.word 798
.word 911
.word 455
.word 739
.word 881
.word 952
.word 988
.word 1006
.word 1015
.word 1019
.word 509
.word 254
.word 639
.word 319
.word 159
.word 79
.word 39
.word 531
.word 777
.word 388
.word 194
.word 97
.word 560
.word 280
.word 652
.word 838
.word 419
.word 721
.word 872
.word 948
.word 474
.word 749
.word 374
.word 187
.word 93
.word 46
.word 535
.word 779
.word 389
.word 706
.word 353
.word 688
.word 344
.word 684
.word 854
.word 427
.word 213
.word 618
.word 821
.word 922
.word 973
.word 486
.word 243
.word 633
.word 316
.word 670
.word 847
.word 423
.word 723
.word 873
.word 436
.word 218
.word 621
.word 310
.word 155
.word 77
.word 38
.word 19
.word 521
.word 260
.word 130
.word 65
.word 544
.word 272
.word 136
.word 580
.word 290
.word 145
.word 584
.word 804
.word 402
.word 201
.word 100
.word 50
.word 25
.word 12
.word 518
.word 259
.word 641
.word 832
.word 416
.word 208
.word 104
.word 564
.word 282
.word 653
.word 326
.word 163
.word 593
.word 808
.word 916
.word 458
.word 741
.word 882
.word 441
.word 220
.word 622
.word 823
.word 923
.word 461
.word 230
.word 115
.word 569
.word 284
.word 654
.word 839
.word 931
.word 977
.word 1000
.word 1012
.word 506
.word 765
.word 382
.word 703
.word 351
.word 175
.word 87
.word 555
.word 277
.word 650
.word 837
.word 930
.word 465
.word 744
.word 884
.word 442
.word 733
.word 366
.word 695
.word 859
.word 429
.word 214
.word 107
.word 53
.word 538
.word 781
.word 390
.word 195
.word 609
.word 816
.word 408
.word 716
.word 870
.word 435
.word 729
.word 364
.word 694
.word 347
.word 173
.word 86
.word 43
.word 21
.word 522
.word 773
.word 898
.word 449
.word 736
.word 368
.word 184
.word 604
.word 814
.word 919
.word 971
.word 485
.word 754
.word 377
.word 188
.word 606
.word 815
.word 407
.word 715
.word 357
.word 690
.word 345
.word 172
.word 598
.word 299
.word 149
.word 586
.word 805
.word 914
.word 457
.word 228
.word 114
.word 57
.word 28
.word 526
.word 775
.word 899
.word 961
.word 992
.word 496
.word 248
.word 636
.word 830
.word 927
.word 463
.word 231
.word 627
.word 825
.word 412
.word 718
.word 871
.word 947
.word 985
.word 492
.word 758
.word 379
.word 189
.word 94
.word 559
.word 279
.word 651
.word 325
.word 674
.word 337
.word 680
.word 852
.word 426
.word 725
.word 874
.word 949
.word 986
.word 1005
.word 502
.word 251
.word 125
.word 62
.word 543
.word 271
.word 135
.word 579
.word 801
.word 912
.word 456
.word 740
.word 370
.word 185
.word 92
.word 558
.word 791
.word 907
.word 453
.word 738
.word 369
.word 696
.word 860
.word 942
.word 983
.word 1003
.word 501
.word 762
.word 893
.word 446
.word 735
.word 367
.word 183
.word 603
.word 301
.word 150
.word 75
.word 37
.word 530
.word 265
.word 132
.word 66
.word 33
.word 528
.word 264
.word 644
.word 322
.word 161
.word 592
.word 296
.word 660
.word 330
.word 677
.word 850
.word 425
.word 212
.word 106
.word 565
.word 794
.word 909
.word 454
.word 227
.word 625
.word 824
.word 924
.word 974
.word 999
.word 1011
.word 1017
.word 508
.word 766
.word 895
.word 447
.word 223
.word 111
.word 55
.word 539
.word 269
.word 134
.word 67
.word 545
.word 784
.word 392
.word 708
.word 354
.word 177
.word 600
.word 812
.word 918
.word 459
.word 229
.word 626
.word 313
.word 156
.word 590
.word 807
.word 915
.word 969
.word 484
.word 242
.word 121
.word 60
.word 542
.word 783
.word 391
.word 707
.word 865
.word 944
.word 472
.word 748
.word 886
.word 443
.word 221
.word 110
.word 567
.word 795
.word 397
.word 198
.word 99
.word 561
.word 792
.word 908
.word 966
.word 483
.word 753
.word 888
.word 956
.word 990
.word 1007
.word 503
.word 763
.word 381
.word 190
.word 607
.word 303
.word 151
.word 587
.word 293
.word 658
.word 329
.word 164
.word 82
.word 41
.word 20
.word 10
.word 517
.word 770
.word 385
.word 704
.word 352
.word 176
.word 88
.word 556
.word 790
.word 395
.word 197
.word 610
.word 305
.word 664
.word 844
.word 934
.word 467
.word 745
.word 372
.word 186
.word 605
.word 302
.word 663
.word 843
.word 421
.word 722
.word 361
.word 180
.word 90
.word 557
.word 278
.word 139
.word 69
.word 546
.word 273
.word 648
.word 836
.word 418
.word 209
.word 616
.word 820
.word 410
.word 717
.word 358
.word 179
.word 601
.word 300
.word 662
.word 331
.word 165
.word 594
.word 297
.word 148
.word 74
.word 549
.word 786
.word 393
.word 196
.word 98
.word 49
.word 536
.word 780
.word 902
.word 451
.word 737
.word 880
.word 440
.word 732
.word 878
.word 951
.word 987
.word 493
.word 246
.word 123
.word 61
.word 30
.word 527
.word 263
.word 643
.word 833
.word 928
.word 464
.word 232
.word 628
.word 314
.word 669
.word 334
.word 679
.word 851
.word 937
.word 468
.word 234
.word 629
.word 826
.word 925
.word 462
.word 743
.word 883
.word 953
.word 476
.word 750
.word 887
.word 955
.word 477
.word 238
.word 631
.word 827
.word 413
.word 206
.word 615
.word 819
.word 921
.word 460
.word 742
.word 371
.word 697
.word 348
.word 686
.word 855
.word 939
.word 469
.word 746
.word 885
.word 954
.word 989
.word 494
.word 759
.word 891
.word 445
.word 222
.word 623
.word 311
.word 667
.word 333
.word 166
.word 83
.word 553
.word 276
.word 138
.word 581
.word 802
.word 401
.word 712
.word 868
.word 434
.word 217
.word 108
.word 566
.word 283
.word 141
.word 70
.word 35
.word 529
.word 776
.word 900
.word 450
.word 225
.word 624
.word 312
.word 668
.word 846
.word 935
.word 979
.word 1001
.word 500
.word 250
.word 637
.word 318
.word 671
.word 335
.word 167
.word 595
.word 809
.word 404
.word 202
.word 613
.word 818
.word 409
.word 204
.word 614
.word 307
.word 665
.word 332
.word 678
.word 339
.word 681
.word 340
.word 170
.word 597
.word 810
.word 917
.word 970
.word 997
.word 1010
.word 505
.word 252
.word 638
.word 831
.word 415
.word 207
.word 103
.word 563
.word 793
.word 396
.word 710
.word 355
.word 689
.word 856
.word 940
.word 982
.word 491
.word 245
.word 634
.word 829
.word 414
.word 719
.word 359
.word 691
.word 857
.word 428
.word 726
.word 363
.word 181
.word 602
.word 813
.word 406
.word 203
.word 101
.word 562
.word 281
.word 140
.word 582
.word 291
.word 657
.word 840
.word 932
.word 466
.word 233
.word 116
.word 58
.word 541
.word 270
.word 647
.word 835
.word 929
.word 976
.word 488
.word 756
.word 378
.word 701
.word 350
.word 687
.word 343
.word 683
.word 341
.word 682
.word 853
.word 938
.word 981
.word 1002
.word 1013
.word 1018
.word 1021
.word 510
.word 767
.word 383
.word 191
.word 95
.word 47
.word 23
.word 523
.word 261
.word 642
.word 321
.word 672
.word 336
.word 168
.word 596
.word 298
.word 661
.word 842
.word 933
.word 978
.word 489
.word 244
.word 122
.word 573
.word 286
.word 655
.word 327
.word 675
.word 849
.word 936
.word 980
.word 490
.word 757
.word 890
.word 957
.word 478
.word 751
.word 375
.word 699
.word 349
.word 174
.word 599
.word 811
.word 405
.word 714
.word 869
.word 946
.word 473
.word 236
.word 630
.word 315
.word 157
.word 78
.word 551
.word 787
.word 905
.word 452
.word 226
.word 113
.word 568
.word 796
.word 910
.word 967
.word 995
.word 1009
.word 1016
.word 1020
.word 1022
RVTEST_CODE_END
|