-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgodson_dtlb_module.v
3718 lines (3208 loc) · 151 KB
/
godson_dtlb_module.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
/*------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Copyright (c) 2016, Loongson Technology Corporation Limited.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. Neither the name of Loongson Technology Corporation Limited nor the names of
its contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL LOONGSON TECHNOLOGY CORPORATION LIMITED BE LIABLE
TO ANY PARTY FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
------------------------------------------------------------------------------*/
`include "global.h"
`include "reg.h"
`include "bus.h"
module godson_dtlb_module(
clock,
reset,
commitbus0_i,
commitbus1_i,
brbus_to_cp0_i,
int_in,
int_out,
status_bev_o,
status_exl_o,
status_erl_o,
status_ksu_o,
status_cu_o,
mode_user,
mode_super,
config_k0,
HWREna,
vector_int,
ebase,
entryhi_vpn2_o,
////// connection with itlb
itlb_req_i,
tlb_to_itlb_o,
itlb_flush_o,
////// connection with icache
cache28_refill_ok_i,
tlb_to_icache_o,
////// connection with interface
filter_window_req_i,
filter_window_result_o,
////// performance counter
imemread_valid_i,
dmemread_valid_i,
duncache_valid_i,
mreadreq_valid_i,
mwritereq_valid_i,
data_inst_conflict_i,
data_inter_conflict_i,
qissuebus_valid0_i,
qissuebus_valid1_i,
brq_full_i,
stalled_fetch_i,
missq_full_i,
not_store_ok_i,
st_ld_conflict_i,
queue_full_i,
icache_hit_i,
icache_access_i,
icache_update_i,
icache_way_hit_i,
itlb_access_i,
flush_pipeline_cycle_i,
inst_to_queue_cycle_i,
insts_to_alu1_i,
insts_to_alu2_i,
insts_to_addr_i,
insts_to_falu_i,
insts_to_queue_i,
insts_fetched_i,
stalled_cycles_icachemiss_i,
itlbmiss_tlbhit_i,
////// ejtag signals
IBE_FROM_CACHE,
HB_DDBL,
HB_DDBS,
HB_DDBSIMPR,
PROBEN_IN,
DMSEG_DFREE,
DEBUG_MODE,
DSS_ENABLE,
NODCR,
IEXI,
PENDING_DBE,
PENDING_IBE,
FIRST_MEM_PASS_AFTER_DERET,
EJTAGBRK_FROM_CORE,
HB_REQBUS,
DCR_REQBUS,
DMSEG_DREQBUS,
HB_DCOMPBUS,
addr_to_tlb_i,
inst_valid_at_addr_i,
inst_cache_at_addr_i,
inst_sync_at_addr_i,
tlb_allowin_o,
tlb_stall_o,
tlb_has_ll_o,
dcache_result_i,
tag_to_tlb_i,
conflict_to_tlb_i,
dcachepaddr_o,
tlb_read_again_o,
load_queue_full_i,
store_queue_full_i,
miss_req_queue_full_i,
ex_memqueue_i,
rand_num_i,
ll_set_llbit_i,
tlb_to_memqueue_o,
tlb_forward_bus_o,
cr_llbit_value_o,
cr_cfg6_brpred_type_o,
cr_cfg6_rti_o,
cr_cfg6_cache0_all_o,
cr_cfg7_dcache_o,
cr_cfg7_icache_o,
ram_to_tlb_i,
tlb_to_ram_o,
DRESBUS_FROM_DRSEG,
DRESBUS_FROM_DCR ,
DRESBUS_FROM_DMSEG,
HB_LOAD_ADDR_MATCH,
DATA_FROM_TAP,
hb_dbs_bs_i
);
parameter MMBUF_INVALID = 2'b00;
parameter MMBUF_VALID = 2'b01;
parameter MMBUF_READ_AGAIN = 2'b10;
////// whole system signals
input clock;
input reset;
input [`Lcommitbus_to_tlb-1:0] commitbus0_i;
input [`Lcommitbus_to_tlb-1:0] commitbus1_i;
input [ 18:0] brbus_to_cp0_i;
input [ 5:0] int_in;
output int_out;
output status_bev_o;
output status_exl_o;
output status_erl_o;
output [ 1:0] status_ksu_o;
output [ 3:0] status_cu_o;
output [ 18:0] entryhi_vpn2_o;
output mode_user;
output mode_super;
output [ 2:0] config_k0;
output [3:0 ] HWREna;
output [8:0 ] vector_int;
output [31:0] ebase;
///// connection with fetch and icache
input [`Litlb_req-1:0] itlb_req_i;
output [`Ltlb_to_itlb-1:0] tlb_to_itlb_o;
output itlb_flush_o;
input cache28_refill_ok_i;
output [`Ltlb_to_icache-1:0] tlb_to_icache_o;
////// connection with interface
input [31:0] filter_window_req_i;
output filter_window_result_o;
//////performance counter
input imemread_valid_i;
input dmemread_valid_i;
input duncache_valid_i;
input mreadreq_valid_i;
input mwritereq_valid_i;
input data_inst_conflict_i;
input data_inter_conflict_i;
input qissuebus_valid0_i;
input qissuebus_valid1_i;
input brq_full_i;
input stalled_fetch_i;
input missq_full_i;
input not_store_ok_i;
input st_ld_conflict_i;
input queue_full_i;
input icache_hit_i;
input icache_access_i;
input icache_update_i;
input icache_way_hit_i;
input itlb_access_i;
input flush_pipeline_cycle_i;
input inst_to_queue_cycle_i;
input insts_to_alu1_i;
input insts_to_alu2_i;
input insts_to_addr_i;
input insts_to_falu_i;
input[1:0] insts_to_queue_i;
input[1:0] insts_fetched_i;
input stalled_cycles_icachemiss_i;
input itlbmiss_tlbhit_i;
////// ejtag signals
input IBE_FROM_CACHE;
input HB_DDBL;
input HB_DDBS;
input HB_DDBSIMPR;
input PROBEN_IN;
input DMSEG_DFREE;
output DEBUG_MODE;
output DSS_ENABLE;
output NODCR;
output IEXI;
output PENDING_DBE;
output PENDING_IBE;
output FIRST_MEM_PASS_AFTER_DERET;
output EJTAGBRK_FROM_CORE;
output [ 78:0] HB_REQBUS;
output [ 78:0] DCR_REQBUS;
output [ 78:0] DMSEG_DREQBUS;
output [`Lhb_dcompbus-1:0] HB_DCOMPBUS;
input [ 64:0] DRESBUS_FROM_DRSEG;
input [ 64:0] DRESBUS_FROM_DCR ;
input [ 64:0] DRESBUS_FROM_DMSEG;
input [ 1:0] HB_LOAD_ADDR_MATCH;
input [`DBKP_NUM-1:0] hb_dbs_bs_i;
////// connect with addr module
input [`Laddr_to_tlb-1:0] addr_to_tlb_i;
input inst_valid_at_addr_i;
input inst_cache_at_addr_i;
input inst_sync_at_addr_i;
output tlb_allowin_o;
output tlb_stall_o;
output tlb_has_ll_o;
////// connect with dcache module
input [`Ldcache_result-1:0] dcache_result_i;
input [ 31:0] tag_to_tlb_i;
input conflict_to_tlb_i;
output [ 31:0] dcachepaddr_o;
output [`Ltlb_read_again-1:0] tlb_read_again_o;
////// connect with memqueue module
input load_queue_full_i;
input store_queue_full_i;
input miss_req_queue_full_i;
input ex_memqueue_i;
input [ 2:0] rand_num_i;
input ll_set_llbit_i;
output [`Ltlb_to_memq-1:0] tlb_to_memqueue_o;
output [`Ltlb_forward-1:0] tlb_forward_bus_o;
output cr_llbit_value_o;
output [2:0] cr_cfg6_brpred_type_o;
output cr_cfg6_rti_o;
output cr_cfg6_cache0_all_o;
output [1:0] cr_cfg7_dcache_o;
output [1:0] cr_cfg7_icache_o;
////// RAM access interface
input [`Lram_to_tlb-1:0] ram_to_tlb_i;
output [`Ltlb_to_ram-1:0] tlb_to_ram_o;
////input form tap buffer
input[32:0] DATA_FROM_TAP;
////// all fields of brbus_to_cp0_i
wire brbus_brerr = brbus_to_cp0_i[ 0];
wire [ 5:0] brbus_brmask = brbus_to_cp0_i[6:1];
wire brbus_valid = brbus_to_cp0_i[ 7];
wire [ 7:0] brbus_op = brbus_to_cp0_i[15:8];
wire brbus_jr31 = brbus_to_cp0_i[ 16];
wire brbus_bht = brbus_to_cp0_i[ 17];
wire brbus_static_br = brbus_to_cp0_i[ 18];
wire mmbuf_brbus_cancel;
wire addr_brbus_cancel;
////// all fields of tlb_forward_bus_o
wire fpq_forward;
wire valid_forward;
wire [ 3:0] qid_forward;
wire [ 2:0] fpqid_forward;
assign tlb_forward_bus_o[8] = fpq_forward;
assign tlb_forward_bus_o[7:5] = fpqid_forward;
assign tlb_forward_bus_o[4 ] = valid_forward;
assign tlb_forward_bus_o[3:0] = qid_forward;
////// all fields of itlb_req_i bus
wire itlb_lookup_req = itlb_req_i[32 ];
wire [31:0] itlb_lookup_pc = itlb_req_i[31:0];
////// all fields of tlb_to_itlb_o bus
wire tlb_valid_to_itlb;
wire tlb_find_to_itlb;
wire [ 7:0] asid_to_itlb;
wire [ 1:0] random_index_to_itlb;
wire [15:0] tlb_pagemask_to_itlb;
wire [ 7:0] tlb_asid_to_itlb;
wire tlb_g_to_itlb;
assign tlb_to_itlb_o[36] = tlb_valid_to_itlb;
assign tlb_to_itlb_o[35] = tlb_find_to_itlb;
assign tlb_to_itlb_o[34:27] = asid_to_itlb;
assign tlb_to_itlb_o[26:25] = random_index_to_itlb;
assign tlb_to_itlb_o[24:9] = tlb_pagemask_to_itlb;
assign tlb_to_itlb_o[8:1] = tlb_asid_to_itlb;
assign tlb_to_itlb_o[0] = tlb_g_to_itlb;
////// all fields of tlb_to_icache_o
wire vaddr_cache28_icache;
wire cache28_icache;
wire vaddr_cache16_icache;
wire vaddr_valid_icache;
wire [ 6:0] vaddr_index_icache;
wire [31:0] taglow_icache;
wire valid_icache;
wire [31:0] paddr_icache;
wire cache16_icache;
wire cache8_icache;
wire cache0_icache;
wire [ 1:0] set_icache;
assign tlb_to_icache_o[81:80] = set_icache;
assign tlb_to_icache_o[79 ] = vaddr_cache28_icache;
assign tlb_to_icache_o[78 ] = cache28_icache;
assign tlb_to_icache_o[77 ] = vaddr_cache16_icache;
assign tlb_to_icache_o[76 ] = vaddr_valid_icache;
assign tlb_to_icache_o[75:69] = vaddr_index_icache;
assign tlb_to_icache_o[68:37] = taglow_icache;
assign tlb_to_icache_o[36 ] = valid_icache;
assign tlb_to_icache_o[34: 3] = paddr_icache;
assign tlb_to_icache_o[2 ] = cache16_icache;
assign tlb_to_icache_o[1 ] = cache8_icache;
assign tlb_to_icache_o[0 ] = cache0_icache;
///// all fields of itlb_flush_o bus
wire itlb_flush_valid;
assign itlb_flush_o = itlb_flush_valid | reset;
////// all fields of addr_to_tlb_i
wire [ 2:0] fpqid_addrout = addr_to_tlb_i[117:115];
wire [ 2:0] brqid_addrout = addr_to_tlb_i[114:112];
wire cond_true_addrout = addr_to_tlb_i[111 ];
wire valid_addrout_in = addr_to_tlb_i[110 ];
wire rd_tag_addrout = addr_to_tlb_i[109 ];
wire rd_data_addrout = addr_to_tlb_i[108 ];
wire [ 3:0] qid_addrout = addr_to_tlb_i[107:104];
wire [ 7:0] op_addrout = addr_to_tlb_i[103: 96];
wire [31:0] vaddr_addrout = addr_to_tlb_i[ 95: 64];
wire [31:0] value_addrout = addr_to_tlb_i[ 63: 32];
wire [31:0] value_h_addrout = addr_to_tlb_i[ 31: 0];
wire valid_addrout = valid_addrout_in & ~addr_brbus_cancel;
////// all fields of dcache_result_i
wire hit_dcache = dcache_result_i[70 ];
wire [ 1:0] hit_set_dcache = dcache_result_i[69:68];
wire [ 3:0] lock_dcache = dcache_result_i[67:64];
////// all fields of tag_to_tlb_i
wire taglo_lock = tag_to_tlb_i[23 ];
wire [19:0] taglo_tag = tag_to_tlb_i[22:3];
wire [ 1:0] taglo_cs = tag_to_tlb_i[2 :1];
////// all fields of tlb_read_again_o
wire valid_tlb_rag;
wire rd_tag_tlb_rag;
wire rd_data_tlb_rag;
wire [ 7:0] op_tlb_rag;
wire [11:0] laddr_tlb_rag;
assign tlb_read_again_o[22 ] = valid_tlb_rag;
assign tlb_read_again_o[21 ] = rd_tag_tlb_rag;
assign tlb_read_again_o[20 ] = rd_data_tlb_rag;
assign tlb_read_again_o[19:12] = op_tlb_rag;
assign tlb_read_again_o[11: 0] = laddr_tlb_rag;
////// all fields of tlb_to_memqueue_o
wire to_mq_valid;
wire to_mq_ex;
wire to_mq_op_load;
wire to_mq_op_store;
wire to_mq_cached;
wire to_mq_uncache_acc;
wire to_mq_hit;
wire [ 1:0] to_mq_hit_set;
wire [ 3:0] to_mq_qid;
wire [ 2:0] to_mq_fpqid;
wire [ 7:0] to_mq_op;
wire [31:0] to_mq_paddr;
wire [31:0] to_mq_value_h;
wire [31:0] to_mq_value;
wire [ 3:0] to_mq_lock;
wire to_mq_ex_ddbl;
wire to_mq_ex_ddbs;
wire to_mq_ex_ddblimpr;
wire to_mq_ex_ddblimpr_h;
wire to_mq_ex_ddbsimpr;
wire to_mq_ex_cacheerr;
wire to_mq_ex_mcheck;
wire to_mq_ex_watch;
wire to_mq_ex_ades;
wire to_mq_ex_adel;
wire to_mq_ex_tlbsr;
wire to_mq_ex_tlbsi;
wire to_mq_ex_tlblr;
wire to_mq_ex_tlbli;
wire to_mq_ex_mod;
//wire to_mq_ejtag_dseg_en;
wire ejtag_dreq_valid;
wire to_mq_cond_true;
wire [ 3:0] to_mq_bytelane;
wire [ 2:0] to_mq_brqid;
wire to_mq_ex_ri;
assign tlb_to_memqueue_o[148 ] = to_mq_ex_ddblimpr_h;
assign tlb_to_memqueue_o[147:145] = to_mq_fpqid;
assign tlb_to_memqueue_o[144 ] = to_mq_ex_ri;
assign tlb_to_memqueue_o[143:141] = to_mq_brqid;
assign tlb_to_memqueue_o[140:137] = to_mq_bytelane;
assign tlb_to_memqueue_o[136 ] = to_mq_cond_true;
assign tlb_to_memqueue_o[135 ] = ejtag_dreq_valid;
assign tlb_to_memqueue_o[134 ] = to_mq_valid;
assign tlb_to_memqueue_o[133 ] = to_mq_ex;
assign tlb_to_memqueue_o[132 ] = to_mq_op_load;
assign tlb_to_memqueue_o[131 ] = to_mq_op_store;
assign tlb_to_memqueue_o[130 ] = to_mq_cached;
assign tlb_to_memqueue_o[129 ] = to_mq_uncache_acc;
assign tlb_to_memqueue_o[128 ] = to_mq_hit;
assign tlb_to_memqueue_o[127:126] = to_mq_hit_set;
assign tlb_to_memqueue_o[125:122] = to_mq_qid;
assign tlb_to_memqueue_o[121:114] = to_mq_op;
assign tlb_to_memqueue_o[113:82 ] = to_mq_paddr;
assign tlb_to_memqueue_o[81 :50 ] = to_mq_value_h;
assign tlb_to_memqueue_o[49 :18 ] = to_mq_value;
assign tlb_to_memqueue_o[17 :14 ] = to_mq_lock;
assign tlb_to_memqueue_o[13 ] = to_mq_ex_ddbl;
assign tlb_to_memqueue_o[12 ] = to_mq_ex_ddbs;
assign tlb_to_memqueue_o[11 ] = to_mq_ex_ddblimpr;
assign tlb_to_memqueue_o[10 ] = to_mq_ex_ddbsimpr;
assign tlb_to_memqueue_o[9 ] = to_mq_ex_cacheerr;
assign tlb_to_memqueue_o[8 ] = to_mq_ex_mcheck;
assign tlb_to_memqueue_o[7 ] = to_mq_ex_watch;
assign tlb_to_memqueue_o[6 ] = to_mq_ex_ades;
assign tlb_to_memqueue_o[5 ] = to_mq_ex_adel;
assign tlb_to_memqueue_o[4 ] = to_mq_ex_tlbsr;
assign tlb_to_memqueue_o[3 ] = to_mq_ex_tlbsi;
assign tlb_to_memqueue_o[2 ] = to_mq_ex_tlblr;
assign tlb_to_memqueue_o[1 ] = to_mq_ex_tlbli;
assign tlb_to_memqueue_o[0 ] = to_mq_ex_mod;
////// all fields of ram_to_tlb_i
wire ne1 = ram_to_tlb_i[51 ];
wire [19:0] pfn1 = ram_to_tlb_i[50:31];
wire [ 2:0] c1 = ram_to_tlb_i[30:28];
wire d1 = ram_to_tlb_i[27 ];
wire v1 = ram_to_tlb_i[26 ];
wire ne0 = ram_to_tlb_i[25 ];
wire [19:0] pfn0 = ram_to_tlb_i[24: 5];
wire [ 2:0] c0 = ram_to_tlb_i[ 4: 2];
wire d0 = ram_to_tlb_i[ 1 ];
wire v0 = ram_to_tlb_i[ 0 ];
wire [31:0] pfn0_from_ram = {1'b0, ne0, 4'b0, pfn0, c0, d0, v0, 1'b0};
wire [31:0] pfn1_from_ram = {1'b0, ne1, 4'b0, pfn1, c1, d1, v1, 1'b0};
////// all fields of tlb_to_ram_o
wire tlb_ram_cen;
wire [ 5:0] tlb_ram_rindex;
wire tlb_ram_wen;
wire [ 5:0] tlb_ram_windex;
wire [51:0] tlb_ram_wdata;
assign tlb_to_ram_o[ 0] = ~tlb_ram_cen;
assign tlb_to_ram_o[ 6: 1] = tlb_ram_rindex;
assign tlb_to_ram_o[ 7] = ~tlb_ram_wen;
assign tlb_to_ram_o[59: 8] = tlb_ram_wdata;
assign tlb_to_ram_o[65:60] = tlb_ram_windex;
////// all fields of commitbus0
wire commitbus0_valid;
wire [7:0] commitbus0_op;
wire [31:0] commitbus0_value_h;
wire [31:0] commitbus0_value;
wire [5:0] commitbus0_excode;
wire commitbus0_bd;
wire [1:0] commitbus0_ce;
wire commitbus0_ex;
////// all fields of commitbus1
wire commitbus1_valid;
wire [7:0] commitbus1_op;
wire [31:0] commitbus1_value_h;
wire [31:0] commitbus1_value;
wire [5:0] commitbus1_excode;
wire commitbus1_bd;
wire [1:0] commitbus1_ce;
wire commitbus1_ex;
wire commitbus_valid;
wire [7:0] commitbus_op;
wire [31:0] commitbus_value_h;
wire [31:0] commitbus_value;
wire [5:0] commitbus_excode;
wire commitbus_bd;
wire [1:0] commitbus_ce;
wire commitbus_ex;
assign commitbus0_op = commitbus0_i[82:75];
assign commitbus0_ce = commitbus0_i[74:73];
assign commitbus0_bd = commitbus0_i[72];
assign commitbus0_valid = commitbus0_i[71];
assign commitbus0_value_h = commitbus0_i[70:39];
assign commitbus0_value = commitbus0_i[38:7];
assign commitbus0_excode = commitbus0_i[6:1];
assign commitbus0_ex = commitbus0_i[0];
assign commitbus1_op = commitbus1_i[82:75];
assign commitbus1_ce = commitbus1_i[74:73];
assign commitbus1_bd = commitbus1_i[72];
assign commitbus1_valid = commitbus1_i[71];
assign commitbus1_value_h = commitbus1_i[70:39];
assign commitbus1_value = commitbus1_i[38:7];
assign commitbus1_excode = commitbus1_i[6:1];
assign commitbus1_ex = commitbus1_i[0];
assign commitbus_valid = commitbus0_valid|commitbus1_valid;
assign commitbus_op = commitbus0_valid?commitbus0_op:commitbus1_op; //only for deret
assign commitbus_ce = commitbus0_ex?commitbus0_ce:commitbus1_ce; //for cr_cause
assign commitbus_bd = commitbus0_ex?commitbus0_bd:commitbus1_bd; //for cr_cause and cr_errorpc
assign commitbus_value_h = commitbus0_ex?commitbus0_value_h:commitbus1_value_h; //for cr_errorpc
assign commitbus_value = commitbus0_ex?commitbus0_value:commitbus1_value; //for cr_entryhi cr_badvaddr cr_context
assign commitbus_excode = commitbus0_ex?commitbus0_excode:commitbus1_excode; //for cr_cause...
assign commitbus_ex = commitbus0_ex|commitbus1_ex; //for ...
wire commit_deret = commitbus0_valid & (commitbus0_op==`OP_DERET) | commitbus1_valid & (commitbus1_op==`OP_DERET);
wire ade;
//------------output signals to HardwareBreakpoint--------------------
wire [31:0] hb_reqbus_value;
wire [7:0] hb_reqbus_op;
wire [31:0] hb_reqbus_addr;
wire [3:0] hb_reqbus_qid;
wire hb_reqbus_valid;
wire [31:0] dcr_reqbus_value;
wire [7:0] dcr_reqbus_op;
wire [31:0] dcr_reqbus_addr;
wire [3:0] dcr_reqbus_qid;
wire dcr_reqbus_valid;
//------------output signals to DMSEG--------------------
wire [31:0] dmseg_dreqbus_value;
wire [7:0] dmseg_dreqbus_op;
wire [31:0] dmseg_dreqbus_addr;
wire [3:0] dmseg_dreqbus_qid;
wire dmseg_dreqbus_valid;
wire dmseg_ireqbus_adei;
wire [31:0] dmseg_ireqbus_addr;
wire dmseg_ireqbus_valid;
wire [31:0] hb_storedata;
wire [3:0] hb_bytelane;
wire hb_type;
wire [31:0] hb_addr;
wire hb_dvalid;
wire hb_ivalid;
//all field of dresult_from_drseg
wire dres_from_drseg_valid = hb_reqbus_valid&!ade;//DRESBUS_FROM_DRSEG[0];
wire[31:0] dres_from_drseg_value = DRESBUS_FROM_DRSEG[32:1];
wire[31:0] dres_from_drseg_value_h = DRESBUS_FROM_DRSEG[64:33];
//all field of dresult_from_dcr
wire dres_from_dcr_valid = dcr_reqbus_valid;//DRESBUS_FROM_DCR[0];
wire[31:0] dres_from_dcr_value = DRESBUS_FROM_DCR[32:1];
wire[31:0] dres_from_dcr_value_h = DRESBUS_FROM_DCR[64:33];
//all field of dresult_from_dcr
wire dres_from_dmseg_valid = DRESBUS_FROM_DMSEG[0];
wire[31:0] dres_from_dmseg_value = DRESBUS_FROM_DMSEG[32:1];
wire[31:0] dres_from_dmseg_value_h = DRESBUS_FROM_DMSEG[64:33];
wire hb_reqbus_ades;
wire hb_reqbus_adel;
wire dcr_reqbus_ades;
wire dcr_reqbus_adel;
wire dmseg_dreqbus_ades;
wire dmseg_dreqbus_adel;
wire access_drseg;
wire access_dcr;
wire access_dmseg;
wire op_cp1_dw;
wire op_word;
wire ejtag_valid = access_drseg | access_dcr | access_dmseg&op_cp1_dw | dres_from_dmseg_valid;
//wire ejtag_valid = dres_from_drseg_valid | dres_from_dcr_valid | dres_from_dmseg_valid;
wire[31:0] ejtag_value = dres_from_drseg_valid ? dres_from_drseg_value :
dres_from_dcr_valid ? dres_from_dcr_value : dres_from_dmseg_value;
wire[31:0] ejtag_value_h = dres_from_drseg_valid ? dres_from_drseg_value_h :
dres_from_dcr_valid ? dres_from_dcr_value_h : dres_from_dmseg_value_h;
wire ejtag_ades = dres_from_drseg_valid ? hb_reqbus_ades:
dres_from_dcr_valid ? dcr_reqbus_ades : dmseg_dreqbus_ades;
wire ejtag_adel = dres_from_drseg_valid ? hb_reqbus_adel:
dres_from_dcr_valid ? dcr_reqbus_adel : dmseg_dreqbus_adel;
wire ejtag_dseg_dreq;
wire ejtag_dcr;
wire ejtag_drseg;
wire ejtag_dmseg_dreq;
wire dmseg_dreq_enable;
wire drseg_enable;
wire [31:0] dmseg_daddr;
wire [31:0] drseg_daddr;
wire [31:0] dcr_daddr;
////// CP0 register
reg [6:0] cr_index;
reg [5:0] cr_random;
reg [26:0] cr_entrylo0;
wire [31:0] cr_entrylo0_value;
reg [26:0] cr_entrylo1;
wire [31:0] cr_entrylo1_value;
reg [27:0] cr_context;
wire [15:0] cr_pagemask_value_out;
wire [ 7:0] cr_pagemask_value_in;
reg [ 7:0] cr_pagemask;
reg [5:0] cr_wired;
reg [3:0] cr_HWREna;
reg [31:0] cr_badvaddr;
reg [31:0] cr_count;
reg [26:0] cr_entryhi;
reg [31:0] cr_compare;
reg [31:0] cr_status;
reg [ 4:0] cr_intctrl;
reg [31:0] cr_cause;
reg [31:0] cr_epc;
reg [17:0] cr_ebase;
reg [ 2:0] cr_config;
reg [ 9:0] cr_config6;
reg [ 31:0] cr_ejtag_value; //for improve download from tap, by xucp
reg [ 5:0] cr_config7; //SPECIAL_CFG
//reg [31:0] cr_lladdr;
//reg [31:0] cr_watchlo;
//reg [17:0] cr_watchhi;
//reg [31:0] cr_protmask;
//reg [31:0] cr_protaddr;
reg [26:0] cr_taglo;
reg [31:0] cr_taghi;
reg [31:0] cr_errorpc;
reg [31:0] cr_debug;
reg [31:0] cr_depc;
reg [31:0] cr_desave;
reg cr_llbit;
//performance counter
reg [10:0] cr_perf_control0;
reg [31:0] cr_perf_count0;
reg [10:0] cr_perf_control1;
reg [31:0] cr_perf_count1;
reg count_add_en;
reg [`FILTER_WINDOW_NUM-1:0] cr_filter_en; //reg 22, sel 7
reg [`FILTER_WINDOW_DEPTH-1:0] cr_filter_addr; //reg 22, sel 5
reg [31-`FILTER_MASK_UNIT:0] filter_window[`FILTER_WINDOW_NUM*2-1:0];
wire [31-`FILTER_MASK_UNIT:0] filter_window_data = filter_window[cr_filter_addr];
wire [31:0] cr_intctrl_init = `INIT_INTCTRL;
wire [31:0] cr_ebase_init = 32'h80000000;
wire [31:0] cr_config_init = `INIT_CONFIG;
wire [31:0] mfc_regi;
assign cr_entrylo0_value = {1'b0, cr_entrylo0[26], 4'b0, cr_entrylo0[25:0]};
assign cr_entrylo1_value = {1'b0, cr_entrylo1[26], 4'b0, cr_entrylo1[25:0]};
////// ITLB
wire itlb_req_tlb_ack;
reg itlb_req_tlb_ok_r;
////// DTLB
wire doddpage;
wire [ 7:0] dtlb_asid;
wire [19:0] data_vpn;
wire dtlb_wren;
wire [ 2:0] dtlb_wr_index;
wire [19:0] dtlb_wr_vpn;
wire [ 7:0] dtlb_wr_mask;
wire [ 7:0] dtlb_wr_asid;
wire dtlb_wr_g;
wire [31:0] dtlb_wr_pfn;
wire dtlb_flush_valid;
wire [18:0] dtlb_flush_vpn2;
wire [ 7:0] dtlb_pagemask;
wire dtlb_find;
wire [31:0] dtlb_pfn;
wire [ 2:0] dtlb_find_index;
wire [31:0] dtlb_paddr;
wire dv;
wire [ 2:0] dc;
wire dd;
wire dne;
wire d_map;
wire d_cached;
wire d_uncache_acc;
wire [23:0] dpfn;
wire [31:0] dmask;
wire [31:0] dcache_paddr;
///// exception found during data access
wire d_ex_mod;
wire d_ex_tlblr;
wire d_ex_tlbsr;
wire d_ex_tlbli;
wire d_ex_tlbsi;
wire d_ex_adel;
wire d_ex_ades;
wire d_ex_watch;
wire d_ex_mcheck;
wire d_ex_cacheerr;
wire d_ex_ddbl;
wire d_ex_ddbs;
wire d_ex_ddblimpr;
wire d_ex_ddblimpr_h;
wire d_ex_ddbsimpr;
wire d_ex;
wire d_ex_tlb;
wire d_ex_ri;
reg dtlb_req_tlb_ok_r;
////// TLB
// tlb_find registered, delayed to the same cycle of tlb ram data out
reg tlb_find_r;
// tlb_pagemask_out registered
reg [ 7:0] tlb_pagemask_r;
wire [15:0] tlb_pagemask_r_value;
// tlb_asid_out registered
reg [ 7:0] tlb_asid_r;
// tlb_g_out registered
reg tlb_g_r;
reg tlb_find_ok_r;
// tlb cam read enable, when need not to look up tlb cam,
// we set tlb_cam_index to be zero.
wire tlb_data_lookup_en;
// when itlb miss occur, find it in tlb
wire tlb_instr_lookup_en;
// vpn2 used to look up tlb cam
wire [18:0] tlb_vpn2_lookup;
// asid used to look up tlb cam
wire [ 7:0] tlb_asid_lookup;
// whether tlb cam lookup is ok
wire tlb_find;
// result index of tlb cam lookup
wire [ 5:0] tlb_index_out;
// pagemask of the hit tlb iterm
wire [ 7:0] tlb_pagemask_out;
wire [ 7:0] tlb_asid_out;
wire tlb_g_out;
wire [18:0] tlb_vpn2_out;
// tlb cam write enable
wire tlb_cam_wen;
// index used for TLBWI, TLBWR
wire [ 5:0] tlb_cam_windex;
// vpn2 value written into tlb cam
wire [18:0] tlbw_vpn2;
// pagemask value written into tlb cam
wire [ 7:0] tlbw_pagemask;
// asid value written into tlb cam
wire [ 7:0] tlbw_asid;
// g value written into tlb cam
wire tlbw_g;
// TLBR instr.
wire tlbr_valid;
// index used for tlb cam read (TLBR)
wire [ 5:0] tlb_cam_rindex;
// vpn2 value read from tlb cam
wire [18:0] tlbr_vpn2;
// pagemask value read from tlb cam
wire [ 7:0] tlbr_pagemask;
// asid value read from tlb cam
wire [ 7:0] tlbr_asid;
// g value read from tlb cam
wire tlbr_g;
wire [31:0] tlb_paddr;
///// some wires with cp0 register operation
wire [ 4:0] excode;
wire random_wired_eq;
wire count_compare_eq;
wire [ 5:0] cr_random_sub1;
wire [31:0] cr_count_add1;
wire [ 7:0] asid;
wire g;
wire exl;
wire erl;
wire [ 1:0] ksu;
wire [ 2:0] config_k0;
wire mode_user;
wire mode_super;
wire mode_kernel;
//tlbr instr. is ready now
reg tlbr_rdy_r;
// op can enter into its queue
wire memqueue_allowin;
wire normal_allowin;
wire ld_queue_allowin;
wire st_queue_allowin;
////// mmbuffer
reg [ 1:0] mmbuf_state_r;
reg mmbuf_rd_tag_r;
reg mmbuf_rd_data_r;
reg [ 3:0] mmbuf_qid_r;
reg [ 2:0] mmbuf_brqid_r;
reg [ 7:0] mmbuf_op_r;
reg [31:0] mmbuf_vaddr_r;
reg [31:0] mmbuf_value_h_r;
reg [31:0] mmbuf_value_r;
reg new_enter_r;
reg addr_trans_ok_r;
reg [ 2:0] select_index_r;
reg d_ex_tlblr_r;
reg d_ex_tlbsr_r;
reg d_ex_tlbli_r;
reg d_ex_tlbsi_r;
wire op_read_tag = mmbuf_rd_tag_r;
wire op_read_data = mmbuf_rd_data_r;
wire [31:0] mmbuf_value_h = mmbuf_value_h_r;
wire [31:0] mmbuf_value = mmbuf_value_r;
wire [31:0] mmbuf_vaddr = mmbuf_vaddr_r;
wire [ 7:0] mmbuf_op = mmbuf_op_r;
wire mmbuf_invalid;
wire mmbuf_valid;
wire mmbuf_read_again;
wire mmbuf_to_valid;
wire mmbuf_to_invalid;
wire mmbuf_to_read_again;
//the ram can not hold it's output
wire ram_no_hold = 1'b0;
wire op_mtc0 = mmbuf_op == `OP_MTC0;
wire op_mfc0 = mmbuf_op == `OP_MFC0;
wire op_di = mmbuf_op == `OP_DI;
wire op_ei = mmbuf_op == `OP_EI;
wire op_tlbp = mmbuf_op == `OP_TLBP;
wire op_tlbr = mmbuf_op == `OP_TLBR;
wire op_tlbwi = mmbuf_op == `OP_TLBWI;
wire op_tlbwr = mmbuf_op == `OP_TLBWR;
wire op_eret = mmbuf_op == `OP_ERET;
wire op_deret = mmbuf_op == `OP_DERET;
wire op_lb = mmbuf_op == `OP_LB;
wire op_lbu = mmbuf_op == `OP_LBU;
wire op_lbux = mmbuf_op == `OP_LBUX;
wire op_lh = mmbuf_op == `OP_LH;
wire op_lhu = mmbuf_op == `OP_LHU;
wire op_lhx = mmbuf_op == `OP_LHX;
wire op_lw = mmbuf_op == `OP_LW;
wire op_lwc1 = 1'b0;
wire op_lwx = mmbuf_op == `OP_LWX;
wire op_ll = mmbuf_op == `OP_LL;
wire op_lwl = mmbuf_op == `OP_LWL;
wire op_lwr = mmbuf_op == `OP_LWR;
wire op_ldc1 = 1'b0;
wire op_sb = mmbuf_op == `OP_SB;
wire op_sh = mmbuf_op == `OP_SH;
wire op_sw = mmbuf_op == `OP_SW;
wire op_swc1 = 1'b0;
wire op_swl = mmbuf_op == `OP_SWL;
wire op_swr = mmbuf_op == `OP_SWR;
wire op_sc = mmbuf_op == `OP_SC;
wire op_sdc1 = 1'b0;
wire op_prefetch = (mmbuf_op == `OP_PREF) || (mmbuf_op == `OP_PREFX);
wire op_sync = mmbuf_op == `OP_SYNC;
wire op_cache1 = mmbuf_op == `OP_CACHE1;
wire op_cache5 = mmbuf_op == `OP_CACHE5;
wire op_cache9 = mmbuf_op == `OP_CACHE9;
wire op_cache29 = mmbuf_op == `OP_CACHE29;
wire op_cache16 = (mmbuf_op==`OP_CACHE16) || (mmbuf_op==`OP_SYNCI);
wire op_cache28 = (mmbuf_op==`OP_CACHE28);
wire op_cache8 = (mmbuf_op==`OP_CACHE8);
wire op_cache0 = (mmbuf_op==`OP_CACHE0);
wire di_op = (mmbuf_op==`OP_DI) ||(mmbuf_op==`OP_EI);
wire op_cp0 = op_mtc0 | op_mfc0 | op_di | op_ei | op_tlbp |
op_tlbr | op_tlbwi | op_tlbwr | op_eret | op_deret ;
wire op_dcache = (mmbuf_op == `OP_CACHE1) || (mmbuf_op == `OP_CACHE5) ||
(mmbuf_op == `OP_CACHE9) || (mmbuf_op == `OP_CACHE17)||
(mmbuf_op == `OP_CACHE21)|| (mmbuf_op == `OP_CACHE29)||
(mmbuf_op == `OP_SYNCI) ;
wire op_icache = (mmbuf_op == `OP_CACHE0) || (mmbuf_op == `OP_CACHE8) ||
(mmbuf_op == `OP_CACHE16) || (mmbuf_op == `OP_CACHE28) ||
(mmbuf_op == `OP_SYNCI) ;
wire op_cache = op_dcache | op_icache;
wire op_index_dcache = (mmbuf_op == `OP_CACHE1) || (mmbuf_op == `OP_CACHE5) ||
(mmbuf_op == `OP_CACHE9);
wire op_index_icache = (mmbuf_op == `OP_CACHE0) || (mmbuf_op == `OP_CACHE8);
wire op_index_cache = op_index_dcache | op_index_icache;
wire op_ld_b_align = op_lb || op_lbu ||
op_lwl || op_lwr ||
op_lbux;
wire op_ld_hw_align = op_lh || op_lhu ||
op_lhx ;
wire op_ld_w_align = op_lw || op_ll || op_lwx || op_lwc1;
wire op_ld_dw_align = op_ldc1;
wire op_st_b_align = op_sb ||
op_swl || op_swr;
wire op_st_hw_align = op_sh;
wire op_st_w_align = op_sw || op_sc || op_swc1;
wire op_st_dw_align = op_sdc1;
wire op_load = op_read_data;
wire op_store = op_read_tag & ~op_read_data & ~op_dcache & ~op_prefetch;
// tlb instruction