-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patharm6.v
1850 lines (1652 loc) · 56 KB
/
arm6.v
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
`timescale 1 ns/1 ns
`define DEL 2
module arm6(
clk,
cpu_en,
cpu_restart,
fiq,
irq,
ram_abort,
ram_rdata,
rom_abort,
rom_data,
rst,
ram_addr,
ram_cen,
ram_flag,
ram_wdata,
ram_wen,
rom_addr,
rom_en
);
input clk;
input cpu_en;
input cpu_restart;
input fiq;
input irq;
input ram_abort;
input [31:0] ram_rdata;
input rom_abort;
input [31:0] rom_data;
input rst;
output [31:0] ram_addr;
output ram_cen;
output [3:0] ram_flag;
output [31:0] ram_wdata;
output ram_wen;
output [31:0] rom_addr;
output rom_en;
/******************************************************/
//register definition area
/******************************************************/
reg add_flag;
reg all_code;
reg [3:0] cha_num;
reg cha_vld;
reg [31:0] cmd;
reg [31:0] cmd_addr;
reg cmd_flag;
reg code_abort;
reg code_flag;
reg [31:0] code_rm;
reg [31:0] code_rma;
reg [4:0] code_rot_num;
reg [31:0] code_rs;
reg [2:0] code_rs_flag;
reg [31:0] code_rsa;
reg code_und;
reg cond_satisfy;
reg cpsr_c;
reg cpsr_f;
reg cpsr_i;
reg [4:0] cpsr_m;
reg cpsr_n;
reg cpsr_v;
reg cpsr_z;
reg [31:0] dp_ans;
reg extra_num;
reg fiq_flag;
reg [31:0] go_data;
reg [5:0] go_fmt;
reg [3:0] go_num;
reg go_vld;
reg hold_en_dly;
reg irq_flag;
reg ldm_change;
reg [3:0] ldm_num;
reg [3:0] ldm_sel;
reg ldm_usr;
reg ldm_vld;
reg multl_extra_num;
reg [31:0] r0;
reg [31:0] r1;
reg [31:0] r2;
reg [31:0] r3;
reg [31:0] r4;
reg [31:0] r5;
reg [31:0] r6;
reg [31:0] r7;
reg [31:0] r8_fiq;
reg [31:0] r8_usr;
reg [31:0] r9_fiq;
reg [31:0] r9_usr;
reg [31:0] ra_fiq;
reg [31:0] ra_usr;
reg [3:0] ram_flag;
reg [31:0] ram_wdata;
reg [31:0] rb_fiq;
reg [31:0] rb_usr;
reg [31:0] rc_fiq;
reg [31:0] rc_usr;
reg [31:0] rd;
reg [31:0] rd_abt;
reg [31:0] rd_fiq;
reg [31:0] rd_irq;
reg [31:0] rd_svc;
reg [31:0] rd_und;
reg [31:0] rd_usr;
reg [31:0] re;
reg [31:0] re_abt;
reg [31:0] re_fiq;
reg [31:0] re_irq;
reg [31:0] re_svc;
reg [31:0] re_und;
reg [31:0] re_usr;
reg [63:0] reg_ans;
reg [31:0] rf;
reg rm_msb;
reg [31:0] rn;
reg [31:0] rn_register;
reg [31:0] rna;
reg [31:0] rnb;
reg rs_msb;
reg [31:0] sec_operand;
reg [10:0] spsr;
reg [10:0] spsr_abt;
reg [10:0] spsr_fiq;
reg [10:0] spsr_irq;
reg [10:0] spsr_svc;
reg [10:0] spsr_und;
reg [4:0] sum_m;
reg [31:0] to_data;
reg [3:0] to_num;
/******************************************************/
/******************************************************/
//wire definition area
/******************************************************/
wire [31:0] and_ans;
wire [31:0] bic_ans;
wire bit_cy;
wire bit_ov;
wire cha_rf_vld;
wire cmd_is_b;
wire cmd_is_bx;
wire cmd_is_dp0;
wire cmd_is_dp1;
wire cmd_is_dp2;
wire cmd_is_ldm;
wire cmd_is_ldr0;
wire cmd_is_ldr1;
wire cmd_is_ldrh0;
wire cmd_is_ldrh1;
wire cmd_is_ldrsb0;
wire cmd_is_ldrsb1;
wire cmd_is_ldrsh0;
wire cmd_is_ldrsh1;
wire cmd_is_mrs;
wire cmd_is_msr0;
wire cmd_is_msr1;
wire cmd_is_mult;
wire cmd_is_multl;
wire cmd_is_multlx;
wire cmd_is_swi;
wire cmd_is_swp;
wire cmd_is_swpx;
wire cmd_ok;
wire [4:0] cmd_sum_m;
wire [31:0] code;
wire code_is_b;
wire code_is_bx;
wire code_is_dp0;
wire code_is_dp1;
wire code_is_dp2;
wire code_is_ldm;
wire code_is_ldr0;
wire code_is_ldr1;
wire code_is_ldrh0;
wire code_is_ldrh1;
wire code_is_ldrsb0;
wire code_is_ldrsb1;
wire code_is_ldrsh0;
wire code_is_ldrsh1;
wire code_is_mrs;
wire code_is_msr0;
wire code_is_msr1;
wire code_is_mult;
wire code_is_multl;
wire code_is_swi;
wire code_is_swp;
wire [3:0] code_rm_num;
wire code_rm_vld;
wire [3:0] code_rn_num;
wire code_rn_vld;
wire [3:0] code_rnhi_num;
wire code_rnhi_vld;
wire [3:0] code_rs_num;
wire code_rs_vld;
wire [4:0] code_sum_m;
wire [10:0] cpsr;
wire [1:0] cy_high_bits;
wire [31:0] eor_ans;
wire fiq_en;
wire go_rf_vld;
wire high_bit;
wire hold_en;
wire hold_en_rising;
wire int_all;
wire irq_en;
wire [31:0] ldm_data;
wire ldm_rf_vld;
wire [63:0] mult_ans;
wire [31:0] or_ans;
wire [31:0] r8;
wire [31:0] r9;
wire [31:0] ra;
wire [31:0] ram_addr;
wire ram_cen;
wire ram_wen;
wire [31:0] rb;
wire [31:0] rc;
wire [31:0] rf_b;
wire [31:0] rom_addr;
wire rom_en;
wire [31:0] sum_middle;
wire [31:0] sum_rn_rm;
wire to_rf_vld;
wire to_vld;
wire wait_en;
/******************************************************/
/******************************************************/
//wire statement area
/******************************************************/
assign and_ans = rn & sec_operand;
assign bic_ans = rn & ~sec_operand;
assign bit_cy = cy_high_bits[1];
assign bit_ov = bit_cy ^ sum_middle[31];
assign cha_rf_vld = cha_vld & ( cha_num==4'hf );
assign cmd_is_b = ( cmd[27:25]==3'b101 );
assign cmd_is_bx = ( {cmd[27:23],cmd[20],cmd[7],cmd[4]}==8'b00010001 );
assign cmd_is_dp0 = ( cmd[27:25]==3'b0 ) & ~cmd[4] & ( ( cmd[24:23]!=2'b10 ) | cmd[20] );
assign cmd_is_dp1 = (cmd[27:25]==3'b0 ) & ~cmd[7] & cmd[4] & ( ( cmd[24:23]!=2'b10 ) | cmd[20] );
assign cmd_is_dp2 = ( cmd[27:25]==3'b001 ) & ( ( cmd[24:23]!=2'b10 ) | cmd[20] );
assign cmd_is_ldm = ( cmd[27:25]==3'b100 );
assign cmd_is_ldr0 = ( cmd[27:25]==3'b010 );
assign cmd_is_ldr1 = ( cmd[27:25]==3'b011 );
assign cmd_is_ldrh0 = (cmd[27:25]==3'b0 ) & ( cmd[7:4]==4'b1011 ) & ~cmd[22];
assign cmd_is_ldrh1 = (cmd[27:25]==3'b0 ) & ( cmd[7:4]==4'b1011 ) & cmd[22];
assign cmd_is_ldrsb0 = (cmd[27:25]==3'b0 ) & ( cmd[7:4]==4'b1101 ) & ~cmd[22];
assign cmd_is_ldrsb1 = (cmd[27:25]==3'b0 ) & ( cmd[7:4]==4'b1101 ) & cmd[22];
assign cmd_is_ldrsh0 = (cmd[27:25]==3'b0 ) & ( cmd[7:4]==4'b1111 ) & ~cmd[22];
assign cmd_is_ldrsh1 = (cmd[27:25]==3'b0 ) & ( cmd[7:4]==4'b1111 ) & cmd[22];
assign cmd_is_mrs = ({cmd[27:23],cmd[21:20],cmd[7],cmd[4]}==9'b000100000 );
assign cmd_is_msr0 = ({cmd[27:23],cmd[21:20],cmd[7],cmd[4]}==9'b000101000 );
assign cmd_is_msr1 = ( cmd[27:25]==3'b001 ) & ( cmd[24:23]==2'b10 ) & ~cmd[20];
assign cmd_is_mult = (cmd[27:25]==3'b0 ) & ( cmd[7:4]==4'b1001 ) & ( cmd[24:23]==2'b00 );
assign cmd_is_multl = (cmd[27:25]==3'b0 ) & ( cmd[7:4]==4'b1001 ) & ( cmd[24:23]==2'b01 );
assign cmd_is_multlx = ( cmd[27:24]==4'b1100 );
assign cmd_is_swi = ( cmd[27:25]==3'b111 );
assign cmd_is_swp = (cmd[27:25]==3'b0 ) & ( cmd[7:4]==4'b1001 ) & ( cmd[24:23]==2'b10 );
assign cmd_is_swpx = ( cmd[27:24]==4'b1101 );
assign cmd_ok = ~int_all & cmd_flag & cond_satisfy;
assign cmd_sum_m = (cmd[0]+cmd[1]+cmd[2]+cmd[3]+cmd[4]+cmd[5]+cmd[6]+cmd[7]+cmd[8]+cmd[9]+cmd[10]+cmd[11]+cmd[12]+cmd[13]+cmd[14]+cmd[15]);
assign code = rom_data;
assign code_is_b = ( code[27:25]==3'b101 );
assign code_is_bx = ( {code[27:23],code[20],code[7],code[4]}==8'b00010001 );
assign code_is_dp0 = ( code[27:25]==3'b0 ) & ~code[4] & ( ( code[24:23]!=2'b10 ) | code[20] );
assign code_is_dp1 = (code[27:25]==3'b0 ) & ~code[7] & code[4] & ( ( code[24:23]!=2'b10 ) | code[20] );
assign code_is_dp2 = ( code[27:25]==3'b001 ) & ( ( code[24:23]!=2'b10 ) | code[20] );
assign code_is_ldm = ( code[27:25]==3'b100 );
assign code_is_ldr0 = ( code[27:25]==3'b010 );
assign code_is_ldr1 = ( code[27:25]==3'b011 );
assign code_is_ldrh0 = (code[27:25]==3'b0 ) & ( code[7:4]==4'b1011 ) & ~code[22];
assign code_is_ldrh1 = (code[27:25]==3'b0 ) & ( code[7:4]==4'b1011 ) & code[22];
assign code_is_ldrsb0 = (code[27:25]==3'b0 ) & ( code[7:4]==4'b1101 ) & ~code[22];
assign code_is_ldrsb1 = (code[27:25]==3'b0 ) & ( code[7:4]==4'b1101 ) & code[22];
assign code_is_ldrsh0 = (code[27:25]==3'b0 ) & ( code[7:4]==4'b1111 ) & ~code[22];
assign code_is_ldrsh1 = (code[27:25]==3'b0 ) & ( code[7:4]==4'b1111 ) & code[22];
assign code_is_mrs = ({code[27:23],code[21:20],code[7],code[4]}==9'b000100000 );
assign code_is_msr0 = ({code[27:23],code[21:20],code[7],code[4]}==9'b000101000 );
assign code_is_msr1 = ( code[27:25]==3'b001 ) & ( code[24:23]==2'b10 ) & ~code[20];
assign code_is_mult = (code[27:25]==3'b0 ) & ( code[7:4]==4'b1001 ) & ( code[24:23]==2'b00 );
assign code_is_multl = (code[27:25]==3'b0 ) & ( code[7:4]==4'b1001 ) & ( code[24:23]==2'b01 );
assign code_is_swi = ( code[27:25]==3'b111 );
assign code_is_swp = (code[27:25]==3'b0 ) & ( code[7:4]==4'b1001 ) & ( code[24:23]==2'b10 );
assign code_rm_num = code[3:0];
assign code_rm_vld = code_flag & ( code_is_msr0|code_is_dp0|code_is_bx|code_is_dp1|code_is_mult|code_is_multl|code_is_swp|code_is_ldrh0|code_is_ldrsb0|code_is_ldrsh0|code_is_ldr1 );
assign code_rn_num = code[19:16];
assign code_rn_vld = code_flag & ( code_is_dp0|code_is_dp1|code_is_multl|code_is_swp|code_is_ldrh0|code_is_ldrh1|code_is_ldrsb0|code_is_ldrsb1|code_is_ldrsh0|code_is_ldrsh1|code_is_dp2|code_is_ldr0|code_is_ldr1|code_is_ldm );
assign code_rnhi_num = code[15:12];
assign code_rnhi_vld = code_flag & ( code_is_mult|code_is_multl|((code_is_ldrh0|code_is_ldrh1|code_is_ldr0|code_is_ldr1)& ~code[20]) );
assign code_rs_num = code[11:8];
assign code_rs_vld = code_flag & ( code_is_dp1|code_is_mult|code_is_multl );
assign code_sum_m = (code[0]+code[1]+code[2]+code[3]+code[4]+code[5]+code[6]+code[7]+code[8]+code[9]+code[10]+code[11]+code[12]+code[13]+code[14]+code[15]);
assign cpsr = { cpsr_n,cpsr_z,cpsr_c,cpsr_v,cpsr_i,cpsr_f,cpsr_m};
assign cy_high_bits = add_flag ? ( rn[31] + sec_operand[31] + sum_middle[31] ) : ( rn[31] - sec_operand[31] - sum_middle[31] );
assign eor_ans = rn ^ sec_operand;
assign fiq_en = fiq_flag & cmd_flag & ~cpsr_f;
assign go_rf_vld = go_vld & (go_num==4'hf);
assign high_bit = cy_high_bits[0];
assign hold_en = cmd_ok & ( cmd_is_swp | cmd_is_multl | ( cmd_is_ldm & (cmd_sum_m !=5'b0) ) );
assign hold_en_rising = hold_en & ~hold_en_dly;
assign int_all = cpu_restart|ram_abort|fiq_en|irq_en|( cmd_flag & ( code_abort|code_und|(cond_satisfy & cmd_is_swi)));
assign irq_en = irq_flag & cmd_flag & ~cpsr_i;
assign ldm_data = go_data;
assign ldm_rf_vld = (ldm_vld & ( ldm_num==4'hf ))|((cmd_ok & cmd_is_ldm & cmd[20])&(ldm_sel==4'hf)) ;
assign mult_ans = code_rm * code_rs;
assign or_ans = rn | sec_operand;
assign r8 = (cpsr_m==5'b10001) ? r8_fiq : r8_usr;
assign r9 = (cpsr_m==5'b10001) ? r9_fiq : r9_usr;
assign ra = (cpsr_m==5'b10001) ? ra_fiq : ra_usr;
assign ram_addr = {cmd_addr[31:2],2'b0};
assign ram_cen = cpu_en & cmd_ok & (cmd_is_ldrh0|cmd_is_ldrh1|cmd_is_ldrsb0|cmd_is_ldrsb1|cmd_is_ldrsh0|cmd_is_ldrsh1|cmd_is_ldr0|cmd_is_ldr1|cmd_is_swp|cmd_is_swpx|(cmd_is_ldm &(cmd_sum_m!=5'b0)));
assign ram_wen = cmd_is_swp ? 1'b0 : ~cmd[20];
assign rb = (cpsr_m==5'b10001) ? rb_fiq : rb_usr;
assign rc = (cpsr_m==5'b10001) ? rc_fiq : rc_usr;
assign rf_b = rf - 3'd4;
assign rom_addr = rf;
assign rom_en = cpu_en & ( ~(int_all | to_rf_vld | cha_rf_vld | go_rf_vld | wait_en | hold_en ) );
assign sum_middle = add_flag ? ( rn[30:0] + sec_operand[30:0] + extra_num ) : ( rn[30:0] - sec_operand[30:0] - extra_num );
assign sum_rn_rm = {high_bit,sum_middle[30:0]};
assign to_rf_vld = cmd_ok & ( ( (cmd[15:12]==4'hf) & ( (cmd_is_dp0|cmd_is_dp1|cmd_is_dp2) & ( cmd[24:23]!=2'b10 ) ) ) | ( cmd_is_b | cmd_is_bx ) );
assign to_vld = cmd_ok & ( cmd_is_mrs|((cmd_is_dp0|cmd_is_dp1|cmd_is_dp2)&(cmd[24:23]!=2'b10))|cmd_is_mult|cmd_is_multl|cmd_is_multlx|((cmd_is_ldrh0|cmd_is_ldrh1|cmd_is_ldrsb0|cmd_is_ldrsb1|cmd_is_ldrsh0|cmd_is_ldrsh1|cmd_is_ldr0|cmd_is_ldr1)&( cmd[21]| ~cmd[24]))|(cmd_is_ldm &(cmd_sum_m==5'b0)&cmd[21]) );
assign wait_en = (code_rm_vld &cha_vld &(cha_num==code_rm_num))|(code_rm_vld & to_vld & (to_num==code_rm_num))|(code_rm_vld & go_vld &(go_num==code_rm_num)) | (code_rs_vld & cha_vld & (cha_num==code_rs_num))|(code_rs_vld & to_vld & (to_num==code_rs_num))|(code_rs_vld & go_vld & (go_num==code_rs_num)) | (code_rn_vld&cha_vld&(code_rn_num==cha_num)) | (code_rnhi_vld&cha_vld&(code_rnhi_num==cha_num)) | (code_rm_vld & (ldm_vld & ~hold_en) & (ldm_num==code_rm_num) ) | (code_rs_vld & (ldm_vld & ~hold_en) & (ldm_num==code_rs_num) );
/******************************************************/
//register statement area
/******************************************************/
always @ ( * )
if ( cmd_is_mult|cmd_is_b|cmd_is_bx )
add_flag = 1'b1;
else if ( cmd_is_multl|cmd_is_multlx )
add_flag = cmd[22] ? ~( rm_msb^rs_msb ) : 1'b1;
else if ( cmd_is_dp0|cmd_is_dp1|cmd_is_dp2 )
add_flag = (cmd[24:21]==4'b0100)|(cmd[24:21]==4'b0101)|(cmd[24:21]==4'b1011)|(cmd[24:21]==4'b1101);
else
add_flag = cmd[23];
always @ ( * )
if ( code[27:25]==3'b0 )
if ( ~code[4] )
if ( ( code[24:23]==2'b10 ) & ~code[20] )
if ( ~code[21] )
all_code = ( code[19:16]==4'hf ) & ( code[11:0] == 12'b0 );
else
all_code = ( code[18:17] == 2'b0 ) & ( code[15:12]==4'hf ) & ( code[11:4]==8'h0 );
else
all_code = ( code[24:23]!=2'b10 ) | code[20];
else if ( ~code[7] )
if ( code[24:20]==5'b10010 )
all_code = ( code[19:4]==16'hfff1 );
else
all_code = ( code[24:23]!=2'b10 ) | code[20];
else if ( code[6:5]==2'b0 )
if ( code[24:22]==3'b0 )
all_code = 1'b1;
else if ( code[24:23]==2'b01 )
all_code = 1'b1;
else if ( code[24:23]==2'b10 )
all_code = ( code[21:20]==2'b0 ) & ( code[11:8]==4'b0 );
else
all_code = 1'b0;
else if ( code[6:5]==2'b01 )
if ( ~code[22] )
all_code = ( code[11:8]==4'b0 );
else
all_code = 1'b1;
else //if ( ( code[6:5]==2'b10 )|(code[6:5]==2'b11) )
if ( code[20] )
if ( ~code[22] )
all_code = ( code[11:8]==4'b0 );
else
all_code = 1'b1;
else
all_code = 1'b0;
else if ( code[27:25]==3'b001 )
if ( (code[24:23]==2'b10) & ~code[20] )
all_code = code[21] & ( code[18:17]==2'b0 ) & ( code[15:12]==4'hf );
else
all_code = ( code[24:23]!=2'b10 ) | code[20];
else if ( code[27:25]==3'b010 )
all_code = 1'b1;
else if ( code[27:25]==3'b011 )
all_code = ~code[4];
else if ( code[27:25]==3'b100 )
all_code = 1'b1;
else if ( code[27:25]==3'b101 )
all_code = 1'b1;
else if ( code[27:25]==3'b111 )
all_code = code[24];
else
all_code = 1'b0;
always @ ( * )
cha_num = cmd[15:12];
always @ ( * )
if ( cmd_ok )
cha_vld = (( cmd_is_ldrh0|cmd_is_ldrh1|cmd_is_ldrsb0|cmd_is_ldrsb1|cmd_is_ldrsh0|cmd_is_ldrsh1|cmd_is_ldr0|cmd_is_ldr1 ) & cmd[20])|cmd_is_swp;
else
cha_vld = 0;
always @ ( posedge clk or posedge rst )
if ( rst )
cmd <= #`DEL 32'd0;
else if ( cpu_en )
if ( ~hold_en )
cmd <= #`DEL code;
else if ( cmd_is_swp ) begin
cmd[27:25] <= #`DEL 3'b110;
cmd[15:12] <= #`DEL cmd[3:0];
end
else if ( cmd_is_multl )
cmd[27:25] <= #`DEL 3'b110;
else if ( cmd_is_ldm ) begin
cmd[0] <= #`DEL 1'b0;
cmd[1] <= #`DEL cmd[0] ? cmd[1] : 1'b0;
cmd[2] <= #`DEL (|(cmd[1:0])) ? cmd[2] : 1'b0;
cmd[3] <= #`DEL (|(cmd[2:0])) ? cmd[3] : 1'b0;
cmd[4] <= #`DEL (|(cmd[3:0])) ? cmd[4] : 1'b0;
cmd[5] <= #`DEL (|(cmd[4:0])) ? cmd[5] : 1'b0;
cmd[6] <= #`DEL (|(cmd[5:0])) ? cmd[6] : 1'b0;
cmd[7] <= #`DEL (|(cmd[6:0])) ? cmd[7] : 1'b0;
cmd[8] <= #`DEL (|(cmd[7:0])) ? cmd[8] : 1'b0;
cmd[9] <= #`DEL (|(cmd[8:0])) ? cmd[9] : 1'b0;
cmd[10] <= #`DEL (|(cmd[9:0])) ? cmd[10] : 1'b0;
cmd[11] <= #`DEL (|(cmd[10:0])) ? cmd[11] : 1'b0;
cmd[12] <= #`DEL (|(cmd[11:0])) ? cmd[12] : 1'b0;
cmd[13] <= #`DEL (|(cmd[12:0])) ? cmd[13] : 1'b0;
cmd[14] <= #`DEL (|(cmd[13:0])) ? cmd[14] : 1'b0;
cmd[15] <= #`DEL (|(cmd[14:0])) ? cmd[15] : 1'b0;
end
else;
else;
always @ ( * )
if ( cmd_is_ldm )
cmd_addr = sum_rn_rm;
else if ( cmd_is_swp|cmd_is_swpx )
cmd_addr = rn;
else if ( cmd[24] )
cmd_addr = sum_rn_rm;
else
cmd_addr = rn;
always @ ( posedge clk or posedge rst )
if ( rst )
cmd_flag <= #`DEL 1'd0;
else if ( cpu_en )
if ( int_all )
cmd_flag <= #`DEL 0;
else if ( ~hold_en )
if ( wait_en | to_rf_vld | cha_rf_vld | go_rf_vld )
cmd_flag <= #`DEL 0;
else
cmd_flag <= #`DEL code_flag;
else;
else;
always @ ( posedge clk or posedge rst )
if ( rst )
code_abort <= #`DEL 1'd0;
else if ( cpu_en )
if ( ~hold_en )
code_abort <= #`DEL rom_abort;
else;
else;
always @ ( posedge clk or posedge rst )
if ( rst )
code_flag <= #`DEL 1'd0;
else if ( cpu_en )
if ( int_all | to_rf_vld | cha_rf_vld | go_rf_vld | ldm_rf_vld )
code_flag <= #`DEL 0;
else
code_flag <= #`DEL 1;
else;
always @ ( * )
if ( code_is_ldrh1|code_is_ldrsb1|code_is_ldrsh1 )
code_rm = {code[11:8],code[3:0]};
else if ( code_is_b )
code_rm = {{6{code[23]}},code[23:0],2'b0};
else if ( code_is_ldm )
case( code[24:23] )
2'd0 : code_rm = {(code_sum_m - 1'b1),2'b0};
2'd1 : code_rm = 0;
2'd2 : code_rm = {code_sum_m,2'b0};
2'd3 : code_rm = 3'b100;
endcase
else if ( code_is_ldr0 )
code_rm = code[11:0];
else if ( code_is_msr1|code_is_dp2 )
code_rm = code[7:0];
else if ( code_is_multl & code[22] & code_rma[31] )
code_rm = ~code_rma + 1'b1;
else if ( ( (code[6:5]==2'b10) & code_rma[31] ) & (code_is_dp0|code_is_dp1|code_is_ldr1) )
code_rm = ~code_rma;
else
code_rm = code_rma;
always @ ( * )
case ( code[3:0] )
4'h0 : code_rma = r0;
4'h1 : code_rma = r1;
4'h2 : code_rma = r2;
4'h3 : code_rma = r3;
4'h4 : code_rma = r4;
4'h5 : code_rma = r5;
4'h6 : code_rma = r6;
4'h7 : code_rma = r7;
4'h8 : code_rma = r8;
4'h9 : code_rma = r9;
4'ha : code_rma = ra;
4'hb : code_rma = rb;
4'hc : code_rma = rc;
4'hd : code_rma = rd;
4'he : code_rma = re;
4'hf : code_rma = (rf+3'b100);
endcase
always @ ( * )
if ( code_is_dp0|code_is_ldr1 )
code_rot_num = ( code[6:5] == 2'b00 ) ? code[11:7] : ( ~code[11:7]+1'b1 );
else if ( code_is_dp1 )
code_rot_num = ( code[6:5] == 2'b00 ) ? code_rsa[4:0] : ( ~code_rsa[4:0]+1'b1 );
else if ( code_is_msr1|code_is_dp2 )
code_rot_num = { (~code[11:8]+1'b1),1'b0 };
else
code_rot_num = 5'b0;
always @ ( * )
if ( code_is_multl )
if ( code[22] & code_rsa[31] )
code_rs = ~code_rsa + 1'b1;
else
code_rs = code_rsa;
else if ( code_is_mult )
code_rs = code_rsa;
else begin
code_rs = 32'b0;
code_rs[code_rot_num] = 1'b1;
end
always @ ( posedge clk or posedge rst )
if ( rst )
code_rs_flag <= #`DEL 3'd0;
else if ( cpu_en )
if ( ~hold_en )
if ( code_is_dp1 )
code_rs_flag <= #`DEL {(code_rsa[7:0]>6'd32),(code_rsa[7:0]==6'd32),(code_rsa[7:0]==8'd0)};
else
code_rs_flag <= #`DEL 0;
else;
else;
always @ ( * )
case ( code[11:8] )
4'h0 : code_rsa = r0;
4'h1 : code_rsa = r1;
4'h2 : code_rsa = r2;
4'h3 : code_rsa = r3;
4'h4 : code_rsa = r4;
4'h5 : code_rsa = r5;
4'h6 : code_rsa = r6;
4'h7 : code_rsa = r7;
4'h8 : code_rsa = r8;
4'h9 : code_rsa = r9;
4'ha : code_rsa = ra;
4'hb : code_rsa = rb;
4'hc : code_rsa = rc;
4'hd : code_rsa = rd;
4'he : code_rsa = re;
4'hf : code_rsa = (rf+3'b100);
endcase
always @ ( posedge clk or posedge rst )
if ( rst )
code_und <= #`DEL 1'd0;
else if ( cpu_en )
if ( ~hold_en )
code_und <= #`DEL ~all_code;
else;
else;
always @ ( * )
case ( cmd[31:28] )
4'h0 : cond_satisfy = ( cpsr_z==1'b1 );
4'h1 : cond_satisfy = ( cpsr_z==1'b0 );
4'h2 : cond_satisfy = ( cpsr_c==1'b1 );
4'h3 : cond_satisfy = ( cpsr_c==1'b0 );
4'h4 : cond_satisfy = ( cpsr_n==1'b1 );
4'h5 : cond_satisfy = ( cpsr_n==1'b0 );
4'h6 : cond_satisfy = ( cpsr_v==1'b1 );
4'h7 : cond_satisfy = ( cpsr_v==1'b0 );
4'h8 : cond_satisfy = ( cpsr_c==1'b1 )&(cpsr_z==1'b0);
4'h9 : cond_satisfy = ( cpsr_c==1'b0 )|(cpsr_z==1'b1);
4'ha : cond_satisfy = ( cpsr_n==cpsr_v);
4'hb : cond_satisfy = ( cpsr_n!=cpsr_v);
4'hc : cond_satisfy = ( cpsr_z==1'b0)&(cpsr_n==cpsr_v);
4'hd : cond_satisfy = ( cpsr_z==1'b1)|(cpsr_n!=cpsr_v);
4'he : cond_satisfy = 1'b1;
4'hf : cond_satisfy = 1'b0;
endcase
always @ ( posedge clk or posedge rst )
if ( rst )
cpsr_c <= #`DEL 1'd0;
else if ( cpu_en )
if ( cmd_ok )
if ( cmd_is_msr0|cmd_is_msr1 )
if ( ~cmd[22] & cmd[19] )
cpsr_c <= #`DEL sec_operand[29];
else;
else if ( cmd_is_dp0|cmd_is_dp1|cmd_is_dp2 )
if ( cmd[20] )
if ( cmd[15:12]==4'hf )
cpsr_c <= #`DEL spsr[8];
else if ( (cmd[24:21]==4'b1011)|(cmd[24:21]==4'b0100)|(cmd[24:21]==4'b0101)|(cmd[24:21]==4'b0011)|(cmd[24:21]==4'b0111) )
cpsr_c <= #`DEL bit_cy;
else if ( (cmd[24:21]==4'b1010)|(cmd[24:21]==4'b0010)|(cmd[24:21]==4'b0110) )
cpsr_c <= #`DEL ~bit_cy;
else if ( cmd_is_dp1 & ~code_rs_flag[0] )
case ( cmd[6:5] )
2'b00 : cpsr_c <= #`DEL code_rs_flag[2]? 1'b0 : ( code_rs_flag[1]? reg_ans[0] : reg_ans[32] );
2'b01 : cpsr_c <= #`DEL code_rs_flag[2]? 1'b0 : ( code_rs_flag[1]? reg_ans[31] : reg_ans[31] );
2'b10 : cpsr_c <= #`DEL code_rs_flag[2]? rm_msb : ( code_rs_flag[1]? rm_msb : ( rm_msb ? ~reg_ans[31]: reg_ans[31]) );
2'b11 : cpsr_c <= #`DEL code_rs_flag[1]? cpsr_c : reg_ans[31];
endcase
else if ( cmd_is_dp2 )
cpsr_c <= #`DEL reg_ans[31];
else if ( cmd_is_dp0 )
case ( cmd[6:5] )
2'b00 : cpsr_c <= #`DEL (cmd[11:7]==5'b0) ? cpsr_c : reg_ans[32];
2'b01 : cpsr_c <= #`DEL reg_ans[31];
2'b10 : cpsr_c <= #`DEL ( rm_msb ? ~reg_ans[31]: reg_ans[31]);
2'b11 : cpsr_c <= #`DEL (cmd[11:7]==5'b0) ? reg_ans[0]:reg_ans[31];
endcase
else;
else;
else if ( cmd_is_ldm & ( cmd_sum_m==5'b0 ) & ldm_change )
cpsr_c <= #`DEL spsr[8];
else;
else;
else;
always @ ( posedge clk or posedge rst )
if ( rst )
cpsr_f <= #`DEL 1'd0;
else if ( cpu_en )
if ( cpu_restart | fiq_en )
cpsr_f <= #`DEL 1;
else if ( cmd_ok & ( cpsr_m != 5'b10000 ) )
if ( cmd_is_msr0|cmd_is_msr1 )
if ( ~cmd[22] & cmd[16] )
cpsr_f <= #`DEL sec_operand[6];
else;
else if ( cmd_is_dp0|cmd_is_dp1|cmd_is_dp2 )
if ( cmd[20] )
if ( cmd[15:12]==4'hf )
cpsr_f <= #`DEL spsr[5];
else;
else;
else if ( cmd_is_ldm & ( cmd_sum_m==5'b0 ) & ldm_change )
cpsr_f <= #`DEL spsr[5];
else;
else;
else;
always @ ( posedge clk or posedge rst )
if ( rst )
cpsr_i <= #`DEL 1'd0;
else if ( cpu_en )
if ( int_all )
cpsr_i <= #`DEL 1;
else if ( cmd_ok & ( cpsr_m != 5'b10000 ) )
if ( cmd_is_msr0|cmd_is_msr1 )
if ( ~cmd[22] & cmd[16] )
cpsr_i <= #`DEL sec_operand[7];
else;
else if ( cmd_is_dp0|cmd_is_dp1|cmd_is_dp2 )
if ( cmd[20] )
if ( cmd[15:12]==4'hf )
cpsr_i <= #`DEL spsr[6];
else;
else;
else if ( cmd_is_ldm & ( cmd_sum_m==5'b0 ) & ldm_change )
cpsr_i <= #`DEL spsr[6];
else;
else;
else;
always @ ( posedge clk or posedge rst )
if ( rst )
cpsr_m <= #`DEL 5'b10011;
else if ( cpu_en )
if ( cpu_restart )
cpsr_m <= #`DEL 5'b10011;
else if ( fiq_en )
cpsr_m <= #`DEL 5'b10001;
else if ( ram_abort )
cpsr_m <= #`DEL 5'b10111;
else if ( irq_en )
cpsr_m <= #`DEL 5'b10010;
else if ( cmd_flag & code_abort )
cpsr_m <= #`DEL 5'b10111;
else if ( cmd_flag & code_und )
cpsr_m <= #`DEL 5'b11011;
else if ( cmd_flag & cond_satisfy & cmd_is_swi )
cpsr_m <= #`DEL 5'b10011;
else if ( cmd_ok & ( cpsr_m != 5'b10000 ) )
if ( cmd_is_msr0|cmd_is_msr1 )
if ( ~cmd[22] & cmd[16] )
cpsr_m <= #`DEL sec_operand[4:0];
else;
else if ( cmd_is_dp0|cmd_is_dp1|cmd_is_dp2 )
if ( cmd[20] )
if ( cmd[15:12]==4'hf )
cpsr_m <= #`DEL spsr[4:0];
else;
else;
else if ( cmd_is_ldm & ( cmd_sum_m==5'b0 ) & ldm_change )
cpsr_m <= #`DEL spsr[4:0];
else;
else;
else;
always @ ( posedge clk or posedge rst )
if ( rst )
cpsr_n <= #`DEL 1'd0;
else if ( cpu_en )
if ( cmd_ok )
if ( cmd_is_msr0|cmd_is_msr1 )
if ( ~cmd[22] & cmd[19] )
cpsr_n <= #`DEL sec_operand[31];
else;
else if ( cmd_is_dp0|cmd_is_dp1|cmd_is_dp2 )
if ( cmd[20] )
if ( cmd[15:12]==4'hf )
cpsr_n <= #`DEL spsr[10];
else
cpsr_n <= #`DEL dp_ans[31];
else;
else if ( cmd_is_mult|cmd_is_multlx )
if ( cmd[20] )
cpsr_n <= #`DEL sum_rn_rm[31];
else;
else if ( cmd_is_ldm & ( cmd_sum_m==5'b0 ) & ldm_change )
cpsr_n <= #`DEL spsr[10];
else;
else;
else;
always @ ( posedge clk or posedge rst )
if ( rst )
cpsr_v <= #`DEL 1'd0;
else if ( cpu_en )
if ( cmd_ok )
if ( cmd_is_msr0|cmd_is_msr1 )
if ( ~cmd[22] & cmd[19] )
cpsr_v <= #`DEL sec_operand[28];
else;
else if ( cmd_is_dp0|cmd_is_dp1|cmd_is_dp2 )
if ( cmd[20] )
if ( cmd[15:12]==4'hf )
cpsr_v <= #`DEL spsr[7];
else if ( (cmd[24:21]==4'd2)|(cmd[24:21]==4'd3)|(cmd[24:21]==4'd4)|(cmd[24:21]==4'd5)|(cmd[24:21]==4'd6)|(cmd[24:21]==4'd7)|(cmd[24:21]==4'd10)|(cmd[24:21]==4'd11) )
cpsr_v <= #`DEL bit_ov;
else;
else;
else if ( cmd_is_ldm & ( cmd_sum_m==5'b0 ) & ldm_change )
cpsr_v <= #`DEL spsr[7];
else;
else;
else;
always @ ( posedge clk or posedge rst )
if ( rst )
cpsr_z <= #`DEL 1'd0;
else if ( cpu_en )
if ( cmd_ok )
if ( cmd_is_msr0|cmd_is_msr1 )
if ( ~cmd[22] & cmd[19] )
cpsr_z <= #`DEL sec_operand[30];
else;
else if ( cmd_is_dp0|cmd_is_dp1|cmd_is_dp2 )
if ( cmd[20] )
if ( cmd[15:12]==4'hf )
cpsr_z <= #`DEL spsr[9];
else
cpsr_z <= #`DEL (dp_ans==32'b0);
else;
else if ( cmd_is_mult|cmd_is_multl )
if ( cmd[20] )
cpsr_z <= #`DEL (sum_rn_rm==32'b0);
else;
else if ( cmd_is_multlx & cmd[20] )
cpsr_z <= #`DEL cpsr_z & (sum_rn_rm==32'b0);
else if ( cmd_is_ldm & ( cmd_sum_m==5'b0 ) & ldm_change )
cpsr_z <= #`DEL spsr[9];
else;
else;
else;
always @ ( * )
case ( cmd[24:21] )
4'h0 : dp_ans = and_ans;
4'h1 : dp_ans = eor_ans;
4'h2 : dp_ans = sum_rn_rm;
4'h3 : dp_ans = ~sum_rn_rm;
4'h4 : dp_ans = sum_rn_rm;
4'h5 : dp_ans = sum_rn_rm;
4'h6 : dp_ans = sum_rn_rm;
4'h7 : dp_ans = ~sum_rn_rm;
4'h8 : dp_ans = and_ans;
4'h9 : dp_ans = eor_ans;
4'ha : dp_ans = sum_rn_rm;
4'hb : dp_ans = sum_rn_rm;
4'hc : dp_ans = or_ans;
4'hd : dp_ans = sum_rn_rm;
4'he : dp_ans = bic_ans;
4'hf : dp_ans = sum_rn_rm;
endcase
always @ ( * )
if ( cmd_is_mult | cmd_is_multl )
extra_num = 1'b0;
else if ( cmd_is_dp0|cmd_is_dp1|cmd_is_dp2 )
case ( cmd[24:21])
4'b0010 : extra_num = 1'b0;
4'b0011 : extra_num = 1'b1;
4'b0100 : extra_num = 1'b0;
4'b0101 : extra_num = cpsr_c;
4'b0110 : extra_num = ~cpsr_c;
4'b0111 : extra_num = cpsr_c;
4'b1111 : extra_num = 1'b1;
default: extra_num = 1'b0;
endcase
else if ( cmd_is_multlx )
extra_num = multl_extra_num;
else
extra_num = 1'b0;
always @ ( posedge clk or posedge rst )
if ( rst )
fiq_flag <= #`DEL 1'b0;
else if ( cpu_en )
if ( fiq )
fiq_flag <= #`DEL 1'b1;
else if ( cmd_flag )
fiq_flag <= #`DEL 1'b0;
else;
else;
always @ ( * )
if ( go_fmt[5] )
go_data = ram_rdata;
else if ( go_fmt[4] )
if ( go_fmt[1] )
go_data = {{16{go_fmt[2]&ram_rdata[31]}},ram_rdata[31:16]};
else
go_data = {{16{go_fmt[2]&ram_rdata[15]}},ram_rdata[15:0]};
else// if ( cha_reg_fmt[3] )
case(go_fmt[1:0])
2'b00 : go_data = { {24{go_fmt[2]&ram_rdata[7]}}, ram_rdata[7:0] };
2'b01 : go_data = { {24{go_fmt[2]&ram_rdata[15]}}, ram_rdata[15:8] };
2'b10 : go_data = { {24{go_fmt[2]&ram_rdata[23]}}, ram_rdata[23:16] };
2'b11 : go_data = { {24{go_fmt[2]&ram_rdata[31]}}, ram_rdata[31:24] };
endcase
always @ ( posedge clk or posedge rst )
if ( rst )
go_fmt <= #`DEL 6'd0;
else if ( cpu_en )
if ( cmd_is_ldr0|cmd_is_ldr1|cmd_is_swp )
go_fmt <= #`DEL cmd[22] ?{4'b0010,cmd_addr[1:0]}: {4'b1000,cmd_addr[1:0]};
else if ( cmd_is_ldrh0|cmd_is_ldrh1 )
go_fmt <= #`DEL {4'b0100,cmd_addr[1:0]};
else if ( cmd_is_ldrsb0|cmd_is_ldrsb1 )
go_fmt <= #`DEL {4'b0011,cmd_addr[1:0]};
else if ( cmd_is_ldrsh0|cmd_is_ldrsh1 )
go_fmt <= #`DEL {4'b0101,cmd_addr[1:0]};
else if ( cmd_is_ldm )
go_fmt <= #`DEL {4'b1000,cmd_addr[1:0]};
else;
else;
always @ ( posedge clk or posedge rst )
if ( rst )
go_num <= #`DEL 4'd0;
else if ( cpu_en )
go_num <= #`DEL cha_num;
else;
always @ ( posedge clk or posedge rst )
if ( rst )
go_vld <= #`DEL 1'd0;