Datasets:

Modalities:
Text
Formats:
json
Size:
< 1K
ArXiv:
License:
arnauad commited on
Commit
febf5c8
·
1 Parent(s): 9442788

Dataset structure modification + README update

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. README.md +113 -21
  2. RuC-cve2-32k.jsonl +0 -0
  3. RuC-datasets/RuC-cve2_b72358c7-32k/p1/all_mask_idx.json +0 -1
  4. RuC-datasets/RuC-cve2_b72358c7-32k/p1/cve2_alu.sv +0 -1818
  5. RuC-datasets/RuC-cve2_b72358c7-32k/p1/mask_idx.json +0 -1
  6. RuC-datasets/RuC-cve2_b72358c7-32k/p10/all_mask_idx.json +0 -1
  7. RuC-datasets/RuC-cve2_b72358c7-32k/p10/cve2_multdiv_slow.sv +0 -1035
  8. RuC-datasets/RuC-cve2_b72358c7-32k/p10/mask_idx.json +0 -1
  9. RuC-datasets/RuC-cve2_b72358c7-32k/p11/all_mask_idx.json +0 -1
  10. RuC-datasets/RuC-cve2_b72358c7-32k/p11/cve2_pmp.sv +0 -798
  11. RuC-datasets/RuC-cve2_b72358c7-32k/p11/mask_idx.json +0 -1
  12. RuC-datasets/RuC-cve2_b72358c7-32k/p12/all_mask_idx.json +0 -1
  13. RuC-datasets/RuC-cve2_b72358c7-32k/p12/cve2_prefetch_buffer.sv +0 -491
  14. RuC-datasets/RuC-cve2_b72358c7-32k/p12/mask_idx.json +0 -1
  15. RuC-datasets/RuC-cve2_b72358c7-32k/p13/all_mask_idx.json +0 -1
  16. RuC-datasets/RuC-cve2_b72358c7-32k/p13/cve2_wb.sv +0 -796
  17. RuC-datasets/RuC-cve2_b72358c7-32k/p13/mask_idx.json +0 -1
  18. RuC-datasets/RuC-cve2_b72358c7-32k/p2/all_mask_idx.json +0 -1
  19. RuC-datasets/RuC-cve2_b72358c7-32k/p2/cve2_branch_predict.sv +0 -792
  20. RuC-datasets/RuC-cve2_b72358c7-32k/p2/mask_idx.json +0 -1
  21. RuC-datasets/RuC-cve2_b72358c7-32k/p3/all_mask_idx.json +0 -1
  22. RuC-datasets/RuC-cve2_b72358c7-32k/p3/cve2_compressed_decoder.sv +0 -964
  23. RuC-datasets/RuC-cve2_b72358c7-32k/p3/mask_idx.json +0 -1
  24. RuC-datasets/RuC-cve2_b72358c7-32k/p4/all_mask_idx.json +0 -1
  25. RuC-datasets/RuC-cve2_b72358c7-32k/p4/cve2_controller.sv +0 -1373
  26. RuC-datasets/RuC-cve2_b72358c7-32k/p4/mask_idx.json +0 -1
  27. RuC-datasets/RuC-cve2_b72358c7-32k/p5/all_mask_idx.json +0 -1
  28. RuC-datasets/RuC-cve2_b72358c7-32k/p5/cve2_cs_registers.sv +0 -2157
  29. RuC-datasets/RuC-cve2_b72358c7-32k/p5/mask_idx.json +0 -1
  30. RuC-datasets/RuC-cve2_b72358c7-32k/p6/all_mask_idx.json +0 -1
  31. RuC-datasets/RuC-cve2_b72358c7-32k/p6/cve2_decoder.sv +0 -1765
  32. RuC-datasets/RuC-cve2_b72358c7-32k/p6/mask_idx.json +0 -1
  33. RuC-datasets/RuC-cve2_b72358c7-32k/p7/all_mask_idx.json +0 -1
  34. RuC-datasets/RuC-cve2_b72358c7-32k/p7/cve2_if_stage.sv +0 -1605
  35. RuC-datasets/RuC-cve2_b72358c7-32k/p7/mask_idx.json +0 -1
  36. RuC-datasets/RuC-cve2_b72358c7-32k/p8/all_mask_idx.json +0 -1
  37. RuC-datasets/RuC-cve2_b72358c7-32k/p8/cve2_load_store_unit.sv +0 -546
  38. RuC-datasets/RuC-cve2_b72358c7-32k/p8/mask_idx.json +0 -1
  39. RuC-datasets/RuC-cve2_b72358c7-32k/p9/all_mask_idx.json +0 -1
  40. RuC-datasets/RuC-cve2_b72358c7-32k/p9/cve2_multdiv_fast.sv +0 -1151
  41. RuC-datasets/RuC-cve2_b72358c7-32k/p9/mask_idx.json +0 -1
  42. RuC-datasets/RuC-tt07-32k/BTFLV-tt07-subleq-fram-cpu/all_mask_idx.json +0 -1
  43. RuC-datasets/RuC-tt07-32k/BTFLV-tt07-subleq-fram-cpu/mask_idx.json +0 -1
  44. RuC-datasets/RuC-tt07-32k/BTFLV-tt07-subleq-fram-cpu/tt_um_btflv_subleq.v +0 -717
  45. RuC-datasets/RuC-tt07-32k/JamesTimothyMeech-TT07-LFSR/all_mask_idx.json +0 -1
  46. RuC-datasets/RuC-tt07-32k/JamesTimothyMeech-TT07-LFSR/mask_idx.json +0 -1
  47. RuC-datasets/RuC-tt07-32k/JamesTimothyMeech-TT07-LFSR/tt_um_lfsr.v +0 -135
  48. RuC-datasets/RuC-tt07-32k/Kevomlml-tt07_chipusm_neural_network/all_mask_idx.json +0 -1
  49. RuC-datasets/RuC-tt07-32k/Kevomlml-tt07_chipusm_neural_network/mask_idx.json +0 -1
  50. RuC-datasets/RuC-tt07-32k/Kevomlml-tt07_chipusm_neural_network/tt_um_neural_network.v +0 -498
README.md CHANGED
@@ -1,33 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ## Summary
2
- RuC is a grammar-driven, rule-selectable benchmark generator that automatically produces RTL code-completion tasks from a set of input hardware description sources. It uses the target HDL grammar to mask syntactically defined code regions and prompts a model to regenerate them using the surrounding unmasked code as context.
 
3
 
4
  **Paper**: https://arxiv.org/abs/2604.27780
5
 
6
- RuC-datasets is a collection of design datasets processed with the RuC framework and used for the experimentations in the paper.
7
- Although RuC-cve2_b72358c7-32k and RuC-tt07-32k share the same schema and preprocessing steps, they originate from different base datasets and should be treated as separate datasets.
 
 
 
 
8
 
9
- ## Datasets structure
10
- Each project inside both datasets contains:
11
 
12
- - <top_module>.sv for cve2 or <top_module>.v for tt07
13
- Verilog or SystemVerilog hardware designs named after the top-level module.
14
- - mask_idx.json
15
- Indices of selected rule occurrences used for RuC.
16
- - all_mask_idx.json
17
- Full set of candidate rule occurrences eligible for masking.
18
 
19
- ## Dataset creation
20
- Both datasets computed mask_idx.json and all_mask_idx.json using RuC as explained in the paper.
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  ### RuC-tt07-32k
23
- NotSoTiny shuttle tt07 (https://huggingface.co/datasets/HPAI-BSC/NotSoTiny-25-12) filtered to keep designs that contain less than 32000 tokens.
24
 
25
- ### RuC-cve2_b72358c7-32k
26
- CVE2 is an industry-grade RISC-V core maintained by OpenHWGroup. The CVE2 codebase preprocessed using vppreproc and filtered to keep designs that contain less than 32000 tokens.
27
 
28
- ## Datasets usage
29
- These datasets are intended to be used together with the RuC framework (https://github.com/HPAI-BSC/RuC) to directly perform inference and evaluation with different LLMs.
30
 
31
- ---
32
- license: apache-2.0
33
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ configs:
4
+ - config_name: RuC-cve2-32k
5
+ data_files:
6
+ - split: train
7
+ path: RuC-cve2-32k.jsonl
8
+
9
+ - config_name: RuC-tt07-32k
10
+ data_files:
11
+ - split: train
12
+ path: RuC-tt07-32k.jsonl
13
+ ---
14
+
15
+
16
+ # RuC Datasets
17
+
18
  ## Summary
19
+
20
+ RuC is a grammar-driven, rule-selectable benchmark generator that automatically produces RTL code-completion tasks from input hardware description sources. It uses the target HDL grammar to mask syntactically defined code regions and prompts a model to regenerate them using the surrounding unmasked code as context.
21
 
22
  **Paper**: https://arxiv.org/abs/2604.27780
23
 
24
+ RuC-datasets is a collection of hardware design datasets processed with the RuC framework and used for the experiments presented in the paper.
25
+
26
+ The repository currently contains two datasets:
27
+
28
+ - `RuC-cve2-32k`
29
+ - `RuC-tt07-32k`
30
 
31
+ Although both datasets share the same schema and preprocessing pipeline, they originate from different source corpora and should be treated as separate datasets.
 
32
 
33
+ ## Dataset Structure
 
 
 
 
 
34
 
35
+ Each dataset is distributed as a JSONL file where each row corresponds to a single hardware design sample.
 
36
 
37
+ Each sample contains the following fields:
38
+
39
+ - `sample_i`
40
+ Unique sample identifier.
41
+
42
+ - `topmodule`
43
+ Name of the top-level Verilog/SystemVerilog module.
44
+
45
+ - `code`
46
+ Full HDL source code of the design.
47
+
48
+ - `mask_idx`
49
+ Indices of the rule occurrences selected by RuC for masking.
50
+
51
+ - `all_mask_idx`
52
+ Complete set of candidate rule occurrences eligible for masking.
53
+
54
+
55
+ ## Dataset Origins
56
  ### RuC-tt07-32k
 
57
 
58
+ Derived from the NotSoTiny shuttle tt07 dataset:
 
59
 
60
+ https://huggingface.co/datasets/HPAI-BSC/NotSoTiny-25-12
 
61
 
62
+ Designs were filtered to retain samples containing fewer than 32000 tokens.
63
+
64
+ The original source files are Verilog (.v) designs.
65
+
66
+ ### RuC-cve2-32k
67
+
68
+ Derived from the CVE2 RISC-V core maintained by OpenHWGroup.
69
+
70
+ The CVE2 codebase was preprocessed using vppreproc and filtered to retain samples containing fewer than 32000 tokens.
71
+
72
+ The original source files are SystemVerilog (.sv) designs.
73
+
74
+ ## RuC usage
75
+
76
+ These datasets are intended to be used together with the RuC framework: https://github.com/HPAI-BSC/RuC
77
+
78
+
79
+ To use the samples directly with the RuC framework, each JSON sample must be reconstructed into the original directory layout expected by RuC.
80
+
81
+ For each sample:
82
+ ```
83
+ RuC-cve2-32k
84
+ <sample_i>/
85
+ ├── <topmodule>.sv
86
+ ├── mask_idx.json
87
+ └── all_mask_idx.json
88
+ ```
89
+
90
+ ```
91
+ RuC-tt07-32k
92
+ <sample_i>/
93
+ ├── <topmodule>.v
94
+ ├── mask_idx.json
95
+ └── all_mask_idx.json
96
+ ```
97
+
98
+ Where:
99
+
100
+ `<topmodule>.sv` or `<topmodule>.v` contains the contents of the code field.
101
+ `mask_idx.json` contains the contents of the `mask_idx` field.
102
+ `all_mask_idx.json` contains the contents of the `all_mask_idx` field.
103
+
104
+ The required HDL extension depends on the dataset:
105
+
106
+ .sv for `RuC-cve2-32k`
107
+ .v for `RuC-tt07-32k`
108
+
109
+
110
+ ## Additional Information
111
+ ### License
112
+ The dataset is released under the Apache License 2.0.
113
+
114
+ ### Citation Information
115
+ ```
116
+ @misc{domingo2026ruchdlagnosticrulecompletion,
117
+ title={RuC: HDL-Agnostic Rule Completion Benchmark Generation},
118
+ author={Arnau Ayguadé Domingo and Miquel Alberti-Binimelis and Cristian Gutierrez-Gomez and Emanuele Parisi and Razine Moundir Ghorab and Miquel Moreto and Gokcen Kestor and Dario Garcia-Gasulla},
119
+ year={2026},
120
+ eprint={2604.27780},
121
+ archivePrefix={arXiv},
122
+ primaryClass={cs.AR},
123
+ url={https://arxiv.org/abs/2604.27780},
124
+ }
125
+ ```
RuC-cve2-32k.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
RuC-datasets/RuC-cve2_b72358c7-32k/p1/all_mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"module_program_interface_instantiation": [], "continuous_assign": [[19483, 19527], [20923, 20978], [21231, 21305], [21308, 21361], [21364, 21405], [21785, 21827], [21830, 21866], [23000, 23040], [26842, 26912], [26915, 27009], [27012, 27048], [27051, 27125], [27189, 27229], [27238, 27361], [27490, 27542], [27545, 27592], [27985, 28122], [29252, 29298], [29301, 29437], [29440, 29548], [31183, 31266], [31269, 31329], [31332, 31392], [31395, 31455], [31458, 31529], [31532, 31604], [32953, 32998], [33003, 33048], [33053, 33100], [33105, 33147], [33477, 33542], [33895, 33975], [38231, 38293], [38377, 38416], [38421, 38460], [38799, 38944], [39824, 39866], [39871, 39993], [39998, 40120], [42303, 42373], [42416, 42463], [45956, 46002], [46011, 46057], [46354, 46400], [46409, 46455], [46764, 46811], [46820, 46868], [48236, 48263], [48329, 48377], [48394, 48424], [51583, 51627], [51644, 51690], [51697, 51743], [52148, 52389], [52396, 52556], [52563, 52641], [52648, 52726], [52733, 52802], [52809, 52870], [53618, 53683], [53768, 53843], [53927, 54004], [54088, 54165], [54249, 54326], [54343, 54411], [54487, 54539], [54957, 54990], [54997, 55030], [55037, 55070], [55102, 55135], [55142, 55175], [55182, 55215], [58274, 58328], [58414, 58472], [58557, 58618], [58703, 58764], [58849, 58912], [58929, 58985], [58992, 59041], [60479, 60690], [60701, 60867], [60878, 61042], [61053, 61136], [61147, 61230], [61330, 61424], [63730, 63775], [63782, 63815], [63822, 63855], [63887, 63920], [63927, 63960], [67242, 67290], [67337, 67390], [67440, 67496], [67529, 67561], [67566, 67598], [67603, 67635], [67640, 67672], [67677, 67709], [67714, 67746], [67751, 67783], [67788, 67820], [67825, 67857], [67862, 67894], [67899, 67931], [67936, 67968], [68002, 68046], [68051, 68095], [70317, 70368]], "blocking_assignment": [[19804, 19829], [19834, 19859], [19864, 19889], [19894, 19919], [20191, 20216], [20304, 20329], [20372, 20397], [20440, 20465], [20590, 20623], [20649, 20688], [20714, 20754], [20780, 20821], [20847, 20879], [21047, 21080], [21106, 21133], [21159, 21192], [21712, 21730], [21746, 21764], [21974, 22020], [22046, 22096], [22650, 22673], [22700, 22723], [22775, 22819], [22910, 22941], [22957, 22979], [27641, 27703], [27729, 27940], [28553, 28571], [28587, 28663], [28679, 28727], [28743, 28803], [28819, 28880], [28896, 29007], [29023, 29136], [29152, 29170], [29217, 29235], [29747, 29804], [29871, 29900], [29923, 29953], [29976, 30033], [30060, 30186], [30191, 30245], [30250, 30299], [30304, 30351], [30406, 30447], [30460, 30520], [30971, 31028], [31045, 31118], [31135, 31162], [31667, 31702], [31722, 31758], [31778, 31814], [33571, 33604], [33611, 33651], [33658, 33698], [33705, 33745], [33752, 33792], [33799, 33840], [33847, 33882], [34037, 34063], [34085, 34146], [34168, 34202], [36749, 36781], [36860, 36930], [37019, 37079], [37168, 37228], [37319, 37379], [37413, 37474], [37594, 37655], [37735, 37795], [37884, 37944], [37978, 38021], [38083, 38148], [38525, 38580], [38598, 38656], [38674, 38727], [39118, 39164], [39183, 39230], [39249, 39295], [39314, 39370], [40149, 40174], [40217, 40387], [40440, 40610], [40663, 40833], [40886, 41124], [41177, 41415], [42528, 42557], [42600, 42631], [42642, 42673], [42684, 42715], [42726, 42757], [42791, 42821], [42876, 43390], [43448, 43626], [43684, 43862], [43920, 44098], [44156, 44334], [44389, 44903], [47175, 47187], [47200, 47212], [47364, 47399], [47414, 47449], [47464, 47494], [47666, 47702], [47717, 47753], [47768, 47804], [47819, 47855], [47870, 47900], [48044, 48056], [48069, 48078], [52943, 52983], [53005, 53046], [53068, 53094], [53209, 53273], [53284, 53341], [53375, 53444], [53455, 53524], [54713, 54745], [54769, 54815], [54839, 54871], [59126, 59160], [59248, 59291], [59390, 59437], [59535, 59585], [59683, 59733], [59831, 59883], [59904, 59949], [61467, 61498], [61507, 61692], [61701, 61884], [61893, 62076], [62085, 62268], [62277, 62460], [62469, 62519], [62562, 62610], [62619, 62814], [62823, 63018], [63027, 63222], [63231, 63426], [63435, 63632], [64419, 64493], [64504, 64540], [64594, 64615], [64653, 64674], [64735, 64791], [64802, 64845], [64899, 64920], [64958, 64979], [65120, 65184], [65222, 65272], [65297, 65334], [65388, 65409], [65447, 65468], [65730, 65788], [65814, 65873], [65899, 65936], [65969, 66010], [66068, 66089], [66131, 66152], [66206, 66242], [66255, 66276], [66289, 66312], [66437, 66596], [66609, 66669], [66727, 66748], [66790, 66811], [66865, 66901], [66914, 66935], [66948, 66971], [67031, 67067], [67078, 67099], [67110, 67133], [68183, 68199], [68356, 68382], [68497, 68521], [68628, 68652], [68717, 68743], [68838, 68862], [68994, 69024], [69111, 69136], [69214, 69248], [69326, 69349], [69407, 69430], [69803, 69832], [69933, 69961], [70034, 70056], [70105, 70127], [70223, 70247]], "nonblocking_assignment": [], "case_statement": [[19924, 20493], [20547, 20891], [21003, 21204], [21594, 21776], [22599, 22991], [28513, 29182], [29830, 30047], [30856, 31174], [31629, 31826], [34004, 34216], [38489, 38741], [39075, 39384], [47072, 48108], [52903, 53110], [54678, 54887], [64360, 67159], [65686, 65956], [68204, 70276]], "conditional_statement": [[20280, 20329], [20348, 20397], [20416, 20465], [21913, 22104], [27617, 27948], [29187, 29243], [29711, 30055], [40181, 40397], [40404, 40620], [40627, 40843], [40850, 41134], [41141, 41425], [42566, 42833], [42842, 43402], [43411, 43638], [43647, 43874], [43883, 44110], [44119, 44346], [44355, 44915], [53181, 53536], [64551, 64688], [64856, 64993], [65074, 65286], [65345, 65482], [65616, 66326], [66023, 66168], [66395, 66985], [66682, 66827]], "always_construct": [[19782, 20499], [20525, 20897], [20981, 21210], [21572, 21782], [21891, 22110], [22577, 22997], [27595, 27954], [28491, 29249], [29575, 30526], [30834, 31180], [31607, 31832], [33547, 33890], [33980, 34224], [36725, 38166], [38465, 38749], [39051, 39392], [40125, 41433], [42502, 44925], [47046, 48118], [52877, 53120], [53155, 53546], [54652, 54897], [59100, 59959], [61441, 62529], [62536, 63642], [64336, 67167], [68161, 70282]], "parameter_declaration": [[6471, 6520], [6523, 6571], [6594, 6628], [6631, 6665], [6668, 6702], [12379, 12461], [12464, 12546], [12570, 12622], [12625, 12677], [12680, 12733], [12736, 12789], [12792, 12845], [12848, 12901], [12925, 13002], [13044, 13089], [13092, 13137], [13140, 13186], [13189, 13235], [13238, 13284], [13332, 13380], [13383, 13431], [13434, 13482], [13551, 13619], [13622, 13688], [13787, 13814], [16708, 16752], [16755, 16799], [16802, 16847], [16850, 16895], [16898, 16943], [16946, 16990], [16993, 17037], [17040, 17096], [18547, 18602]], "ansi_port_declaration": [[18609, 18646], [18649, 18687], [18690, 18728], [18731, 18777], [18780, 18826], [18829, 18875], [18878, 18918], [18921, 18962], [18965, 19006], [19009, 19048], [19051, 19092], [19095, 19140], [19143, 19178], [19181, 19227], [19230, 19273]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p1/cve2_alu.sv DELETED
@@ -1,1818 +0,0 @@
1
- // Copyright (c) 2025 Eclipse Foundation
2
- // Copyright lowRISC contributors.
3
- // Copyright 2017 ETH Zurich and University of Bologna, see also CREDITS.md.
4
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
5
- // SPDX-License-Identifier: Apache-2.0
6
- /**
7
- * Package with constants used by CVE2
8
- */
9
- package cve2_pkg;
10
- ////////////////
11
- // IO Structs //
12
- ////////////////
13
- typedef struct packed {
14
- logic [31:0] current_pc;
15
- logic [31:0] next_pc;
16
- logic [31:0] last_data_addr;
17
- logic [31:0] exception_addr;
18
- } crash_dump_t;
19
- typedef struct packed {
20
- logic dummy_instr_id;
21
- logic [4:0] raddr_a;
22
- logic [4:0] waddr_a;
23
- logic we_a;
24
- logic [4:0] raddr_b;
25
- } core2rf_t;
26
- /////////////////////
27
- // Parameter Enums //
28
- /////////////////////
29
- typedef enum integer {
30
- RV32MNone = 0,
31
- RV32MSlow = 1,
32
- RV32MFast = 2,
33
- RV32MSingleCycle = 3
34
- } rv32m_e;
35
- typedef enum integer {
36
- RV32BNone = 0,
37
- RV32BBalanced = 1,
38
- RV32BOTEarlGrey = 2,
39
- RV32BFull = 3
40
- } rv32b_e;
41
- /////////////
42
- // Opcodes //
43
- /////////////
44
- typedef enum logic [6:0] {
45
- OPCODE_LOAD = 7'h03,
46
- OPCODE_MISC_MEM = 7'h0f,
47
- OPCODE_OP_IMM = 7'h13,
48
- OPCODE_AUIPC = 7'h17,
49
- OPCODE_STORE = 7'h23,
50
- OPCODE_OP = 7'h33,
51
- OPCODE_LUI = 7'h37,
52
- OPCODE_BRANCH = 7'h63,
53
- OPCODE_JALR = 7'h67,
54
- OPCODE_JAL = 7'h6f,
55
- OPCODE_SYSTEM = 7'h73
56
- } opcode_e;
57
- ////////////////////
58
- // ALU operations //
59
- ////////////////////
60
- typedef enum logic [6:0] {
61
- // Arithmetics
62
- ALU_ADD,
63
- ALU_SUB,
64
- // Logics
65
- ALU_XOR,
66
- ALU_OR,
67
- ALU_AND,
68
- // RV32B
69
- ALU_XNOR,
70
- ALU_ORN,
71
- ALU_ANDN,
72
- // Shifts
73
- ALU_SRA,
74
- ALU_SRL,
75
- ALU_SLL,
76
- // RV32B
77
- ALU_SRO,
78
- ALU_SLO,
79
- ALU_ROR,
80
- ALU_ROL,
81
- ALU_GREV,
82
- ALU_GORC,
83
- ALU_SHFL,
84
- ALU_UNSHFL,
85
- ALU_XPERM_N,
86
- ALU_XPERM_B,
87
- ALU_XPERM_H,
88
- // Address Calculations
89
- // RV32B
90
- ALU_SH1ADD,
91
- ALU_SH2ADD,
92
- ALU_SH3ADD,
93
- // Comparisons
94
- ALU_LT,
95
- ALU_LTU,
96
- ALU_GE,
97
- ALU_GEU,
98
- ALU_EQ,
99
- ALU_NE,
100
- // RV32B
101
- ALU_MIN,
102
- ALU_MINU,
103
- ALU_MAX,
104
- ALU_MAXU,
105
- // Pack
106
- // RV32B
107
- ALU_PACK,
108
- ALU_PACKU,
109
- ALU_PACKH,
110
- // Sign-Extend
111
- // RV32B
112
- ALU_SEXTB,
113
- ALU_SEXTH,
114
- // Bitcounting
115
- // RV32B
116
- ALU_CLZ,
117
- ALU_CTZ,
118
- ALU_CPOP,
119
- // Set lower than
120
- ALU_SLT,
121
- ALU_SLTU,
122
- // Ternary Bitmanip Operations
123
- // RV32B
124
- ALU_CMOV,
125
- ALU_CMIX,
126
- ALU_FSL,
127
- ALU_FSR,
128
- // Single-Bit Operations
129
- // RV32B
130
- ALU_BSET,
131
- ALU_BCLR,
132
- ALU_BINV,
133
- ALU_BEXT,
134
- // Bit Compress / Decompress
135
- // RV32B
136
- ALU_BCOMPRESS,
137
- ALU_BDECOMPRESS,
138
- // Bit Field Place
139
- // RV32B
140
- ALU_BFP,
141
- // Carry-less Multiply
142
- // RV32B
143
- ALU_CLMUL,
144
- ALU_CLMULR,
145
- ALU_CLMULH,
146
- // Cyclic Redundancy Check
147
- ALU_CRC32_B,
148
- ALU_CRC32C_B,
149
- ALU_CRC32_H,
150
- ALU_CRC32C_H,
151
- ALU_CRC32_W,
152
- ALU_CRC32C_W
153
- } alu_op_e;
154
- typedef enum logic [1:0] {
155
- // Multiplier/divider
156
- MD_OP_MULL,
157
- MD_OP_MULH,
158
- MD_OP_DIV,
159
- MD_OP_REM
160
- } md_op_e;
161
- //////////////////////////////////
162
- // Control and status registers //
163
- //////////////////////////////////
164
- // CSR operations
165
- typedef enum logic [1:0] {
166
- CSR_OP_READ,
167
- CSR_OP_WRITE,
168
- CSR_OP_SET,
169
- CSR_OP_CLEAR
170
- } csr_op_e;
171
- // Privileged mode
172
- typedef enum logic[1:0] {
173
- PRIV_LVL_M = 2'b11,
174
- PRIV_LVL_H = 2'b10,
175
- PRIV_LVL_S = 2'b01,
176
- PRIV_LVL_U = 2'b00
177
- } priv_lvl_e;
178
- // Constants for the dcsr.xdebugver fields
179
- typedef enum logic[3:0] {
180
- XDEBUGVER_NO = 4'd0, // no external debug support
181
- XDEBUGVER_STD = 4'd4, // external debug according to RISC-V debug spec
182
- XDEBUGVER_NONSTD = 4'd15 // debug not conforming to RISC-V debug spec
183
- } x_debug_ver_e;
184
- //////////////
185
- // WB stage //
186
- //////////////
187
- // Type of instruction present in writeback stage
188
- typedef enum logic[1:0] {
189
- WB_INSTR_LOAD, // Instruction is awaiting load data
190
- WB_INSTR_STORE, // Instruction is awaiting store response
191
- WB_INSTR_OTHER // Instruction doesn't fit into above categories
192
- } wb_instr_type_e;
193
- //////////////
194
- // ID stage //
195
- //////////////
196
- // Operand a selection
197
- typedef enum logic[1:0] {
198
- OP_A_REG_A,
199
- OP_A_FWD,
200
- OP_A_CURRPC,
201
- OP_A_IMM
202
- } op_a_sel_e;
203
- // Immediate a selection
204
- typedef enum logic {
205
- IMM_A_Z,
206
- IMM_A_ZERO
207
- } imm_a_sel_e;
208
- // Operand b selection
209
- typedef enum logic {
210
- OP_B_REG_B,
211
- OP_B_IMM
212
- } op_b_sel_e;
213
- // Immediate b selection
214
- typedef enum logic [2:0] {
215
- IMM_B_I,
216
- IMM_B_S,
217
- IMM_B_B,
218
- IMM_B_U,
219
- IMM_B_J,
220
- IMM_B_INCR_PC,
221
- IMM_B_INCR_ADDR
222
- } imm_b_sel_e;
223
- // Regfile write data selection
224
- typedef enum {
225
- RF_WD_EX,
226
- RF_WD_CSR,
227
- RF_WD_COPROC // Only used when XInterface = 1
228
- } rf_wd_sel_e;
229
- //////////////
230
- // IF stage //
231
- //////////////
232
- // PC mux selection
233
- typedef enum logic [2:0] {
234
- PC_BOOT,
235
- PC_JUMP,
236
- PC_EXC,
237
- PC_ERET,
238
- PC_DRET,
239
- PC_BP
240
- } pc_sel_e;
241
- // Exception PC mux selection
242
- typedef enum logic [1:0] {
243
- EXC_PC_EXC,
244
- EXC_PC_IRQ,
245
- EXC_PC_DBD,
246
- EXC_PC_DBG_EXC // Exception while in debug mode
247
- } exc_pc_sel_e;
248
- // Interrupt requests
249
- typedef struct packed {
250
- logic irq_software;
251
- logic irq_timer;
252
- logic irq_external;
253
- logic [15:0] irq_fast; // 16 fast interrupts
254
- } irqs_t;
255
- // Exception cause
256
- typedef enum logic [6:0] {
257
- EXC_CAUSE_IRQ_SOFTWARE_M = {1'b1, 6'd03},
258
- EXC_CAUSE_IRQ_TIMER_M = {1'b1, 6'd07},
259
- EXC_CAUSE_IRQ_EXTERNAL_M = {1'b1, 6'd11},
260
- // EXC_CAUSE_IRQ_FAST_0 = {1'b1, 6'd16},
261
- // EXC_CAUSE_IRQ_FAST_15 = {1'b1, 6'd31},
262
- EXC_CAUSE_IRQ_NM = {1'b1, 6'd32},
263
- EXC_CAUSE_INSN_ADDR_MISA = {1'b0, 6'd00},
264
- EXC_CAUSE_INSTR_ACCESS_FAULT = {1'b0, 6'd01},
265
- EXC_CAUSE_ILLEGAL_INSN = {1'b0, 6'd02},
266
- EXC_CAUSE_BREAKPOINT = {1'b0, 6'd03},
267
- EXC_CAUSE_LOAD_ACCESS_FAULT = {1'b0, 6'd05},
268
- EXC_CAUSE_STORE_ACCESS_FAULT = {1'b0, 6'd07},
269
- EXC_CAUSE_ECALL_UMODE = {1'b0, 6'd08},
270
- EXC_CAUSE_ECALL_MMODE = {1'b0, 6'd11}
271
- } exc_cause_e;
272
- // Debug cause
273
- typedef enum logic [2:0] {
274
- DBG_CAUSE_NONE = 3'h0,
275
- DBG_CAUSE_EBREAK = 3'h1,
276
- DBG_CAUSE_TRIGGER = 3'h2,
277
- DBG_CAUSE_HALTREQ = 3'h3,
278
- DBG_CAUSE_STEP = 3'h4
279
- } dbg_cause_e;
280
- // PMP constants
281
- parameter int unsigned PMP_MAX_REGIONS = 16;
282
- parameter int unsigned PMP_CFG_W = 8;
283
- // PMP acces type
284
- parameter int unsigned PMP_I = 0;
285
- parameter int unsigned PMP_I2 = 1;
286
- parameter int unsigned PMP_D = 2;
287
- typedef enum logic [1:0] {
288
- PMP_ACC_EXEC = 2'b00,
289
- PMP_ACC_WRITE = 2'b01,
290
- PMP_ACC_READ = 2'b10
291
- } pmp_req_e;
292
- // PMP cfg structures
293
- typedef enum logic [1:0] {
294
- PMP_MODE_OFF = 2'b00,
295
- PMP_MODE_TOR = 2'b01,
296
- PMP_MODE_NA4 = 2'b10,
297
- PMP_MODE_NAPOT = 2'b11
298
- } pmp_cfg_mode_e;
299
- typedef struct packed {
300
- logic lock;
301
- pmp_cfg_mode_e mode;
302
- logic exec;
303
- logic write;
304
- logic read;
305
- } pmp_cfg_t;
306
- // Machine Security Configuration (ePMP)
307
- typedef struct packed {
308
- logic rlb; // Rule Locking Bypass
309
- logic mmwp; // Machine Mode Whitelist Policy
310
- logic mml; // Machine Mode Lockdown
311
- } pmp_mseccfg_t;
312
- // CSRs
313
- typedef enum logic[11:0] {
314
- // Machine information
315
- CSR_MVENDORID = 12'hF11,
316
- CSR_MARCHID = 12'hF12,
317
- CSR_MIMPID = 12'hF13,
318
- CSR_MHARTID = 12'hF14,
319
- CSR_MCONFIGPTR = 12'hF15,
320
- // Machine trap setup
321
- CSR_MSTATUS = 12'h300,
322
- CSR_MISA = 12'h301,
323
- CSR_MIE = 12'h304,
324
- CSR_MTVEC = 12'h305,
325
- CSR_MCOUNTEREN= 12'h306,
326
- CSR_MSTATUSH = 12'h310,
327
- CSR_MENVCFG = 12'h30A,
328
- CSR_MENVCFGH = 12'h31A,
329
- // Machine trap handling
330
- CSR_MSCRATCH = 12'h340,
331
- CSR_MEPC = 12'h341,
332
- CSR_MCAUSE = 12'h342,
333
- CSR_MTVAL = 12'h343,
334
- CSR_MIP = 12'h344,
335
- // Physical memory protection
336
- CSR_PMPCFG0 = 12'h3A0,
337
- CSR_PMPCFG1 = 12'h3A1,
338
- CSR_PMPCFG2 = 12'h3A2,
339
- CSR_PMPCFG3 = 12'h3A3,
340
- CSR_PMPADDR0 = 12'h3B0,
341
- CSR_PMPADDR1 = 12'h3B1,
342
- CSR_PMPADDR2 = 12'h3B2,
343
- CSR_PMPADDR3 = 12'h3B3,
344
- CSR_PMPADDR4 = 12'h3B4,
345
- CSR_PMPADDR5 = 12'h3B5,
346
- CSR_PMPADDR6 = 12'h3B6,
347
- CSR_PMPADDR7 = 12'h3B7,
348
- CSR_PMPADDR8 = 12'h3B8,
349
- CSR_PMPADDR9 = 12'h3B9,
350
- CSR_PMPADDR10 = 12'h3BA,
351
- CSR_PMPADDR11 = 12'h3BB,
352
- CSR_PMPADDR12 = 12'h3BC,
353
- CSR_PMPADDR13 = 12'h3BD,
354
- CSR_PMPADDR14 = 12'h3BE,
355
- CSR_PMPADDR15 = 12'h3BF,
356
- // ePMP control
357
- CSR_MSECCFG = 12'h747,
358
- CSR_MSECCFGH = 12'h757,
359
- // Debug trigger
360
- CSR_TSELECT = 12'h7A0,
361
- CSR_TDATA1 = 12'h7A1,
362
- CSR_TDATA2 = 12'h7A2,
363
- CSR_TDATA3 = 12'h7A3,
364
- CSR_MCONTEXT = 12'h7A8,
365
- CSR_SCONTEXT = 12'h7AA,
366
- // Debug/trace
367
- CSR_DCSR = 12'h7b0,
368
- CSR_DPC = 12'h7b1,
369
- // Debug
370
- CSR_DSCRATCH0 = 12'h7b2, // optional
371
- CSR_DSCRATCH1 = 12'h7b3, // optional
372
- // Machine Counter/Timers
373
- CSR_MCOUNTINHIBIT = 12'h320,
374
- CSR_MHPMEVENT3 = 12'h323,
375
- CSR_MHPMEVENT4 = 12'h324,
376
- CSR_MHPMEVENT5 = 12'h325,
377
- CSR_MHPMEVENT6 = 12'h326,
378
- CSR_MHPMEVENT7 = 12'h327,
379
- CSR_MHPMEVENT8 = 12'h328,
380
- CSR_MHPMEVENT9 = 12'h329,
381
- CSR_MHPMEVENT10 = 12'h32A,
382
- CSR_MHPMEVENT11 = 12'h32B,
383
- CSR_MHPMEVENT12 = 12'h32C,
384
- CSR_MHPMEVENT13 = 12'h32D,
385
- CSR_MHPMEVENT14 = 12'h32E,
386
- CSR_MHPMEVENT15 = 12'h32F,
387
- CSR_MHPMEVENT16 = 12'h330,
388
- CSR_MHPMEVENT17 = 12'h331,
389
- CSR_MHPMEVENT18 = 12'h332,
390
- CSR_MHPMEVENT19 = 12'h333,
391
- CSR_MHPMEVENT20 = 12'h334,
392
- CSR_MHPMEVENT21 = 12'h335,
393
- CSR_MHPMEVENT22 = 12'h336,
394
- CSR_MHPMEVENT23 = 12'h337,
395
- CSR_MHPMEVENT24 = 12'h338,
396
- CSR_MHPMEVENT25 = 12'h339,
397
- CSR_MHPMEVENT26 = 12'h33A,
398
- CSR_MHPMEVENT27 = 12'h33B,
399
- CSR_MHPMEVENT28 = 12'h33C,
400
- CSR_MHPMEVENT29 = 12'h33D,
401
- CSR_MHPMEVENT30 = 12'h33E,
402
- CSR_MHPMEVENT31 = 12'h33F,
403
- CSR_MCYCLE = 12'hB00,
404
- CSR_MINSTRET = 12'hB02,
405
- CSR_MHPMCOUNTER3 = 12'hB03,
406
- CSR_MHPMCOUNTER4 = 12'hB04,
407
- CSR_MHPMCOUNTER5 = 12'hB05,
408
- CSR_MHPMCOUNTER6 = 12'hB06,
409
- CSR_MHPMCOUNTER7 = 12'hB07,
410
- CSR_MHPMCOUNTER8 = 12'hB08,
411
- CSR_MHPMCOUNTER9 = 12'hB09,
412
- CSR_MHPMCOUNTER10 = 12'hB0A,
413
- CSR_MHPMCOUNTER11 = 12'hB0B,
414
- CSR_MHPMCOUNTER12 = 12'hB0C,
415
- CSR_MHPMCOUNTER13 = 12'hB0D,
416
- CSR_MHPMCOUNTER14 = 12'hB0E,
417
- CSR_MHPMCOUNTER15 = 12'hB0F,
418
- CSR_MHPMCOUNTER16 = 12'hB10,
419
- CSR_MHPMCOUNTER17 = 12'hB11,
420
- CSR_MHPMCOUNTER18 = 12'hB12,
421
- CSR_MHPMCOUNTER19 = 12'hB13,
422
- CSR_MHPMCOUNTER20 = 12'hB14,
423
- CSR_MHPMCOUNTER21 = 12'hB15,
424
- CSR_MHPMCOUNTER22 = 12'hB16,
425
- CSR_MHPMCOUNTER23 = 12'hB17,
426
- CSR_MHPMCOUNTER24 = 12'hB18,
427
- CSR_MHPMCOUNTER25 = 12'hB19,
428
- CSR_MHPMCOUNTER26 = 12'hB1A,
429
- CSR_MHPMCOUNTER27 = 12'hB1B,
430
- CSR_MHPMCOUNTER28 = 12'hB1C,
431
- CSR_MHPMCOUNTER29 = 12'hB1D,
432
- CSR_MHPMCOUNTER30 = 12'hB1E,
433
- CSR_MHPMCOUNTER31 = 12'hB1F,
434
- CSR_MCYCLEH = 12'hB80,
435
- CSR_MINSTRETH = 12'hB82,
436
- CSR_MHPMCOUNTER3H = 12'hB83,
437
- CSR_MHPMCOUNTER4H = 12'hB84,
438
- CSR_MHPMCOUNTER5H = 12'hB85,
439
- CSR_MHPMCOUNTER6H = 12'hB86,
440
- CSR_MHPMCOUNTER7H = 12'hB87,
441
- CSR_MHPMCOUNTER8H = 12'hB88,
442
- CSR_MHPMCOUNTER9H = 12'hB89,
443
- CSR_MHPMCOUNTER10H = 12'hB8A,
444
- CSR_MHPMCOUNTER11H = 12'hB8B,
445
- CSR_MHPMCOUNTER12H = 12'hB8C,
446
- CSR_MHPMCOUNTER13H = 12'hB8D,
447
- CSR_MHPMCOUNTER14H = 12'hB8E,
448
- CSR_MHPMCOUNTER15H = 12'hB8F,
449
- CSR_MHPMCOUNTER16H = 12'hB90,
450
- CSR_MHPMCOUNTER17H = 12'hB91,
451
- CSR_MHPMCOUNTER18H = 12'hB92,
452
- CSR_MHPMCOUNTER19H = 12'hB93,
453
- CSR_MHPMCOUNTER20H = 12'hB94,
454
- CSR_MHPMCOUNTER21H = 12'hB95,
455
- CSR_MHPMCOUNTER22H = 12'hB96,
456
- CSR_MHPMCOUNTER23H = 12'hB97,
457
- CSR_MHPMCOUNTER24H = 12'hB98,
458
- CSR_MHPMCOUNTER25H = 12'hB99,
459
- CSR_MHPMCOUNTER26H = 12'hB9A,
460
- CSR_MHPMCOUNTER27H = 12'hB9B,
461
- CSR_MHPMCOUNTER28H = 12'hB9C,
462
- CSR_MHPMCOUNTER29H = 12'hB9D,
463
- CSR_MHPMCOUNTER30H = 12'hB9E,
464
- CSR_MHPMCOUNTER31H = 12'hB9F,
465
- CSR_CPUCTRL = 12'h7C0,
466
- CSR_SECURESEED = 12'h7C1
467
- } csr_num_e;
468
- // CSR pmp-related offsets
469
- parameter logic [11:0] CSR_OFF_PMP_CFG = 12'h3A0; // pmp_cfg @ 12'h3a0 - 12'h3a3
470
- parameter logic [11:0] CSR_OFF_PMP_ADDR = 12'h3B0; // pmp_addr @ 12'h3b0 - 12'h3bf
471
- // CSR status bits
472
- parameter int unsigned CSR_MSTATUS_MIE_BIT = 3;
473
- parameter int unsigned CSR_MSTATUS_MPIE_BIT = 7;
474
- parameter int unsigned CSR_MSTATUS_MPP_BIT_LOW = 11;
475
- parameter int unsigned CSR_MSTATUS_MPP_BIT_HIGH = 12;
476
- parameter int unsigned CSR_MSTATUS_MPRV_BIT = 17;
477
- parameter int unsigned CSR_MSTATUS_TW_BIT = 21;
478
- // CSR machine ISA
479
- parameter logic [1:0] CSR_MISA_MXL = 2'd1; // M-XLEN: XLEN in M-Mode for RV32
480
- // CSR interrupt pending/enable bits
481
- parameter int unsigned CSR_MSIX_BIT = 3;
482
- parameter int unsigned CSR_MTIX_BIT = 7;
483
- parameter int unsigned CSR_MEIX_BIT = 11;
484
- parameter int unsigned CSR_MFIX_BIT_LOW = 16;
485
- parameter int unsigned CSR_MFIX_BIT_HIGH = 31;
486
- // CSR Machine Security Configuration bits
487
- parameter int unsigned CSR_MSECCFG_MML_BIT = 0;
488
- parameter int unsigned CSR_MSECCFG_MMWP_BIT = 1;
489
- parameter int unsigned CSR_MSECCFG_RLB_BIT = 2;
490
- // Machine Vendor ID - OpenHW JEDEC ID is '2 decimal (bank 13)'
491
- parameter MVENDORID_OFFSET = 7'h2; // Final byte without parity bit
492
- parameter MVENDORID_BANK = 25'hC; // Number of continuation codes
493
- // Machine Architecture ID (https://github.com/riscv/riscv-isa-manual/blob/master/marchid.md)
494
- parameter MARCHID = 32'd35;
495
- localparam logic [31:0] CSR_MVENDORID_VALUE = {MVENDORID_BANK, MVENDORID_OFFSET};
496
- localparam logic [31:0] CSR_MARCHID_VALUE = MARCHID;
497
- // Implementation ID
498
- // 0 indicates this field is not implemeted. cve2 implementors may wish to indicate an RTL/netlist
499
- // version here using their own unique encoding (e.g. 32 bits of the git hash of the implemented
500
- // commit).
501
- localparam logic [31:0] CSR_MIMPID_VALUE = 32'b0;
502
- // Machine Configuration Pointer
503
- // 0 indicates the configuration data structure does not eixst. cve2 implementors may wish to
504
- // alter this to point to their system specific configuration data structure.
505
- localparam logic [31:0] CSR_MCONFIGPTR_VALUE = 32'b0;
506
- // RVFI CSR element
507
- typedef struct packed {
508
- bit [63:0] rdata;
509
- bit [63:0] rmask;
510
- bit [63:0] wdata;
511
- bit [63:0] wmask;
512
- } rvfi_csr_elmt_t;
513
- // RVFI CSR structure
514
- typedef struct packed {
515
- rvfi_csr_elmt_t fflags;
516
- rvfi_csr_elmt_t frm;
517
- rvfi_csr_elmt_t fcsr;
518
- rvfi_csr_elmt_t ftran;
519
- rvfi_csr_elmt_t dcsr;
520
- rvfi_csr_elmt_t dpc;
521
- rvfi_csr_elmt_t dscratch0;
522
- rvfi_csr_elmt_t dscratch1;
523
- rvfi_csr_elmt_t sstatus;
524
- rvfi_csr_elmt_t sie;
525
- rvfi_csr_elmt_t sip;
526
- rvfi_csr_elmt_t stvec;
527
- rvfi_csr_elmt_t scounteren;
528
- rvfi_csr_elmt_t sscratch;
529
- rvfi_csr_elmt_t sepc;
530
- rvfi_csr_elmt_t scause;
531
- rvfi_csr_elmt_t stval;
532
- rvfi_csr_elmt_t satp;
533
- rvfi_csr_elmt_t mstatus;
534
- rvfi_csr_elmt_t mstatush;
535
- rvfi_csr_elmt_t misa;
536
- rvfi_csr_elmt_t medeleg;
537
- rvfi_csr_elmt_t mideleg;
538
- rvfi_csr_elmt_t mie;
539
- rvfi_csr_elmt_t mtvec;
540
- rvfi_csr_elmt_t mcounteren;
541
- rvfi_csr_elmt_t mscratch;
542
- rvfi_csr_elmt_t mepc;
543
- rvfi_csr_elmt_t mcause;
544
- rvfi_csr_elmt_t mtval;
545
- rvfi_csr_elmt_t mip;
546
- rvfi_csr_elmt_t menvcfg;
547
- rvfi_csr_elmt_t menvcfgh;
548
- rvfi_csr_elmt_t mvendorid;
549
- rvfi_csr_elmt_t marchid;
550
- rvfi_csr_elmt_t mhartid;
551
- rvfi_csr_elmt_t mcountinhibit;
552
- rvfi_csr_elmt_t mcycle;
553
- rvfi_csr_elmt_t mcycleh;
554
- rvfi_csr_elmt_t minstret;
555
- rvfi_csr_elmt_t minstreth;
556
- rvfi_csr_elmt_t cycle;
557
- rvfi_csr_elmt_t cycleh;
558
- rvfi_csr_elmt_t instret;
559
- rvfi_csr_elmt_t instreth;
560
- rvfi_csr_elmt_t dcache;
561
- rvfi_csr_elmt_t icache;
562
- rvfi_csr_elmt_t acc_cons;
563
- rvfi_csr_elmt_t pmpcfg0;
564
- rvfi_csr_elmt_t pmpcfg1;
565
- rvfi_csr_elmt_t pmpcfg2;
566
- rvfi_csr_elmt_t pmpcfg3;
567
- rvfi_csr_elmt_t pmpaddr0;
568
- rvfi_csr_elmt_t pmpaddr1;
569
- rvfi_csr_elmt_t pmpaddr2;
570
- rvfi_csr_elmt_t pmpaddr3;
571
- rvfi_csr_elmt_t pmpaddr4;
572
- rvfi_csr_elmt_t pmpaddr5;
573
- rvfi_csr_elmt_t pmpaddr6;
574
- rvfi_csr_elmt_t pmpaddr7;
575
- rvfi_csr_elmt_t pmpaddr8;
576
- rvfi_csr_elmt_t pmpaddr9;
577
- rvfi_csr_elmt_t pmpaddr10;
578
- rvfi_csr_elmt_t pmpaddr11;
579
- rvfi_csr_elmt_t pmpaddr12;
580
- rvfi_csr_elmt_t pmpaddr13;
581
- rvfi_csr_elmt_t pmpaddr14;
582
- rvfi_csr_elmt_t pmpaddr15;
583
- } rvfi_csr_t;
584
- // CV-X-IF
585
- parameter int unsigned X_NUM_RS = 3;
586
- parameter int unsigned X_ID_WIDTH = 4;
587
- parameter int unsigned X_RFR_WIDTH = 32;
588
- parameter int unsigned X_RFW_WIDTH = 32;
589
- parameter int unsigned X_HARTID_WIDTH = 32;
590
- parameter int unsigned X_DUAL_READ = 0;
591
- parameter int unsigned X_DUAL_WRITE = 0;
592
- parameter int unsigned X_INSTR_INFLIGHT = 2**X_ID_WIDTH;
593
- typedef logic [X_NUM_RS+X_DUAL_READ-1:0] readregflags_t;
594
- typedef logic [X_DUAL_WRITE:0] writeregflags_t;
595
- typedef logic [X_ID_WIDTH-1:0] id_t;
596
- typedef logic [X_HARTID_WIDTH-1:0] hartid_t;
597
- // Issue Interface
598
- typedef struct packed {
599
- logic [31:0] instr;
600
- hartid_t hartid;
601
- id_t id;
602
- } x_issue_req_t;
603
- typedef struct packed {
604
- logic accept;
605
- writeregflags_t writeback;
606
- readregflags_t register_read;
607
- } x_issue_resp_t;
608
- // Register Interface
609
- typedef struct packed {
610
- hartid_t hartid;
611
- id_t id;
612
- logic [X_NUM_RS-1:0][X_RFR_WIDTH-1:0] rs;
613
- readregflags_t rs_valid;
614
- } x_register_t;
615
- // Commit Interface
616
- typedef struct packed {
617
- hartid_t hartid;
618
- id_t id;
619
- logic commit_kill;
620
- } x_commit_t;
621
- // Result Interface
622
- typedef struct packed {
623
- hartid_t hartid;
624
- id_t id;
625
- logic [X_RFW_WIDTH-1:0] data;
626
- logic [4:0] rd;
627
- writeregflags_t we;
628
- } x_result_t;
629
- endpackage
630
- // Copyright (c) 2025 Eclipse Foundation
631
- // Copyright lowRISC contributors.
632
- // Copyright 2018 ETH Zurich and University of Bologna, see also CREDITS.md.
633
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
634
- // SPDX-License-Identifier: Apache-2.0
635
- /**
636
- * Arithmetic logic unit
637
- */
638
- module cve2_alu #(
639
- parameter cve2_pkg::rv32b_e RV32B = cve2_pkg::RV32BNone
640
- ) (
641
- input cve2_pkg::alu_op_e operator_i,
642
- input logic [31:0] operand_a_i,
643
- input logic [31:0] operand_b_i,
644
- input logic instr_first_cycle_i,
645
- input logic [32:0] multdiv_operand_a_i,
646
- input logic [32:0] multdiv_operand_b_i,
647
- input logic multdiv_sel_i,
648
- input logic [31:0] imd_val_q_i[2],
649
- output logic [31:0] imd_val_d_o[2],
650
- output logic [1:0] imd_val_we_o,
651
- output logic [31:0] adder_result_o,
652
- output logic [33:0] adder_result_ext_o,
653
- output logic [31:0] result_o,
654
- output logic comparison_result_o,
655
- output logic is_equal_result_o
656
- );
657
- import cve2_pkg::*;
658
- logic [31:0] operand_a_rev;
659
- logic [32:0] operand_b_neg;
660
- // bit reverse operand_a for left shifts and bit counting
661
- for (genvar k = 0; k < 32; k++) begin : gen_rev_operand_a
662
- assign operand_a_rev[k] = operand_a_i[31-k];
663
- end
664
- ///////////
665
- // Adder //
666
- ///////////
667
- logic adder_op_a_shift1;
668
- logic adder_op_a_shift2;
669
- logic adder_op_a_shift3;
670
- logic adder_op_b_negate;
671
- logic [32:0] adder_in_a, adder_in_b;
672
- logic [31:0] adder_result;
673
- always_comb begin
674
- adder_op_a_shift1 = 1'b0;
675
- adder_op_a_shift2 = 1'b0;
676
- adder_op_a_shift3 = 1'b0;
677
- adder_op_b_negate = 1'b0;
678
- unique case (operator_i)
679
- // Adder OPs
680
- ALU_SUB,
681
- // Comparator OPs
682
- ALU_EQ, ALU_NE,
683
- ALU_GE, ALU_GEU,
684
- ALU_LT, ALU_LTU,
685
- ALU_SLT, ALU_SLTU,
686
- // MinMax OPs (RV32B Ops)
687
- ALU_MIN, ALU_MINU,
688
- ALU_MAX, ALU_MAXU: adder_op_b_negate = 1'b1;
689
- // Address Calculation OPs (RV32B Ops)
690
- ALU_SH1ADD: if (RV32B != RV32BNone) adder_op_a_shift1 = 1'b1;
691
- ALU_SH2ADD: if (RV32B != RV32BNone) adder_op_a_shift2 = 1'b1;
692
- ALU_SH3ADD: if (RV32B != RV32BNone) adder_op_a_shift3 = 1'b1;
693
- default:;
694
- endcase
695
- end
696
- // prepare operand a
697
- always_comb begin
698
- unique case(1'b1)
699
- multdiv_sel_i: adder_in_a = multdiv_operand_a_i;
700
- adder_op_a_shift1: adder_in_a = {operand_a_i[30:0],2'b01};
701
- adder_op_a_shift2: adder_in_a = {operand_a_i[29:0],3'b001};
702
- adder_op_a_shift3: adder_in_a = {operand_a_i[28:0],4'b0001};
703
- default: adder_in_a = {operand_a_i,1'b1};
704
- endcase
705
- end
706
- // prepare operand b
707
- assign operand_b_neg = {operand_b_i,1'b0} ^ {33{1'b1}};
708
- always_comb begin
709
- unique case (1'b1)
710
- multdiv_sel_i: adder_in_b = multdiv_operand_b_i;
711
- adder_op_b_negate: adder_in_b = operand_b_neg;
712
- default: adder_in_b = {operand_b_i, 1'b0};
713
- endcase
714
- end
715
- // actual adder
716
- assign adder_result_ext_o = $unsigned(adder_in_a) + $unsigned(adder_in_b);
717
- assign adder_result = adder_result_ext_o[32:1];
718
- assign adder_result_o = adder_result;
719
- ////////////////
720
- // Comparison //
721
- ////////////////
722
- logic is_equal;
723
- logic is_greater_equal; // handles both signed and unsigned forms
724
- logic cmp_signed;
725
- always_comb begin
726
- unique case (operator_i)
727
- ALU_GE,
728
- ALU_LT,
729
- ALU_SLT,
730
- // RV32B only
731
- ALU_MIN,
732
- ALU_MAX: cmp_signed = 1'b1;
733
- default: cmp_signed = 1'b0;
734
- endcase
735
- end
736
- assign is_equal = (adder_result == 32'b0);
737
- assign is_equal_result_o = is_equal;
738
- // Is greater equal
739
- always_comb begin
740
- if ((operand_a_i[31] ^ operand_b_i[31]) == 1'b0) begin
741
- is_greater_equal = (adder_result[31] == 1'b0);
742
- end else begin
743
- is_greater_equal = operand_a_i[31] ^ (cmp_signed);
744
- end
745
- end
746
- // GTE unsigned:
747
- // (a[31] == 1 && b[31] == 1) => adder_result[31] == 0
748
- // (a[31] == 0 && b[31] == 0) => adder_result[31] == 0
749
- // (a[31] == 1 && b[31] == 0) => 1
750
- // (a[31] == 0 && b[31] == 1) => 0
751
- // GTE signed:
752
- // (a[31] == 1 && b[31] == 1) => adder_result[31] == 0
753
- // (a[31] == 0 && b[31] == 0) => adder_result[31] == 0
754
- // (a[31] == 1 && b[31] == 0) => 0
755
- // (a[31] == 0 && b[31] == 1) => 1
756
- // generate comparison result
757
- logic cmp_result;
758
- always_comb begin
759
- unique case (operator_i)
760
- ALU_EQ: cmp_result = is_equal;
761
- ALU_NE: cmp_result = ~is_equal;
762
- ALU_GE, ALU_GEU,
763
- ALU_MAX, ALU_MAXU: cmp_result = is_greater_equal; // RV32B only
764
- ALU_LT, ALU_LTU,
765
- ALU_MIN, ALU_MINU, //RV32B only
766
- ALU_SLT, ALU_SLTU: cmp_result = ~is_greater_equal;
767
- default: cmp_result = is_equal;
768
- endcase
769
- end
770
- assign comparison_result_o = cmp_result;
771
- ///////////
772
- // Shift //
773
- ///////////
774
- // The shifter structure consists of a 33-bit shifter: 32-bit operand + 1 bit extension for
775
- // arithmetic shifts and one-shift support.
776
- // Rotations and funnel shifts are implemented as multi-cycle instructions.
777
- // The shifter is also used for single-bit instructions and bit-field place as detailed below.
778
- //
779
- // Standard Shifts
780
- // ===============
781
- // For standard shift instructions, the direction of the shift is to the right by default. For
782
- // left shifts, the signal shift_left signal is set. If so, the operand is initially reversed,
783
- // shifted to the right by the specified amount and shifted back again. For arithmetic- and
784
- // one-shifts the 33rd bit of the shifter operand can is set accordingly.
785
- //
786
- // Multicycle Shifts
787
- // =================
788
- //
789
- // Rotation
790
- // --------
791
- // For rotations, the operand signals operand_a_i and operand_b_i are kept constant to rs1 and
792
- // rs2 respectively.
793
- //
794
- // Rotation pseudocode:
795
- // shift_amt = rs2 & 31;
796
- // multicycle_result = (rs1 >> shift_amt) | (rs1 << (32 - shift_amt));
797
- // ^-- cycle 0 -----^ ^-- cycle 1 --------------^
798
- //
799
- // Funnel Shifts
800
- // -------------
801
- // For funnel shifs, operand_a_i is tied to rs1 in the first cycle and rs3 in the
802
- // second cycle. operand_b_i is always tied to rs2. The order of applying the shift amount or
803
- // its complement is determined by bit [5] of shift_amt.
804
- //
805
- // Funnel shift Pseudocode: (fsl)
806
- // shift_amt = rs2 & 63;
807
- // shift_amt_compl = 32 - shift_amt[4:0]
808
- // if (shift_amt >=33):
809
- // multicycle_result = (rs1 >> shift_amt_compl[4:0]) | (rs3 << shift_amt[4:0]);
810
- // ^-- cycle 0 ----------------^ ^-- cycle 1 ------------^
811
- // else if (shift_amt <= 31 && shift_amt > 0):
812
- // multicycle_result = (rs1 << shift_amt[4:0]) | (rs3 >> shift_amt_compl[4:0]);
813
- // ^-- cycle 0 ----------^ ^-- cycle 1 -------------------^
814
- // For shift_amt == 0, 32, both shift_amt[4:0] and shift_amt_compl[4:0] == '0.
815
- // these cases need to be handled separately outside the shifting structure:
816
- // else if (shift_amt == 32):
817
- // multicycle_result = rs3
818
- // else if (shift_amt == 0):
819
- // multicycle_result = rs1.
820
- //
821
- // Single-Bit Instructions
822
- // =======================
823
- // Single bit instructions operate on bit operand_b_i[4:0] of operand_a_i.
824
- // The operations bset, bclr and binv are implemented by generation of a bit-mask using the
825
- // shifter structure. This is done by left-shifting the operand 32'h1 by the required amount.
826
- // The signal shift_sbmode multiplexes the shifter input and sets the signal shift_left.
827
- // Further processing is taken care of by a separate structure.
828
- //
829
- // For bext, the bit defined by operand_b_i[4:0] is to be returned. This is done by simply
830
- // shifting operand_a_i to the right by the required amount and returning bit [0] of the result.
831
- //
832
- // Bit-Field Place
833
- // ===============
834
- // The shifter structure is shared to compute bfp_mask << bfp_off.
835
- logic shift_left;
836
- logic shift_ones;
837
- logic shift_arith;
838
- logic shift_funnel;
839
- logic shift_sbmode;
840
- logic [5:0] shift_amt;
841
- logic [5:0] shift_amt_compl; // complementary shift amount (32 - shift_amt)
842
- logic [31:0] shift_operand;
843
- logic signed [32:0] shift_result_ext_signed;
844
- logic [32:0] shift_result_ext;
845
- logic unused_shift_result_ext;
846
- logic [31:0] shift_result;
847
- logic [31:0] shift_result_rev;
848
- // zbf
849
- logic bfp_op;
850
- logic [4:0] bfp_len;
851
- logic [4:0] bfp_off;
852
- logic [31:0] bfp_mask;
853
- logic [31:0] bfp_mask_rev;
854
- logic [31:0] bfp_result;
855
- // bfp: shares the shifter structure to compute bfp_mask << bfp_off
856
- assign bfp_op = (RV32B != RV32BNone) ? (operator_i == ALU_BFP) : 1'b0;
857
- assign bfp_len = {~(|operand_b_i[27:24]), operand_b_i[27:24]}; // len = 0 encodes for len = 16
858
- assign bfp_off = operand_b_i[20:16];
859
- assign bfp_mask = (RV32B != RV32BNone) ? ~(32'hffff_ffff << bfp_len) : '0;
860
- for (genvar i = 0; i < 32; i++) begin : gen_rev_bfp_mask
861
- assign bfp_mask_rev[i] = bfp_mask[31-i];
862
- end
863
- assign bfp_result =(RV32B != RV32BNone) ?
864
- (~shift_result & operand_a_i) | ((operand_b_i & bfp_mask) << bfp_off) : '0;
865
- // bit shift_amt[5]: word swap bit: only considered for FSL/FSR.
866
- // if set, reverse operations in first and second cycle.
867
- assign shift_amt[5] = operand_b_i[5] & shift_funnel;
868
- assign shift_amt_compl = 32 - operand_b_i[4:0];
869
- always_comb begin
870
- if (bfp_op) begin
871
- shift_amt[4:0] = bfp_off; // length field of bfp control word
872
- end else begin
873
- shift_amt[4:0] = instr_first_cycle_i ?
874
- (operand_b_i[5] && shift_funnel ? shift_amt_compl[4:0] : operand_b_i[4:0]) :
875
- (operand_b_i[5] && shift_funnel ? operand_b_i[4:0] : shift_amt_compl[4:0]);
876
- end
877
- end
878
- // single-bit mode: shift
879
- assign shift_sbmode = (RV32B != RV32BNone) ?
880
- (operator_i == ALU_BSET) | (operator_i == ALU_BCLR) | (operator_i == ALU_BINV) : 1'b0;
881
- // left shift if this is:
882
- // * a standard left shift (slo, sll)
883
- // * a rol in the first cycle
884
- // * a ror in the second cycle
885
- // * fsl: without word-swap bit: first cycle, else: second cycle
886
- // * fsr: without word-swap bit: second cycle, else: first cycle
887
- // * a single-bit instruction: bclr, bset, binv (excluding bext)
888
- // * bfp: bfp_mask << bfp_off
889
- always_comb begin
890
- unique case (operator_i)
891
- ALU_SLL: shift_left = 1'b1;
892
- ALU_SLO: shift_left = (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) ? 1'b1 : 1'b0;
893
- ALU_BFP: shift_left = (RV32B != RV32BNone) ? 1'b1 : 1'b0;
894
- ALU_ROL: shift_left = (RV32B != RV32BNone) ? instr_first_cycle_i : 0;
895
- ALU_ROR: shift_left = (RV32B != RV32BNone) ? ~instr_first_cycle_i : 0;
896
- ALU_FSL: shift_left = (RV32B != RV32BNone) ?
897
- (shift_amt[5] ? ~instr_first_cycle_i : instr_first_cycle_i) : 1'b0;
898
- ALU_FSR: shift_left = (RV32B != RV32BNone) ?
899
- (shift_amt[5] ? instr_first_cycle_i : ~instr_first_cycle_i) : 1'b0;
900
- default: shift_left = 1'b0;
901
- endcase
902
- if (shift_sbmode) begin
903
- shift_left = 1'b1;
904
- end
905
- end
906
- assign shift_arith = (operator_i == ALU_SRA);
907
- assign shift_ones = (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) ?
908
- (operator_i == ALU_SLO) | (operator_i == ALU_SRO) : 1'b0;
909
- assign shift_funnel = (RV32B != RV32BNone) ?
910
- (operator_i == ALU_FSL) | (operator_i == ALU_FSR) : 1'b0;
911
- // shifter structure.
912
- always_comb begin
913
- // select shifter input
914
- // for bfp, sbmode and shift_left the corresponding bit-reversed input is chosen.
915
- if (RV32B == RV32BNone) begin
916
- shift_operand = shift_left ? operand_a_rev : operand_a_i;
917
- end else begin
918
- unique case (1'b1)
919
- bfp_op: shift_operand = bfp_mask_rev;
920
- shift_sbmode: shift_operand = 32'h8000_0000;
921
- default: shift_operand = shift_left ? operand_a_rev : operand_a_i;
922
- endcase
923
- end
924
- shift_result_ext_signed =
925
- $signed({shift_ones | (shift_arith & shift_operand[31]), shift_operand}) >>> shift_amt[4:0];
926
- shift_result_ext = $unsigned(shift_result_ext_signed);
927
- shift_result = shift_result_ext[31:0];
928
- unused_shift_result_ext = shift_result_ext[32];
929
- for (int unsigned i = 0; i < 32; i++) begin
930
- shift_result_rev[i] = shift_result[31-i];
931
- end
932
- shift_result = shift_left ? shift_result_rev : shift_result;
933
- end
934
- ///////////////////
935
- // Bitwise Logic //
936
- ///////////////////
937
- logic bwlogic_or;
938
- logic bwlogic_and;
939
- logic [31:0] bwlogic_operand_b;
940
- logic [31:0] bwlogic_or_result;
941
- logic [31:0] bwlogic_and_result;
942
- logic [31:0] bwlogic_xor_result;
943
- logic [31:0] bwlogic_result;
944
- logic bwlogic_op_b_negate;
945
- always_comb begin
946
- unique case (operator_i)
947
- // Logic-with-negate OPs (RV32B Ops)
948
- ALU_XNOR,
949
- ALU_ORN,
950
- ALU_ANDN: bwlogic_op_b_negate = (RV32B != RV32BNone) ? 1'b1 : 1'b0;
951
- ALU_CMIX: bwlogic_op_b_negate = (RV32B != RV32BNone) ? ~instr_first_cycle_i : 1'b0;
952
- default: bwlogic_op_b_negate = 1'b0;
953
- endcase
954
- end
955
- assign bwlogic_operand_b = bwlogic_op_b_negate ? operand_b_neg[32:1] : operand_b_i;
956
- assign bwlogic_or_result = operand_a_i | bwlogic_operand_b;
957
- assign bwlogic_and_result = operand_a_i & bwlogic_operand_b;
958
- assign bwlogic_xor_result = operand_a_i ^ bwlogic_operand_b;
959
- assign bwlogic_or = (operator_i == ALU_OR) | (operator_i == ALU_ORN);
960
- assign bwlogic_and = (operator_i == ALU_AND) | (operator_i == ALU_ANDN);
961
- always_comb begin
962
- unique case (1'b1)
963
- bwlogic_or: bwlogic_result = bwlogic_or_result;
964
- bwlogic_and: bwlogic_result = bwlogic_and_result;
965
- default: bwlogic_result = bwlogic_xor_result;
966
- endcase
967
- end
968
- logic [5:0] bitcnt_result;
969
- logic [31:0] minmax_result;
970
- logic [31:0] pack_result;
971
- logic [31:0] sext_result;
972
- logic [31:0] singlebit_result;
973
- logic [31:0] rev_result;
974
- logic [31:0] shuffle_result;
975
- logic [31:0] xperm_result;
976
- logic [31:0] butterfly_result;
977
- logic [31:0] invbutterfly_result;
978
- logic [31:0] clmul_result;
979
- logic [31:0] multicycle_result;
980
- if (RV32B != RV32BNone) begin : g_alu_rvb
981
- /////////////////
982
- // Bitcounting //
983
- /////////////////
984
- // The bit-counter structure computes the number of set bits in its operand. Partial results
985
- // (from left to right) are needed to compute the control masks for computation of
986
- // bcompress/bdecompress by the butterfly network, if implemented.
987
- // For cpop, clz and ctz, only the end result is used.
988
- logic zbe_op;
989
- logic bitcnt_ctz;
990
- logic bitcnt_clz;
991
- logic bitcnt_cz;
992
- logic [31:0] bitcnt_bits;
993
- logic [31:0] bitcnt_mask_op;
994
- logic [31:0] bitcnt_bit_mask;
995
- logic [ 5:0] bitcnt_partial [32];
996
- logic [31:0] bitcnt_partial_lsb_d;
997
- logic [31:0] bitcnt_partial_msb_d;
998
- assign bitcnt_ctz = operator_i == ALU_CTZ;
999
- assign bitcnt_clz = operator_i == ALU_CLZ;
1000
- assign bitcnt_cz = bitcnt_ctz | bitcnt_clz;
1001
- assign bitcnt_result = bitcnt_partial[31];
1002
- // Bit-mask generation for clz and ctz:
1003
- // The bit mask is generated by spreading the lowest-order set bit in the operand to all
1004
- // higher order bits. The resulting mask is inverted to cover the lowest order zeros. In order
1005
- // to create the bit mask for leading zeros, the input operand needs to be reversed.
1006
- assign bitcnt_mask_op = bitcnt_clz ? operand_a_rev : operand_a_i;
1007
- always_comb begin
1008
- bitcnt_bit_mask = bitcnt_mask_op;
1009
- bitcnt_bit_mask |= bitcnt_bit_mask << 1;
1010
- bitcnt_bit_mask |= bitcnt_bit_mask << 2;
1011
- bitcnt_bit_mask |= bitcnt_bit_mask << 4;
1012
- bitcnt_bit_mask |= bitcnt_bit_mask << 8;
1013
- bitcnt_bit_mask |= bitcnt_bit_mask << 16;
1014
- bitcnt_bit_mask = ~bitcnt_bit_mask;
1015
- end
1016
- assign zbe_op = (operator_i == ALU_BCOMPRESS) | (operator_i == ALU_BDECOMPRESS);
1017
- always_comb begin
1018
- case (1'b1)
1019
- zbe_op: bitcnt_bits = operand_b_i;
1020
- bitcnt_cz: bitcnt_bits = bitcnt_bit_mask & ~bitcnt_mask_op; // clz / ctz
1021
- default: bitcnt_bits = operand_a_i; // cpop
1022
- endcase
1023
- end
1024
- // The parallel prefix counter is of the structure of a Brent-Kung Adder. In the first
1025
- // log2(width) stages, the sum of the n preceding bit lines is computed for the bit lines at
1026
- // positions 2**n-1 (power-of-two positions) where n denotes the current stage.
1027
- // In stage n=log2(width), the count for position width-1 (the MSB) is finished.
1028
- // For the intermediate values, an inverse adder tree then computes the bit counts for the bit
1029
- // lines at positions
1030
- // m = 2**(n-1) + i*2**(n-2), where i = [1 ... width / 2**(n-1)-1] and n = [log2(width) ... 2].
1031
- // Thus, at every subsequent stage the result of two previously unconnected sub-trees is
1032
- // summed, starting at the node summing bits [width/2-1 : 0] and [3*width/4-1: width/2]
1033
- // and moving to iteratively sum up all the sub-trees.
1034
- // The inverse adder tree thus features log2(width) - 1 stages the first of these stages is a
1035
- // single addition at position 3*width/4 - 1. It does not interfere with the last
1036
- // stage of the primary adder tree. These stages can thus be folded together, resulting in a
1037
- // total of 2*log2(width)-2 stages.
1038
- // For more details refer to R. Brent, H. T. Kung, "A Regular Layout for Parallel Adders",
1039
- // (1982).
1040
- // For a bitline at position p, only bits
1041
- // bitcnt_partial[max(i, such that p % log2(i) == 0)-1 : 0] are needed for generation of the
1042
- // butterfly network control signals. The adders in the intermediate value adder tree thus need
1043
- // not be full 5-bit adders. We leave the optimization to the synthesis tools.
1044
- //
1045
- // Consider the following 8-bit example for illustraton.
1046
- //
1047
- // let bitcnt_bits = 8'babcdefgh.
1048
- //
1049
- // a b c d e f g h
1050
- // | /: | /: | /: | /:
1051
- // |/ : |/ : |/ : |/ :
1052
- // stage 1: + : + : + : + :
1053
- // | : /: : | : /: :
1054
- // |,--+ : : |,--+ : :
1055
- // stage 2: + : : : + : : :
1056
- // | : | : /: : : :
1057
- // |,-----,--+ : : : : ^-primary adder tree
1058
- // stage 3: + : + : : : : : -------------------------
1059
- // : | /| /| /| /| /| : ,-intermediate adder tree
1060
- // : |/ |/ |/ |/ |/ : :
1061
- // stage 4 : + + + + + : :
1062
- // : : : : : : : :
1063
- // bitcnt_partial[i] 7 6 5 4 3 2 1 0
1064
- always_comb begin
1065
- bitcnt_partial = '{default: '0};
1066
- // stage 1
1067
- for (int unsigned i = 1; i < 32; i += 2) begin
1068
- bitcnt_partial[i] = {5'h0, bitcnt_bits[i]} + {5'h0, bitcnt_bits[i-1]};
1069
- end
1070
- // stage 2
1071
- for (int unsigned i = 3; i < 32; i += 4) begin
1072
- bitcnt_partial[i] = bitcnt_partial[i-2] + bitcnt_partial[i];
1073
- end
1074
- // stage 3
1075
- for (int unsigned i = 7; i < 32; i += 8) begin
1076
- bitcnt_partial[i] = bitcnt_partial[i-4] + bitcnt_partial[i];
1077
- end
1078
- // stage 4
1079
- for (int unsigned i = 15; i < 32; i += 16) begin
1080
- bitcnt_partial[i] = bitcnt_partial[i-8] + bitcnt_partial[i];
1081
- end
1082
- // stage 5
1083
- bitcnt_partial[31] = bitcnt_partial[15] + bitcnt_partial[31];
1084
- // ^- primary adder tree
1085
- // -------------------------------
1086
- // ,-intermediate value adder tree
1087
- bitcnt_partial[23] = bitcnt_partial[15] + bitcnt_partial[23];
1088
- // stage 6
1089
- for (int unsigned i = 11; i < 32; i += 8) begin
1090
- bitcnt_partial[i] = bitcnt_partial[i-4] + bitcnt_partial[i];
1091
- end
1092
- // stage 7
1093
- for (int unsigned i = 5; i < 32; i += 4) begin
1094
- bitcnt_partial[i] = bitcnt_partial[i-2] + bitcnt_partial[i];
1095
- end
1096
- // stage 8
1097
- bitcnt_partial[0] = {5'h0, bitcnt_bits[0]};
1098
- for (int unsigned i = 2; i < 32; i += 2) begin
1099
- bitcnt_partial[i] = bitcnt_partial[i-1] + {5'h0, bitcnt_bits[i]};
1100
- end
1101
- end
1102
- ///////////////
1103
- // Min / Max //
1104
- ///////////////
1105
- assign minmax_result = cmp_result ? operand_a_i : operand_b_i;
1106
- //////////
1107
- // Pack //
1108
- //////////
1109
- logic packu;
1110
- logic packh;
1111
- assign packu = operator_i == ALU_PACKU;
1112
- assign packh = operator_i == ALU_PACKH;
1113
- always_comb begin
1114
- unique case (1'b1)
1115
- packu: pack_result = {operand_b_i[31:16], operand_a_i[31:16]};
1116
- packh: pack_result = {16'h0, operand_b_i[7:0], operand_a_i[7:0]};
1117
- default: pack_result = {operand_b_i[15:0], operand_a_i[15:0]};
1118
- endcase
1119
- end
1120
- //////////
1121
- // Sext //
1122
- //////////
1123
- assign sext_result = (operator_i == ALU_SEXTB) ?
1124
- { {24{operand_a_i[7]}}, operand_a_i[7:0]} : { {16{operand_a_i[15]}}, operand_a_i[15:0]};
1125
- /////////////////////////////
1126
- // Single-bit Instructions //
1127
- /////////////////////////////
1128
- always_comb begin
1129
- unique case (operator_i)
1130
- ALU_BSET: singlebit_result = operand_a_i | shift_result;
1131
- ALU_BCLR: singlebit_result = operand_a_i & ~shift_result;
1132
- ALU_BINV: singlebit_result = operand_a_i ^ shift_result;
1133
- default: singlebit_result = {31'h0, shift_result[0]}; // ALU_BEXT
1134
- endcase
1135
- end
1136
- ////////////////////////////////////
1137
- // General Reverse and Or-combine //
1138
- ////////////////////////////////////
1139
- // Only a subset of the general reverse and or-combine instructions are implemented in the
1140
- // balanced version of the B extension. Currently rev8 (shift_amt = 5'b11000) and orc.b
1141
- // (shift_amt = 5'b00111) are supported in the base extension.
1142
- logic [4:0] zbp_shift_amt;
1143
- logic gorc_op;
1144
- assign gorc_op = (operator_i == ALU_GORC);
1145
- assign zbp_shift_amt[2:0] =
1146
- (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) ? shift_amt[2:0] : {3{shift_amt[0]}};
1147
- assign zbp_shift_amt[4:3] =
1148
- (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) ? shift_amt[4:3] : {2{shift_amt[3]}};
1149
- always_comb begin
1150
- rev_result = operand_a_i;
1151
- if (zbp_shift_amt[0]) begin
1152
- rev_result = (gorc_op ? rev_result : 32'h0) |
1153
- ((rev_result & 32'h5555_5555) << 1) |
1154
- ((rev_result & 32'haaaa_aaaa) >> 1);
1155
- end
1156
- if (zbp_shift_amt[1]) begin
1157
- rev_result = (gorc_op ? rev_result : 32'h0) |
1158
- ((rev_result & 32'h3333_3333) << 2) |
1159
- ((rev_result & 32'hcccc_cccc) >> 2);
1160
- end
1161
- if (zbp_shift_amt[2]) begin
1162
- rev_result = (gorc_op ? rev_result : 32'h0) |
1163
- ((rev_result & 32'h0f0f_0f0f) << 4) |
1164
- ((rev_result & 32'hf0f0_f0f0) >> 4);
1165
- end
1166
- if (zbp_shift_amt[3]) begin
1167
- rev_result = ((RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) &&
1168
- gorc_op ? rev_result : 32'h0) |
1169
- ((rev_result & 32'h00ff_00ff) << 8) |
1170
- ((rev_result & 32'hff00_ff00) >> 8);
1171
- end
1172
- if (zbp_shift_amt[4]) begin
1173
- rev_result = ((RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) &&
1174
- gorc_op ? rev_result : 32'h0) |
1175
- ((rev_result & 32'h0000_ffff) << 16) |
1176
- ((rev_result & 32'hffff_0000) >> 16);
1177
- end
1178
- end
1179
- logic crc_hmode;
1180
- logic crc_bmode;
1181
- logic [31:0] clmul_result_rev;
1182
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) begin : gen_alu_rvb_otearlgrey_full
1183
- /////////////////////////
1184
- // Shuffle / Unshuffle //
1185
- /////////////////////////
1186
- localparam logic [31:0] SHUFFLE_MASK_L [4] =
1187
- '{32'h00ff_0000, 32'h0f00_0f00, 32'h3030_3030, 32'h4444_4444};
1188
- localparam logic [31:0] SHUFFLE_MASK_R [4] =
1189
- '{32'h0000_ff00, 32'h00f0_00f0, 32'h0c0c_0c0c, 32'h2222_2222};
1190
- localparam logic [31:0] FLIP_MASK_L [4] =
1191
- '{32'h2200_1100, 32'h0044_0000, 32'h4411_0000, 32'h1100_0000};
1192
- localparam logic [31:0] FLIP_MASK_R [4] =
1193
- '{32'h0088_0044, 32'h0000_2200, 32'h0000_8822, 32'h0000_0088};
1194
- logic [31:0] SHUFFLE_MASK_NOT [4];
1195
- for(genvar i = 0; i < 4; i++) begin : gen_shuffle_mask_not
1196
- assign SHUFFLE_MASK_NOT[i] = ~(SHUFFLE_MASK_L[i] | SHUFFLE_MASK_R[i]);
1197
- end
1198
- logic shuffle_flip;
1199
- assign shuffle_flip = operator_i == ALU_UNSHFL;
1200
- logic [3:0] shuffle_mode;
1201
- always_comb begin
1202
- shuffle_result = operand_a_i;
1203
- if (shuffle_flip) begin
1204
- shuffle_mode[3] = shift_amt[0];
1205
- shuffle_mode[2] = shift_amt[1];
1206
- shuffle_mode[1] = shift_amt[2];
1207
- shuffle_mode[0] = shift_amt[3];
1208
- end else begin
1209
- shuffle_mode = shift_amt[3:0];
1210
- end
1211
- if (shuffle_flip) begin
1212
- shuffle_result = (shuffle_result & 32'h8822_4411) |
1213
- ((shuffle_result << 6) & FLIP_MASK_L[0]) |
1214
- ((shuffle_result >> 6) & FLIP_MASK_R[0]) |
1215
- ((shuffle_result << 9) & FLIP_MASK_L[1]) |
1216
- ((shuffle_result >> 9) & FLIP_MASK_R[1]) |
1217
- ((shuffle_result << 15) & FLIP_MASK_L[2]) |
1218
- ((shuffle_result >> 15) & FLIP_MASK_R[2]) |
1219
- ((shuffle_result << 21) & FLIP_MASK_L[3]) |
1220
- ((shuffle_result >> 21) & FLIP_MASK_R[3]);
1221
- end
1222
- if (shuffle_mode[3]) begin
1223
- shuffle_result = (shuffle_result & SHUFFLE_MASK_NOT[0]) |
1224
- (((shuffle_result << 8) & SHUFFLE_MASK_L[0]) |
1225
- ((shuffle_result >> 8) & SHUFFLE_MASK_R[0]));
1226
- end
1227
- if (shuffle_mode[2]) begin
1228
- shuffle_result = (shuffle_result & SHUFFLE_MASK_NOT[1]) |
1229
- (((shuffle_result << 4) & SHUFFLE_MASK_L[1]) |
1230
- ((shuffle_result >> 4) & SHUFFLE_MASK_R[1]));
1231
- end
1232
- if (shuffle_mode[1]) begin
1233
- shuffle_result = (shuffle_result & SHUFFLE_MASK_NOT[2]) |
1234
- (((shuffle_result << 2) & SHUFFLE_MASK_L[2]) |
1235
- ((shuffle_result >> 2) & SHUFFLE_MASK_R[2]));
1236
- end
1237
- if (shuffle_mode[0]) begin
1238
- shuffle_result = (shuffle_result & SHUFFLE_MASK_NOT[3]) |
1239
- (((shuffle_result << 1) & SHUFFLE_MASK_L[3]) |
1240
- ((shuffle_result >> 1) & SHUFFLE_MASK_R[3]));
1241
- end
1242
- if (shuffle_flip) begin
1243
- shuffle_result = (shuffle_result & 32'h8822_4411) |
1244
- ((shuffle_result << 6) & FLIP_MASK_L[0]) |
1245
- ((shuffle_result >> 6) & FLIP_MASK_R[0]) |
1246
- ((shuffle_result << 9) & FLIP_MASK_L[1]) |
1247
- ((shuffle_result >> 9) & FLIP_MASK_R[1]) |
1248
- ((shuffle_result << 15) & FLIP_MASK_L[2]) |
1249
- ((shuffle_result >> 15) & FLIP_MASK_R[2]) |
1250
- ((shuffle_result << 21) & FLIP_MASK_L[3]) |
1251
- ((shuffle_result >> 21) & FLIP_MASK_R[3]);
1252
- end
1253
- end
1254
- //////////////
1255
- // Crossbar //
1256
- //////////////
1257
- // The crossbar permutation instructions xperm.[nbh] (Zbp) can be implemented using 8
1258
- // parallel 4-bit-wide, 8-input crossbars. Basically, we permute the 8 nibbles of operand_a_i
1259
- // based on operand_b_i.
1260
- // Generate selector indices and valid signals.
1261
- // - sel_n[x] indicates which nibble of operand_a_i is selected for output nibble x.
1262
- // - vld_n[x] indicates if the selection is valid.
1263
- logic [7:0][2:0] sel_n; // nibbles
1264
- logic [7:0] vld_n; // nibbles
1265
- logic [3:0][1:0] sel_b; // bytes
1266
- logic [3:0] vld_b; // bytes
1267
- logic [1:0][0:0] sel_h; // half words
1268
- logic [1:0] vld_h; // half words
1269
- // Per nibble, 3 bits are needed for the selection. Other bits must be zero.
1270
- // sel_n bit mask: 32'b0111_0111_0111_0111_0111_0111_0111_0111
1271
- // vld_n bit mask: 32'b1000_1000_1000_1000_1000_1000_1000_1000
1272
- for (genvar i = 0; i < 8; i++) begin : gen_sel_vld_n
1273
- assign sel_n[i] = operand_b_i[i*4 +: 3];
1274
- assign vld_n[i] = ~|operand_b_i[i*4 + 3 +: 1];
1275
- end
1276
- // Per byte, 2 bits are needed for the selection. Other bits must be zero.
1277
- // sel_b bit mask: 32'b0000_0011_0000_0011_0000_0011_0000_0011
1278
- // vld_b bit mask: 32'b1111_1100_1111_1100_1111_1100_1111_1100
1279
- for (genvar i = 0; i < 4; i++) begin : gen_sel_vld_b
1280
- assign sel_b[i] = operand_b_i[i*8 +: 2];
1281
- assign vld_b[i] = ~|operand_b_i[i*8 + 2 +: 6];
1282
- end
1283
- // Per half word, 1 bit is needed for the selection only. All other bits must be zero.
1284
- // sel_h bit mask: 32'b0000_0000_0000_0001_0000_0000_0000_0001
1285
- // vld_h bit mask: 32'b1111_1111_1111_1110_1111_1111_1111_1110
1286
- for (genvar i = 0; i < 2; i++) begin : gen_sel_vld_h
1287
- assign sel_h[i] = operand_b_i[i*16 +: 1];
1288
- assign vld_h[i] = ~|operand_b_i[i*16 + 1 +: 15];
1289
- end
1290
- // Convert selector indices and valid signals to control the nibble-based
1291
- // crossbar logic.
1292
- logic [7:0][2:0] sel;
1293
- logic [7:0] vld;
1294
- always_comb begin
1295
- unique case (operator_i)
1296
- ALU_XPERM_N: begin
1297
- // No conversion needed.
1298
- sel = sel_n;
1299
- vld = vld_n;
1300
- end
1301
- ALU_XPERM_B: begin
1302
- // Convert byte to nibble indicies.
1303
- for (int b = 0; b < 4; b++) begin
1304
- sel[b*2 + 0] = {sel_b[b], 1'b0};
1305
- sel[b*2 + 1] = {sel_b[b], 1'b1};
1306
- vld[b*2 +: 2] = {2{vld_b[b]}};
1307
- end
1308
- end
1309
- ALU_XPERM_H: begin
1310
- // Convert half-word to nibble indices.
1311
- for (int h = 0; h < 2; h++) begin
1312
- sel[h*4 + 0] = {sel_h[h], 2'b00};
1313
- sel[h*4 + 1] = {sel_h[h], 2'b01};
1314
- sel[h*4 + 2] = {sel_h[h], 2'b10};
1315
- sel[h*4 + 3] = {sel_h[h], 2'b11};
1316
- vld[h*4 +: 4] = {4{vld_h[h]}};
1317
- end
1318
- end
1319
- default: begin
1320
- // Tie valid to zero to disable the crossbar unless we need it.
1321
- sel = sel_n;
1322
- vld = '0;
1323
- end
1324
- endcase
1325
- end
1326
- // The actual nibble-based crossbar logic.
1327
- logic [7:0][3:0] val_n;
1328
- logic [7:0][3:0] xperm_n;
1329
- assign val_n = operand_a_i;
1330
- for (genvar i = 0; i < 8; i++) begin : gen_xperm_n
1331
- assign xperm_n[i] = vld[i] ? val_n[sel[i]] : '0;
1332
- end
1333
- assign xperm_result = xperm_n;
1334
- ///////////////////////////////////////////////////
1335
- // Carry-less Multiply + Cyclic Redundancy Check //
1336
- ///////////////////////////////////////////////////
1337
- // Carry-less multiplication can be understood as multiplication based on
1338
- // the addition interpreted as the bit-wise xor operation.
1339
- //
1340
- // Example: 1101 X 1011 = 1111111:
1341
- //
1342
- // 1011 X 1101
1343
- // -----------
1344
- // 1101
1345
- // xor 1101
1346
- // ---------
1347
- // 10111
1348
- // xor 0000
1349
- // ----------
1350
- // 010111
1351
- // xor 1101
1352
- // -----------
1353
- // 1111111
1354
- //
1355
- // Architectural details:
1356
- // A 32 x 32-bit array
1357
- // [ operand_b[i] ? (operand_a << i) : '0 for i in 0 ... 31 ]
1358
- // is generated. The entries of the array are pairwise 'xor-ed'
1359
- // together in a 5-stage binary tree.
1360
- //
1361
- //
1362
- // Cyclic Redundancy Check:
1363
- //
1364
- // CRC-32 (CRC-32/ISO-HDLC) and CRC-32C (CRC-32/ISCSI) are directly implemented. For
1365
- // documentation of the crc configuration (crc-polynomials, initialization, reflection, etc.)
1366
- // see http://reveng.sourceforge.net/crc-catalogue/all.htm
1367
- // A useful guide to crc arithmetic and algorithms is given here:
1368
- // http://www.piclist.com/techref/method/math/crcguide.html.
1369
- //
1370
- // The CRC operation solves the following equation using binary polynomial arithmetic:
1371
- //
1372
- // rev(rd)(x) = rev(rs1)(x) * x**n mod {1, P}(x)
1373
- //
1374
- // where P denotes lower 32 bits of the corresponding CRC polynomial, rev(a) the bit reversal
1375
- // of a, n = 8,16, or 32 for .b, .h, .w -variants. {a, b} denotes bit concatenation.
1376
- //
1377
- // Using barret reduction, one can show that
1378
- //
1379
- // M(x) mod P(x) = R(x) =
1380
- // (M(x) * x**n) & {deg(P(x)'{1'b1}}) ^ (M(x) x**-(deg(P(x) - n)) cx mu(x) cx P(x),
1381
- //
1382
- // Where mu(x) = polydiv(x**64, {1,P}) & 0xffffffff. Here, 'cx' refers to carry-less
1383
- // multiplication. Substituting rev(rd)(x) for R(x) and rev(rs1)(x) for M(x) and solving for
1384
- // rd(x) with P(x) a crc32 polynomial (deg(P(x)) = 32), we get
1385
- //
1386
- // rd = rev( (rev(rs1) << n) ^ ((rev(rs1) >> (32-n)) cx mu cx P)
1387
- // = (rs1 >> n) ^ rev(rev( (rs1 << (32-n)) cx rev(mu)) cx P)
1388
- // ^-- cycle 0--------------------^
1389
- // ^- cycle 1 -------------------------------------------^
1390
- //
1391
- // In the last step we used the fact that carry-less multiplication is bit-order agnostic:
1392
- // rev(a cx b) = rev(a) cx rev(b).
1393
- logic clmul_rmode;
1394
- logic clmul_hmode;
1395
- logic [31:0] clmul_op_a;
1396
- logic [31:0] clmul_op_b;
1397
- logic [31:0] operand_b_rev;
1398
- logic [31:0] clmul_and_stage[32];
1399
- logic [31:0] clmul_xor_stage1[16];
1400
- logic [31:0] clmul_xor_stage2[8];
1401
- logic [31:0] clmul_xor_stage3[4];
1402
- logic [31:0] clmul_xor_stage4[2];
1403
- logic [31:0] clmul_result_raw;
1404
- for (genvar i = 0; i < 32; i++) begin : gen_rev_operand_b
1405
- assign operand_b_rev[i] = operand_b_i[31-i];
1406
- end
1407
- assign clmul_rmode = operator_i == ALU_CLMULR;
1408
- assign clmul_hmode = operator_i == ALU_CLMULH;
1409
- // CRC
1410
- localparam logic [31:0] CRC32_POLYNOMIAL = 32'h04c1_1db7;
1411
- localparam logic [31:0] CRC32_MU_REV = 32'hf701_1641;
1412
- localparam logic [31:0] CRC32C_POLYNOMIAL = 32'h1edc_6f41;
1413
- localparam logic [31:0] CRC32C_MU_REV = 32'hdea7_13f1;
1414
- logic crc_op;
1415
- logic crc_cpoly;
1416
- logic [31:0] crc_operand;
1417
- logic [31:0] crc_poly;
1418
- logic [31:0] crc_mu_rev;
1419
- assign crc_op = (operator_i == ALU_CRC32C_W) | (operator_i == ALU_CRC32_W) |
1420
- (operator_i == ALU_CRC32C_H) | (operator_i == ALU_CRC32_H) |
1421
- (operator_i == ALU_CRC32C_B) | (operator_i == ALU_CRC32_B);
1422
- assign crc_cpoly = (operator_i == ALU_CRC32C_W) |
1423
- (operator_i == ALU_CRC32C_H) |
1424
- (operator_i == ALU_CRC32C_B);
1425
- assign crc_hmode = (operator_i == ALU_CRC32_H) | (operator_i == ALU_CRC32C_H);
1426
- assign crc_bmode = (operator_i == ALU_CRC32_B) | (operator_i == ALU_CRC32C_B);
1427
- assign crc_poly = crc_cpoly ? CRC32C_POLYNOMIAL : CRC32_POLYNOMIAL;
1428
- assign crc_mu_rev = crc_cpoly ? CRC32C_MU_REV : CRC32_MU_REV;
1429
- always_comb begin
1430
- unique case (1'b1)
1431
- crc_bmode: crc_operand = {operand_a_i[7:0], 24'h0};
1432
- crc_hmode: crc_operand = {operand_a_i[15:0], 16'h0};
1433
- default: crc_operand = operand_a_i;
1434
- endcase
1435
- end
1436
- // Select clmul input
1437
- always_comb begin
1438
- if (crc_op) begin
1439
- clmul_op_a = instr_first_cycle_i ? crc_operand : imd_val_q_i[0];
1440
- clmul_op_b = instr_first_cycle_i ? crc_mu_rev : crc_poly;
1441
- end else begin
1442
- clmul_op_a = clmul_rmode | clmul_hmode ? operand_a_rev : operand_a_i;
1443
- clmul_op_b = clmul_rmode | clmul_hmode ? operand_b_rev : operand_b_i;
1444
- end
1445
- end
1446
- for (genvar i = 0; i < 32; i++) begin : gen_clmul_and_op
1447
- assign clmul_and_stage[i] = clmul_op_b[i] ? clmul_op_a << i : '0;
1448
- end
1449
- for (genvar i = 0; i < 16; i++) begin : gen_clmul_xor_op_l1
1450
- assign clmul_xor_stage1[i] = clmul_and_stage[2*i] ^ clmul_and_stage[2*i+1];
1451
- end
1452
- for (genvar i = 0; i < 8; i++) begin : gen_clmul_xor_op_l2
1453
- assign clmul_xor_stage2[i] = clmul_xor_stage1[2*i] ^ clmul_xor_stage1[2*i+1];
1454
- end
1455
- for (genvar i = 0; i < 4; i++) begin : gen_clmul_xor_op_l3
1456
- assign clmul_xor_stage3[i] = clmul_xor_stage2[2*i] ^ clmul_xor_stage2[2*i+1];
1457
- end
1458
- for (genvar i = 0; i < 2; i++) begin : gen_clmul_xor_op_l4
1459
- assign clmul_xor_stage4[i] = clmul_xor_stage3[2*i] ^ clmul_xor_stage3[2*i+1];
1460
- end
1461
- assign clmul_result_raw = clmul_xor_stage4[0] ^ clmul_xor_stage4[1];
1462
- for (genvar i = 0; i < 32; i++) begin : gen_rev_clmul_result
1463
- assign clmul_result_rev[i] = clmul_result_raw[31-i];
1464
- end
1465
- // clmulr_result = rev(clmul(rev(a), rev(b)))
1466
- // clmulh_result = clmulr_result >> 1
1467
- always_comb begin
1468
- case (1'b1)
1469
- clmul_rmode: clmul_result = clmul_result_rev;
1470
- clmul_hmode: clmul_result = {1'b0, clmul_result_rev[31:1]};
1471
- default: clmul_result = clmul_result_raw;
1472
- endcase
1473
- end
1474
- end else begin : gen_alu_rvb_not_otearlgrey_full
1475
- assign shuffle_result = '0;
1476
- assign xperm_result = '0;
1477
- assign clmul_result = '0;
1478
- // support signals
1479
- assign clmul_result_rev = '0;
1480
- assign crc_bmode = '0;
1481
- assign crc_hmode = '0;
1482
- end
1483
- if (RV32B == RV32BFull) begin : gen_alu_rvb_full
1484
- ///////////////
1485
- // Butterfly //
1486
- ///////////////
1487
- // The butterfly / inverse butterfly network executing bcompress/bdecompress (zbe)
1488
- // instructions. For bdecompress, the control bits mask of a local left region is generated
1489
- // by the inverse of a n-bit left rotate and complement upon wrap (LROTC) operation by the
1490
- // number of ones in the deposit bitmask to the right of the segment. n hereby denotes the
1491
- // width of the according segment. The bitmask for a pertaining local right region is equal
1492
- // to the corresponding local left region. Bcompress uses an analogue inverse process.
1493
- // Consider the following 8-bit example. For details, see Hilewitz et al. "Fast Bit Gather,
1494
- // Bit Scatter and Bit Permuation Instructions for Commodity Microprocessors", (2008).
1495
- //
1496
- // The bcompress/bdecompress instructions are completed in 2 cycles. In the first cycle, the
1497
- // control bitmask is prepared by executing the parallel prefix bit count. In the second
1498
- // cycle, the bit swapping is executed according to the control masks.
1499
- // 8-bit example: (Hilewitz et al.)
1500
- // Consider the instruction bdecompress operand_a_i deposit_mask
1501
- // Let operand_a_i = 8'babcd_efgh
1502
- // deposit_mask = 8'b1010_1101
1503
- //
1504
- // control bitmask for stage 1:
1505
- // - number of ones in the right half of the deposit bitmask: 3
1506
- // - width of the segment: 4
1507
- // - control bitmask = ~LROTC(4'b0, 3)[3:0] = 4'b1000
1508
- //
1509
- // control bitmask: c3 c2 c1 c0 c3 c2 c1 c0
1510
- // 1 0 0 0 1 0 0 0
1511
- // <- L -----> <- R ----->
1512
- // operand_a_i a b c d e f g h
1513
- // :\ | | | /: | | |
1514
- // : +|---|--|-+ : | | |
1515
- // :/ | | | \: | | |
1516
- // stage 1 e b c d a f g h
1517
- // <L-> <R-> <L-> <R->
1518
- // control bitmask: c3 c2 c3 c2 c1 c0 c1 c0
1519
- // 1 1 1 1 1 0 1 0
1520
- // :\ :\ /: /: :\ | /: |
1521
- // : +:-+-:+ : : +|-+ : |
1522
- // :/ :/ \: \: :/ | \: |
1523
- // stage 2 c d e b g f a h
1524
- // L R L R L R L R
1525
- // control bitmask: c3 c3 c2 c2 c1 c1 c0 c0
1526
- // 1 1 0 0 1 1 0 0
1527
- // :\/: | | :\/: | |
1528
- // : : | | : : | |
1529
- // :/\: | | :/\: | |
1530
- // stage 3 d c e b f g a h
1531
- // & deposit bitmask: 1 0 1 0 1 1 0 1
1532
- // result: d 0 e 0 f g 0 h
1533
- logic [ 5:0] bitcnt_partial_q [32];
1534
- // first cycle
1535
- // Store partial bitcnts
1536
- for (genvar i = 0; i < 32; i++) begin : gen_bitcnt_reg_in_lsb
1537
- assign bitcnt_partial_lsb_d[i] = bitcnt_partial[i][0];
1538
- end
1539
- for (genvar i = 0; i < 16; i++) begin : gen_bitcnt_reg_in_b1
1540
- assign bitcnt_partial_msb_d[i] = bitcnt_partial[2*i+1][1];
1541
- end
1542
- for (genvar i = 0; i < 8; i++) begin : gen_bitcnt_reg_in_b2
1543
- assign bitcnt_partial_msb_d[16+i] = bitcnt_partial[4*i+3][2];
1544
- end
1545
- for (genvar i = 0; i < 4; i++) begin : gen_bitcnt_reg_in_b3
1546
- assign bitcnt_partial_msb_d[24+i] = bitcnt_partial[8*i+7][3];
1547
- end
1548
- for (genvar i = 0; i < 2; i++) begin : gen_bitcnt_reg_in_b4
1549
- assign bitcnt_partial_msb_d[28+i] = bitcnt_partial[16*i+15][4];
1550
- end
1551
- assign bitcnt_partial_msb_d[30] = bitcnt_partial[31][5];
1552
- assign bitcnt_partial_msb_d[31] = 1'b0; // unused
1553
- // Second cycle
1554
- // Load partial bitcnts
1555
- always_comb begin
1556
- bitcnt_partial_q = '{default: '0};
1557
- for (int unsigned i = 0; i < 32; i++) begin : gen_bitcnt_reg_out_lsb
1558
- bitcnt_partial_q[i][0] = imd_val_q_i[0][i];
1559
- end
1560
- for (int unsigned i = 0; i < 16; i++) begin : gen_bitcnt_reg_out_b1
1561
- bitcnt_partial_q[2*i+1][1] = imd_val_q_i[1][i];
1562
- end
1563
- for (int unsigned i = 0; i < 8; i++) begin : gen_bitcnt_reg_out_b2
1564
- bitcnt_partial_q[4*i+3][2] = imd_val_q_i[1][16+i];
1565
- end
1566
- for (int unsigned i = 0; i < 4; i++) begin : gen_bitcnt_reg_out_b3
1567
- bitcnt_partial_q[8*i+7][3] = imd_val_q_i[1][24+i];
1568
- end
1569
- for (int unsigned i = 0; i < 2; i++) begin : gen_bitcnt_reg_out_b4
1570
- bitcnt_partial_q[16*i+15][4] = imd_val_q_i[1][28+i];
1571
- end
1572
- bitcnt_partial_q[31][5] = imd_val_q_i[1][30];
1573
- end
1574
- logic [31:0] butterfly_mask_l[5];
1575
- logic [31:0] butterfly_mask_r[5];
1576
- logic [31:0] butterfly_mask_not[5];
1577
- logic [31:0] lrotc_stage [5]; // left rotate and complement upon wrap
1578
- // number of bits in local r = 32 / 2**(stage + 1) = 16/2**stage
1579
- // bcompress / bdecompress control bit generation
1580
- for (genvar stg = 0; stg < 5; stg++) begin : gen_butterfly_ctrl_stage
1581
- // number of segs: 2** stg
1582
- for (genvar seg=0; seg<2**stg; seg++) begin : gen_butterfly_ctrl
1583
- assign lrotc_stage[stg][2*(16 >> stg)*(seg+1)-1 : 2*(16 >> stg)*seg] =
1584
- {{(16 >> stg){1'b0}},{(16 >> stg){1'b1}}} <<
1585
- bitcnt_partial_q[(16 >> stg)*(2*seg+1)-1][$clog2((16 >> stg)):0];
1586
- assign butterfly_mask_l[stg][(16 >> stg)*(2*seg+2)-1 : (16 >> stg)*(2*seg+1)]
1587
- = ~lrotc_stage[stg][(16 >> stg)*(2*seg+2)-1 : (16 >> stg)*(2*seg+1)];
1588
- assign butterfly_mask_r[stg][(16 >> stg)*(2*seg+1)-1 : (16 >> stg)*(2*seg)]
1589
- = ~lrotc_stage[stg][(16 >> stg)*(2*seg+2)-1 : (16 >> stg)*(2*seg+1)];
1590
- assign butterfly_mask_l[stg][(16 >> stg)*(2*seg+1)-1 : (16 >> stg)*(2*seg)] = '0;
1591
- assign butterfly_mask_r[stg][(16 >> stg)*(2*seg+2)-1 : (16 >> stg)*(2*seg+1)] = '0;
1592
- end
1593
- end
1594
- for (genvar stg = 0; stg < 5; stg++) begin : gen_butterfly_not
1595
- assign butterfly_mask_not[stg] =
1596
- ~(butterfly_mask_l[stg] | butterfly_mask_r[stg]);
1597
- end
1598
- always_comb begin
1599
- butterfly_result = operand_a_i;
1600
- butterfly_result = butterfly_result & butterfly_mask_not[0] |
1601
- ((butterfly_result & butterfly_mask_l[0]) >> 16)|
1602
- ((butterfly_result & butterfly_mask_r[0]) << 16);
1603
- butterfly_result = butterfly_result & butterfly_mask_not[1] |
1604
- ((butterfly_result & butterfly_mask_l[1]) >> 8)|
1605
- ((butterfly_result & butterfly_mask_r[1]) << 8);
1606
- butterfly_result = butterfly_result & butterfly_mask_not[2] |
1607
- ((butterfly_result & butterfly_mask_l[2]) >> 4)|
1608
- ((butterfly_result & butterfly_mask_r[2]) << 4);
1609
- butterfly_result = butterfly_result & butterfly_mask_not[3] |
1610
- ((butterfly_result & butterfly_mask_l[3]) >> 2)|
1611
- ((butterfly_result & butterfly_mask_r[3]) << 2);
1612
- butterfly_result = butterfly_result & butterfly_mask_not[4] |
1613
- ((butterfly_result & butterfly_mask_l[4]) >> 1)|
1614
- ((butterfly_result & butterfly_mask_r[4]) << 1);
1615
- butterfly_result = butterfly_result & operand_b_i;
1616
- end
1617
- always_comb begin
1618
- invbutterfly_result = operand_a_i & operand_b_i;
1619
- invbutterfly_result = invbutterfly_result & butterfly_mask_not[4] |
1620
- ((invbutterfly_result & butterfly_mask_l[4]) >> 1)|
1621
- ((invbutterfly_result & butterfly_mask_r[4]) << 1);
1622
- invbutterfly_result = invbutterfly_result & butterfly_mask_not[3] |
1623
- ((invbutterfly_result & butterfly_mask_l[3]) >> 2)|
1624
- ((invbutterfly_result & butterfly_mask_r[3]) << 2);
1625
- invbutterfly_result = invbutterfly_result & butterfly_mask_not[2] |
1626
- ((invbutterfly_result & butterfly_mask_l[2]) >> 4)|
1627
- ((invbutterfly_result & butterfly_mask_r[2]) << 4);
1628
- invbutterfly_result = invbutterfly_result & butterfly_mask_not[1] |
1629
- ((invbutterfly_result & butterfly_mask_l[1]) >> 8)|
1630
- ((invbutterfly_result & butterfly_mask_r[1]) << 8);
1631
- invbutterfly_result = invbutterfly_result & butterfly_mask_not[0] |
1632
- ((invbutterfly_result & butterfly_mask_l[0]) >> 16)|
1633
- ((invbutterfly_result & butterfly_mask_r[0]) << 16);
1634
- end
1635
- end else begin : gen_alu_rvb_not_full
1636
- logic [31:0] unused_imd_val_q_1;
1637
- assign unused_imd_val_q_1 = imd_val_q_i[1];
1638
- assign butterfly_result = '0;
1639
- assign invbutterfly_result = '0;
1640
- // support signals
1641
- assign bitcnt_partial_lsb_d = '0;
1642
- assign bitcnt_partial_msb_d = '0;
1643
- end
1644
- //////////////////////////////////////
1645
- // Multicycle Bitmanip Instructions //
1646
- //////////////////////////////////////
1647
- // Ternary instructions + Shift Rotations + Bit Compress/Decompress + CRC
1648
- // For ternary instructions (zbt), operand_a_i is tied to rs1 in the first cycle and rs3 in the
1649
- // second cycle. operand_b_i is always tied to rs2.
1650
- always_comb begin
1651
- unique case (operator_i)
1652
- ALU_CMOV: begin
1653
- multicycle_result = (operand_b_i == 32'h0) ? operand_a_i : imd_val_q_i[0];
1654
- imd_val_d_o = '{operand_a_i, 32'h0};
1655
- if (instr_first_cycle_i) begin
1656
- imd_val_we_o = 2'b01;
1657
- end else begin
1658
- imd_val_we_o = 2'b00;
1659
- end
1660
- end
1661
- ALU_CMIX: begin
1662
- multicycle_result = imd_val_q_i[0] | bwlogic_and_result;
1663
- imd_val_d_o = '{bwlogic_and_result, 32'h0};
1664
- if (instr_first_cycle_i) begin
1665
- imd_val_we_o = 2'b01;
1666
- end else begin
1667
- imd_val_we_o = 2'b00;
1668
- end
1669
- end
1670
- ALU_FSR, ALU_FSL,
1671
- ALU_ROL, ALU_ROR: begin
1672
- if (shift_amt[4:0] == 5'h0) begin
1673
- multicycle_result = shift_amt[5] ? operand_a_i : imd_val_q_i[0];
1674
- end else begin
1675
- multicycle_result = imd_val_q_i[0] | shift_result;
1676
- end
1677
- imd_val_d_o = '{shift_result, 32'h0};
1678
- if (instr_first_cycle_i) begin
1679
- imd_val_we_o = 2'b01;
1680
- end else begin
1681
- imd_val_we_o = 2'b00;
1682
- end
1683
- end
1684
- ALU_CRC32_W, ALU_CRC32C_W,
1685
- ALU_CRC32_H, ALU_CRC32C_H,
1686
- ALU_CRC32_B, ALU_CRC32C_B: begin
1687
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) begin
1688
- unique case (1'b1)
1689
- crc_bmode: multicycle_result = clmul_result_rev ^ (operand_a_i >> 8);
1690
- crc_hmode: multicycle_result = clmul_result_rev ^ (operand_a_i >> 16);
1691
- default: multicycle_result = clmul_result_rev;
1692
- endcase
1693
- imd_val_d_o = '{clmul_result_rev, 32'h0};
1694
- if (instr_first_cycle_i) begin
1695
- imd_val_we_o = 2'b01;
1696
- end else begin
1697
- imd_val_we_o = 2'b00;
1698
- end
1699
- end else begin
1700
- imd_val_d_o = '{operand_a_i, 32'h0};
1701
- imd_val_we_o = 2'b00;
1702
- multicycle_result = '0;
1703
- end
1704
- end
1705
- ALU_BCOMPRESS, ALU_BDECOMPRESS: begin
1706
- if (RV32B == RV32BFull) begin
1707
- multicycle_result = (operator_i == ALU_BDECOMPRESS) ? butterfly_result :
1708
- invbutterfly_result;
1709
- imd_val_d_o = '{bitcnt_partial_lsb_d, bitcnt_partial_msb_d};
1710
- if (instr_first_cycle_i) begin
1711
- imd_val_we_o = 2'b11;
1712
- end else begin
1713
- imd_val_we_o = 2'b00;
1714
- end
1715
- end else begin
1716
- imd_val_d_o = '{operand_a_i, 32'h0};
1717
- imd_val_we_o = 2'b00;
1718
- multicycle_result = '0;
1719
- end
1720
- end
1721
- default: begin
1722
- imd_val_d_o = '{operand_a_i, 32'h0};
1723
- imd_val_we_o = 2'b00;
1724
- multicycle_result = '0;
1725
- end
1726
- endcase
1727
- end
1728
- end else begin : g_no_alu_rvb
1729
- logic [31:0] unused_imd_val_q[2];
1730
- assign unused_imd_val_q = imd_val_q_i;
1731
- logic [31:0] unused_butterfly_result;
1732
- assign unused_butterfly_result = butterfly_result;
1733
- logic [31:0] unused_invbutterfly_result;
1734
- assign unused_invbutterfly_result = invbutterfly_result;
1735
- // RV32B result signals
1736
- assign bitcnt_result = '0;
1737
- assign minmax_result = '0;
1738
- assign pack_result = '0;
1739
- assign sext_result = '0;
1740
- assign singlebit_result = '0;
1741
- assign rev_result = '0;
1742
- assign shuffle_result = '0;
1743
- assign xperm_result = '0;
1744
- assign butterfly_result = '0;
1745
- assign invbutterfly_result = '0;
1746
- assign clmul_result = '0;
1747
- assign multicycle_result = '0;
1748
- // RV32B support signals
1749
- assign imd_val_d_o = '{default: '0};
1750
- assign imd_val_we_o = '{default: '0};
1751
- end
1752
- ////////////////
1753
- // Result mux //
1754
- ////////////////
1755
- always_comb begin
1756
- result_o = '0;
1757
- unique case (operator_i)
1758
- // Bitwise Logic Operations (negate: RV32B)
1759
- ALU_XOR, ALU_XNOR,
1760
- ALU_OR, ALU_ORN,
1761
- ALU_AND, ALU_ANDN: result_o = bwlogic_result;
1762
- // Adder Operations
1763
- ALU_ADD, ALU_SUB,
1764
- // RV32B
1765
- ALU_SH1ADD, ALU_SH2ADD,
1766
- ALU_SH3ADD: result_o = adder_result;
1767
- // Shift Operations
1768
- ALU_SLL, ALU_SRL,
1769
- ALU_SRA,
1770
- // RV32B
1771
- ALU_SLO, ALU_SRO: result_o = shift_result;
1772
- // Shuffle Operations (RV32B)
1773
- ALU_SHFL, ALU_UNSHFL: result_o = shuffle_result;
1774
- // Crossbar Permutation Operations (RV32B)
1775
- ALU_XPERM_N, ALU_XPERM_B, ALU_XPERM_H: result_o = xperm_result;
1776
- // Comparison Operations
1777
- ALU_EQ, ALU_NE,
1778
- ALU_GE, ALU_GEU,
1779
- ALU_LT, ALU_LTU,
1780
- ALU_SLT, ALU_SLTU: result_o = {31'h0,cmp_result};
1781
- // MinMax Operations (RV32B)
1782
- ALU_MIN, ALU_MAX,
1783
- ALU_MINU, ALU_MAXU: result_o = minmax_result;
1784
- // Bitcount Operations (RV32B)
1785
- ALU_CLZ, ALU_CTZ,
1786
- ALU_CPOP: result_o = {26'h0, bitcnt_result};
1787
- // Pack Operations (RV32B)
1788
- ALU_PACK, ALU_PACKH,
1789
- ALU_PACKU: result_o = pack_result;
1790
- // Sign-Extend (RV32B)
1791
- ALU_SEXTB, ALU_SEXTH: result_o = sext_result;
1792
- // Ternary Bitmanip Operations (RV32B)
1793
- ALU_CMIX, ALU_CMOV,
1794
- ALU_FSL, ALU_FSR,
1795
- // Rotate Shift (RV32B)
1796
- ALU_ROL, ALU_ROR,
1797
- // Cyclic Redundancy Checks (RV32B)
1798
- ALU_CRC32_W, ALU_CRC32C_W,
1799
- ALU_CRC32_H, ALU_CRC32C_H,
1800
- ALU_CRC32_B, ALU_CRC32C_B,
1801
- // Bit Compress / Decompress (RV32B)
1802
- ALU_BCOMPRESS, ALU_BDECOMPRESS: result_o = multicycle_result;
1803
- // Single-Bit Bitmanip Operations (RV32B)
1804
- ALU_BSET, ALU_BCLR,
1805
- ALU_BINV, ALU_BEXT: result_o = singlebit_result;
1806
- // General Reverse / Or-combine (RV32B)
1807
- ALU_GREV, ALU_GORC: result_o = rev_result;
1808
- // Bit Field Place (RV32B)
1809
- ALU_BFP: result_o = bfp_result;
1810
- // Carry-less Multiply Operations (RV32B)
1811
- ALU_CLMUL, ALU_CLMULR,
1812
- ALU_CLMULH: result_o = clmul_result;
1813
- default: ;
1814
- endcase
1815
- end
1816
- logic unused_shift_amt_compl;
1817
- assign unused_shift_amt_compl = shift_amt_compl[5];
1818
- endmodule
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p1/mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"conditional_statement": [[20280, 20329], [41141, 41425], [40404, 40620], [43411, 43638], [64856, 64993], [65345, 65482], [44119, 44346], [64551, 64688], [43647, 43874], [53181, 53536], [66023, 66168], [44355, 44915]], "blocking_assignment": [[40440, 40610], [38083, 38148], [20649, 20688], [65730, 65788], [22700, 22723], [53209, 53273], [28553, 28571], [63435, 63632]], "always_construct": [[36725, 38166], [21572, 21782], [31607, 31832], [22577, 22997], [29575, 30526], [38465, 38749], [62536, 63642], [42502, 44925], [33980, 34224], [40125, 41433], [19782, 20499], [52877, 53120], [30834, 31180], [54652, 54897], [20981, 21210], [21891, 22110], [28491, 29249], [33547, 33890], [27595, 27954], [61441, 62529], [39051, 39392], [68161, 70282], [59100, 59959], [47046, 48118], [64336, 67167], [53155, 53546], [20525, 20897]], "case_statement": [[52903, 53110], [21594, 21776], [38489, 38741], [28513, 29182], [31629, 31826], [54678, 54887], [68204, 70276], [47072, 48108], [65686, 65956], [19924, 20493], [34004, 34216], [21003, 21204], [22599, 22991], [30856, 31174], [39075, 39384], [29830, 30047], [64360, 67159], [20547, 20891]], "ansi_port_declaration": [[19230, 19273], [18690, 18728], [19143, 19178], [19051, 19092], [18731, 18777], [18829, 18875], [18878, 18918], [19181, 19227]], "continuous_assign": [[67440, 67496], [31183, 31266], [31458, 31529], [52563, 52641], [52648, 52726], [33895, 33975], [52396, 52556], [33003, 33048], [67603, 67635], [68002, 68046], [52733, 52802], [48394, 48424], [67242, 67290]], "parameter_declaration": [[13332, 13380], [12925, 13002], [12625, 12677], [12792, 12845], [12736, 12789], [13189, 13235], [12570, 12622], [12464, 12546], [13140, 13186], [6471, 6520]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p10/all_mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"module_program_interface_instantiation": [], "continuous_assign": [[24919, 24962], [25006, 25049], [25173, 25220], [25223, 25262], [25265, 25311], [25314, 25358], [25361, 25410], [25413, 25449], [25452, 25498], [25501, 25548], [27069, 27116], [27119, 27215], [27218, 27314], [27353, 27401], [27404, 27452], [27455, 27490], [27493, 27528], [27776, 27889], [27892, 27949], [27952, 28043], [28046, 28129], [28132, 28193], [28196, 28229], [34480, 34539], [35082, 35265], [35268, 35346]], "blocking_assignment": [[25573, 25606], [25668, 25697], [25740, 25813], [25970, 26004], [26017, 26051], [26134, 26168], [26181, 26215], [26298, 26332], [26345, 26379], [26496, 26530], [26543, 26591], [26667, 26743], [26756, 26836], [26906, 26939], [26948, 26994], [28254, 28289], [28294, 28328], [28333, 28365], [28370, 28402], [28407, 28441], [28446, 28476], [28481, 28505], [28510, 28543], [28716, 28747], [28762, 28899], [28914, 28945], [29088, 29148], [29209, 29235], [29250, 29387], [29402, 29433], [29448, 29473], [29798, 29826], [29887, 29943], [30104, 30137], [30493, 30519], [30580, 30636], [30703, 30729], [30798, 30818], [30854, 30901], [30912, 30938], [31008, 31053], [31089, 31152], [31163, 31188], [31234, 31275], [31355, 31384], [31399, 31434], [31449, 31484], [31741, 31861], [31922, 31951], [31966, 31996], [32011, 32046], [32061, 32124], [32207, 32280], [32295, 32326], [32341, 32404], [32576, 32605], [32696, 32719], [32734, 32769], [32830, 32859], [32874, 32899], [32990, 33013], [33028, 33063], [33249, 33280], [33295, 33327], [33483, 33529], [33544, 33576], [33686, 33709], [33782, 33853], [33891, 33962], [34123, 34146], [34157, 34192], [34238, 34259]], "nonblocking_assignment": [[34622, 34647], [34654, 34680], [34687, 34713], [34720, 34748], [34755, 34780], [34822, 34858], [34865, 34898], [34905, 34938], [34945, 34976], [34983, 35017]], "case_statement": [[25611, 27016], [25872, 26866], [28589, 34299], [28647, 30692], [31286, 32461], [32507, 33633], [33720, 34003]], "conditional_statement": [[28548, 34336], [34597, 35025], [34794, 35025]], "always_construct": [[25551, 27022], [28232, 34342], [34542, 35031]], "parameter_declaration": [[6471, 6520], [6523, 6571], [6594, 6628], [6631, 6665], [6668, 6702], [12379, 12461], [12464, 12546], [12570, 12622], [12625, 12677], [12680, 12733], [12736, 12789], [12792, 12845], [12848, 12901], [12925, 13002], [13044, 13089], [13092, 13137], [13140, 13186], [13189, 13235], [13238, 13284], [13332, 13380], [13383, 13431], [13434, 13482], [13551, 13619], [13622, 13688], [13787, 13814], [16708, 16752], [16755, 16799], [16802, 16847], [16850, 16895], [16898, 16943], [16946, 16990], [16993, 17037], [17040, 17096]], "ansi_port_declaration": [[22940, 22971], [22974, 23006], [23009, 23087], [23090, 23168], [23171, 23248], [23251, 23328], [23331, 23367], [23370, 23409], [23412, 23444], [23447, 23479], [23482, 23523], [23526, 23563], [23566, 23607], [23610, 23651], [23654, 23695], [23698, 23738], [23741, 23781], [23784, 23822], [23825, 23869], [23872, 23914], [23917, 23949]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p10/cve2_multdiv_slow.sv DELETED
@@ -1,1035 +0,0 @@
1
- // Copyright (c) 2025 Eclipse Foundation
2
- // Copyright lowRISC contributors.
3
- // Copyright 2017 ETH Zurich and University of Bologna, see also CREDITS.md.
4
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
5
- // SPDX-License-Identifier: Apache-2.0
6
- /**
7
- * Package with constants used by CVE2
8
- */
9
- package cve2_pkg;
10
- ////////////////
11
- // IO Structs //
12
- ////////////////
13
- typedef struct packed {
14
- logic [31:0] current_pc;
15
- logic [31:0] next_pc;
16
- logic [31:0] last_data_addr;
17
- logic [31:0] exception_addr;
18
- } crash_dump_t;
19
- typedef struct packed {
20
- logic dummy_instr_id;
21
- logic [4:0] raddr_a;
22
- logic [4:0] waddr_a;
23
- logic we_a;
24
- logic [4:0] raddr_b;
25
- } core2rf_t;
26
- /////////////////////
27
- // Parameter Enums //
28
- /////////////////////
29
- typedef enum integer {
30
- RV32MNone = 0,
31
- RV32MSlow = 1,
32
- RV32MFast = 2,
33
- RV32MSingleCycle = 3
34
- } rv32m_e;
35
- typedef enum integer {
36
- RV32BNone = 0,
37
- RV32BBalanced = 1,
38
- RV32BOTEarlGrey = 2,
39
- RV32BFull = 3
40
- } rv32b_e;
41
- /////////////
42
- // Opcodes //
43
- /////////////
44
- typedef enum logic [6:0] {
45
- OPCODE_LOAD = 7'h03,
46
- OPCODE_MISC_MEM = 7'h0f,
47
- OPCODE_OP_IMM = 7'h13,
48
- OPCODE_AUIPC = 7'h17,
49
- OPCODE_STORE = 7'h23,
50
- OPCODE_OP = 7'h33,
51
- OPCODE_LUI = 7'h37,
52
- OPCODE_BRANCH = 7'h63,
53
- OPCODE_JALR = 7'h67,
54
- OPCODE_JAL = 7'h6f,
55
- OPCODE_SYSTEM = 7'h73
56
- } opcode_e;
57
- ////////////////////
58
- // ALU operations //
59
- ////////////////////
60
- typedef enum logic [6:0] {
61
- // Arithmetics
62
- ALU_ADD,
63
- ALU_SUB,
64
- // Logics
65
- ALU_XOR,
66
- ALU_OR,
67
- ALU_AND,
68
- // RV32B
69
- ALU_XNOR,
70
- ALU_ORN,
71
- ALU_ANDN,
72
- // Shifts
73
- ALU_SRA,
74
- ALU_SRL,
75
- ALU_SLL,
76
- // RV32B
77
- ALU_SRO,
78
- ALU_SLO,
79
- ALU_ROR,
80
- ALU_ROL,
81
- ALU_GREV,
82
- ALU_GORC,
83
- ALU_SHFL,
84
- ALU_UNSHFL,
85
- ALU_XPERM_N,
86
- ALU_XPERM_B,
87
- ALU_XPERM_H,
88
- // Address Calculations
89
- // RV32B
90
- ALU_SH1ADD,
91
- ALU_SH2ADD,
92
- ALU_SH3ADD,
93
- // Comparisons
94
- ALU_LT,
95
- ALU_LTU,
96
- ALU_GE,
97
- ALU_GEU,
98
- ALU_EQ,
99
- ALU_NE,
100
- // RV32B
101
- ALU_MIN,
102
- ALU_MINU,
103
- ALU_MAX,
104
- ALU_MAXU,
105
- // Pack
106
- // RV32B
107
- ALU_PACK,
108
- ALU_PACKU,
109
- ALU_PACKH,
110
- // Sign-Extend
111
- // RV32B
112
- ALU_SEXTB,
113
- ALU_SEXTH,
114
- // Bitcounting
115
- // RV32B
116
- ALU_CLZ,
117
- ALU_CTZ,
118
- ALU_CPOP,
119
- // Set lower than
120
- ALU_SLT,
121
- ALU_SLTU,
122
- // Ternary Bitmanip Operations
123
- // RV32B
124
- ALU_CMOV,
125
- ALU_CMIX,
126
- ALU_FSL,
127
- ALU_FSR,
128
- // Single-Bit Operations
129
- // RV32B
130
- ALU_BSET,
131
- ALU_BCLR,
132
- ALU_BINV,
133
- ALU_BEXT,
134
- // Bit Compress / Decompress
135
- // RV32B
136
- ALU_BCOMPRESS,
137
- ALU_BDECOMPRESS,
138
- // Bit Field Place
139
- // RV32B
140
- ALU_BFP,
141
- // Carry-less Multiply
142
- // RV32B
143
- ALU_CLMUL,
144
- ALU_CLMULR,
145
- ALU_CLMULH,
146
- // Cyclic Redundancy Check
147
- ALU_CRC32_B,
148
- ALU_CRC32C_B,
149
- ALU_CRC32_H,
150
- ALU_CRC32C_H,
151
- ALU_CRC32_W,
152
- ALU_CRC32C_W
153
- } alu_op_e;
154
- typedef enum logic [1:0] {
155
- // Multiplier/divider
156
- MD_OP_MULL,
157
- MD_OP_MULH,
158
- MD_OP_DIV,
159
- MD_OP_REM
160
- } md_op_e;
161
- //////////////////////////////////
162
- // Control and status registers //
163
- //////////////////////////////////
164
- // CSR operations
165
- typedef enum logic [1:0] {
166
- CSR_OP_READ,
167
- CSR_OP_WRITE,
168
- CSR_OP_SET,
169
- CSR_OP_CLEAR
170
- } csr_op_e;
171
- // Privileged mode
172
- typedef enum logic[1:0] {
173
- PRIV_LVL_M = 2'b11,
174
- PRIV_LVL_H = 2'b10,
175
- PRIV_LVL_S = 2'b01,
176
- PRIV_LVL_U = 2'b00
177
- } priv_lvl_e;
178
- // Constants for the dcsr.xdebugver fields
179
- typedef enum logic[3:0] {
180
- XDEBUGVER_NO = 4'd0, // no external debug support
181
- XDEBUGVER_STD = 4'd4, // external debug according to RISC-V debug spec
182
- XDEBUGVER_NONSTD = 4'd15 // debug not conforming to RISC-V debug spec
183
- } x_debug_ver_e;
184
- //////////////
185
- // WB stage //
186
- //////////////
187
- // Type of instruction present in writeback stage
188
- typedef enum logic[1:0] {
189
- WB_INSTR_LOAD, // Instruction is awaiting load data
190
- WB_INSTR_STORE, // Instruction is awaiting store response
191
- WB_INSTR_OTHER // Instruction doesn't fit into above categories
192
- } wb_instr_type_e;
193
- //////////////
194
- // ID stage //
195
- //////////////
196
- // Operand a selection
197
- typedef enum logic[1:0] {
198
- OP_A_REG_A,
199
- OP_A_FWD,
200
- OP_A_CURRPC,
201
- OP_A_IMM
202
- } op_a_sel_e;
203
- // Immediate a selection
204
- typedef enum logic {
205
- IMM_A_Z,
206
- IMM_A_ZERO
207
- } imm_a_sel_e;
208
- // Operand b selection
209
- typedef enum logic {
210
- OP_B_REG_B,
211
- OP_B_IMM
212
- } op_b_sel_e;
213
- // Immediate b selection
214
- typedef enum logic [2:0] {
215
- IMM_B_I,
216
- IMM_B_S,
217
- IMM_B_B,
218
- IMM_B_U,
219
- IMM_B_J,
220
- IMM_B_INCR_PC,
221
- IMM_B_INCR_ADDR
222
- } imm_b_sel_e;
223
- // Regfile write data selection
224
- typedef enum {
225
- RF_WD_EX,
226
- RF_WD_CSR,
227
- RF_WD_COPROC // Only used when XInterface = 1
228
- } rf_wd_sel_e;
229
- //////////////
230
- // IF stage //
231
- //////////////
232
- // PC mux selection
233
- typedef enum logic [2:0] {
234
- PC_BOOT,
235
- PC_JUMP,
236
- PC_EXC,
237
- PC_ERET,
238
- PC_DRET,
239
- PC_BP
240
- } pc_sel_e;
241
- // Exception PC mux selection
242
- typedef enum logic [1:0] {
243
- EXC_PC_EXC,
244
- EXC_PC_IRQ,
245
- EXC_PC_DBD,
246
- EXC_PC_DBG_EXC // Exception while in debug mode
247
- } exc_pc_sel_e;
248
- // Interrupt requests
249
- typedef struct packed {
250
- logic irq_software;
251
- logic irq_timer;
252
- logic irq_external;
253
- logic [15:0] irq_fast; // 16 fast interrupts
254
- } irqs_t;
255
- // Exception cause
256
- typedef enum logic [6:0] {
257
- EXC_CAUSE_IRQ_SOFTWARE_M = {1'b1, 6'd03},
258
- EXC_CAUSE_IRQ_TIMER_M = {1'b1, 6'd07},
259
- EXC_CAUSE_IRQ_EXTERNAL_M = {1'b1, 6'd11},
260
- // EXC_CAUSE_IRQ_FAST_0 = {1'b1, 6'd16},
261
- // EXC_CAUSE_IRQ_FAST_15 = {1'b1, 6'd31},
262
- EXC_CAUSE_IRQ_NM = {1'b1, 6'd32},
263
- EXC_CAUSE_INSN_ADDR_MISA = {1'b0, 6'd00},
264
- EXC_CAUSE_INSTR_ACCESS_FAULT = {1'b0, 6'd01},
265
- EXC_CAUSE_ILLEGAL_INSN = {1'b0, 6'd02},
266
- EXC_CAUSE_BREAKPOINT = {1'b0, 6'd03},
267
- EXC_CAUSE_LOAD_ACCESS_FAULT = {1'b0, 6'd05},
268
- EXC_CAUSE_STORE_ACCESS_FAULT = {1'b0, 6'd07},
269
- EXC_CAUSE_ECALL_UMODE = {1'b0, 6'd08},
270
- EXC_CAUSE_ECALL_MMODE = {1'b0, 6'd11}
271
- } exc_cause_e;
272
- // Debug cause
273
- typedef enum logic [2:0] {
274
- DBG_CAUSE_NONE = 3'h0,
275
- DBG_CAUSE_EBREAK = 3'h1,
276
- DBG_CAUSE_TRIGGER = 3'h2,
277
- DBG_CAUSE_HALTREQ = 3'h3,
278
- DBG_CAUSE_STEP = 3'h4
279
- } dbg_cause_e;
280
- // PMP constants
281
- parameter int unsigned PMP_MAX_REGIONS = 16;
282
- parameter int unsigned PMP_CFG_W = 8;
283
- // PMP acces type
284
- parameter int unsigned PMP_I = 0;
285
- parameter int unsigned PMP_I2 = 1;
286
- parameter int unsigned PMP_D = 2;
287
- typedef enum logic [1:0] {
288
- PMP_ACC_EXEC = 2'b00,
289
- PMP_ACC_WRITE = 2'b01,
290
- PMP_ACC_READ = 2'b10
291
- } pmp_req_e;
292
- // PMP cfg structures
293
- typedef enum logic [1:0] {
294
- PMP_MODE_OFF = 2'b00,
295
- PMP_MODE_TOR = 2'b01,
296
- PMP_MODE_NA4 = 2'b10,
297
- PMP_MODE_NAPOT = 2'b11
298
- } pmp_cfg_mode_e;
299
- typedef struct packed {
300
- logic lock;
301
- pmp_cfg_mode_e mode;
302
- logic exec;
303
- logic write;
304
- logic read;
305
- } pmp_cfg_t;
306
- // Machine Security Configuration (ePMP)
307
- typedef struct packed {
308
- logic rlb; // Rule Locking Bypass
309
- logic mmwp; // Machine Mode Whitelist Policy
310
- logic mml; // Machine Mode Lockdown
311
- } pmp_mseccfg_t;
312
- // CSRs
313
- typedef enum logic[11:0] {
314
- // Machine information
315
- CSR_MVENDORID = 12'hF11,
316
- CSR_MARCHID = 12'hF12,
317
- CSR_MIMPID = 12'hF13,
318
- CSR_MHARTID = 12'hF14,
319
- CSR_MCONFIGPTR = 12'hF15,
320
- // Machine trap setup
321
- CSR_MSTATUS = 12'h300,
322
- CSR_MISA = 12'h301,
323
- CSR_MIE = 12'h304,
324
- CSR_MTVEC = 12'h305,
325
- CSR_MCOUNTEREN= 12'h306,
326
- CSR_MSTATUSH = 12'h310,
327
- CSR_MENVCFG = 12'h30A,
328
- CSR_MENVCFGH = 12'h31A,
329
- // Machine trap handling
330
- CSR_MSCRATCH = 12'h340,
331
- CSR_MEPC = 12'h341,
332
- CSR_MCAUSE = 12'h342,
333
- CSR_MTVAL = 12'h343,
334
- CSR_MIP = 12'h344,
335
- // Physical memory protection
336
- CSR_PMPCFG0 = 12'h3A0,
337
- CSR_PMPCFG1 = 12'h3A1,
338
- CSR_PMPCFG2 = 12'h3A2,
339
- CSR_PMPCFG3 = 12'h3A3,
340
- CSR_PMPADDR0 = 12'h3B0,
341
- CSR_PMPADDR1 = 12'h3B1,
342
- CSR_PMPADDR2 = 12'h3B2,
343
- CSR_PMPADDR3 = 12'h3B3,
344
- CSR_PMPADDR4 = 12'h3B4,
345
- CSR_PMPADDR5 = 12'h3B5,
346
- CSR_PMPADDR6 = 12'h3B6,
347
- CSR_PMPADDR7 = 12'h3B7,
348
- CSR_PMPADDR8 = 12'h3B8,
349
- CSR_PMPADDR9 = 12'h3B9,
350
- CSR_PMPADDR10 = 12'h3BA,
351
- CSR_PMPADDR11 = 12'h3BB,
352
- CSR_PMPADDR12 = 12'h3BC,
353
- CSR_PMPADDR13 = 12'h3BD,
354
- CSR_PMPADDR14 = 12'h3BE,
355
- CSR_PMPADDR15 = 12'h3BF,
356
- // ePMP control
357
- CSR_MSECCFG = 12'h747,
358
- CSR_MSECCFGH = 12'h757,
359
- // Debug trigger
360
- CSR_TSELECT = 12'h7A0,
361
- CSR_TDATA1 = 12'h7A1,
362
- CSR_TDATA2 = 12'h7A2,
363
- CSR_TDATA3 = 12'h7A3,
364
- CSR_MCONTEXT = 12'h7A8,
365
- CSR_SCONTEXT = 12'h7AA,
366
- // Debug/trace
367
- CSR_DCSR = 12'h7b0,
368
- CSR_DPC = 12'h7b1,
369
- // Debug
370
- CSR_DSCRATCH0 = 12'h7b2, // optional
371
- CSR_DSCRATCH1 = 12'h7b3, // optional
372
- // Machine Counter/Timers
373
- CSR_MCOUNTINHIBIT = 12'h320,
374
- CSR_MHPMEVENT3 = 12'h323,
375
- CSR_MHPMEVENT4 = 12'h324,
376
- CSR_MHPMEVENT5 = 12'h325,
377
- CSR_MHPMEVENT6 = 12'h326,
378
- CSR_MHPMEVENT7 = 12'h327,
379
- CSR_MHPMEVENT8 = 12'h328,
380
- CSR_MHPMEVENT9 = 12'h329,
381
- CSR_MHPMEVENT10 = 12'h32A,
382
- CSR_MHPMEVENT11 = 12'h32B,
383
- CSR_MHPMEVENT12 = 12'h32C,
384
- CSR_MHPMEVENT13 = 12'h32D,
385
- CSR_MHPMEVENT14 = 12'h32E,
386
- CSR_MHPMEVENT15 = 12'h32F,
387
- CSR_MHPMEVENT16 = 12'h330,
388
- CSR_MHPMEVENT17 = 12'h331,
389
- CSR_MHPMEVENT18 = 12'h332,
390
- CSR_MHPMEVENT19 = 12'h333,
391
- CSR_MHPMEVENT20 = 12'h334,
392
- CSR_MHPMEVENT21 = 12'h335,
393
- CSR_MHPMEVENT22 = 12'h336,
394
- CSR_MHPMEVENT23 = 12'h337,
395
- CSR_MHPMEVENT24 = 12'h338,
396
- CSR_MHPMEVENT25 = 12'h339,
397
- CSR_MHPMEVENT26 = 12'h33A,
398
- CSR_MHPMEVENT27 = 12'h33B,
399
- CSR_MHPMEVENT28 = 12'h33C,
400
- CSR_MHPMEVENT29 = 12'h33D,
401
- CSR_MHPMEVENT30 = 12'h33E,
402
- CSR_MHPMEVENT31 = 12'h33F,
403
- CSR_MCYCLE = 12'hB00,
404
- CSR_MINSTRET = 12'hB02,
405
- CSR_MHPMCOUNTER3 = 12'hB03,
406
- CSR_MHPMCOUNTER4 = 12'hB04,
407
- CSR_MHPMCOUNTER5 = 12'hB05,
408
- CSR_MHPMCOUNTER6 = 12'hB06,
409
- CSR_MHPMCOUNTER7 = 12'hB07,
410
- CSR_MHPMCOUNTER8 = 12'hB08,
411
- CSR_MHPMCOUNTER9 = 12'hB09,
412
- CSR_MHPMCOUNTER10 = 12'hB0A,
413
- CSR_MHPMCOUNTER11 = 12'hB0B,
414
- CSR_MHPMCOUNTER12 = 12'hB0C,
415
- CSR_MHPMCOUNTER13 = 12'hB0D,
416
- CSR_MHPMCOUNTER14 = 12'hB0E,
417
- CSR_MHPMCOUNTER15 = 12'hB0F,
418
- CSR_MHPMCOUNTER16 = 12'hB10,
419
- CSR_MHPMCOUNTER17 = 12'hB11,
420
- CSR_MHPMCOUNTER18 = 12'hB12,
421
- CSR_MHPMCOUNTER19 = 12'hB13,
422
- CSR_MHPMCOUNTER20 = 12'hB14,
423
- CSR_MHPMCOUNTER21 = 12'hB15,
424
- CSR_MHPMCOUNTER22 = 12'hB16,
425
- CSR_MHPMCOUNTER23 = 12'hB17,
426
- CSR_MHPMCOUNTER24 = 12'hB18,
427
- CSR_MHPMCOUNTER25 = 12'hB19,
428
- CSR_MHPMCOUNTER26 = 12'hB1A,
429
- CSR_MHPMCOUNTER27 = 12'hB1B,
430
- CSR_MHPMCOUNTER28 = 12'hB1C,
431
- CSR_MHPMCOUNTER29 = 12'hB1D,
432
- CSR_MHPMCOUNTER30 = 12'hB1E,
433
- CSR_MHPMCOUNTER31 = 12'hB1F,
434
- CSR_MCYCLEH = 12'hB80,
435
- CSR_MINSTRETH = 12'hB82,
436
- CSR_MHPMCOUNTER3H = 12'hB83,
437
- CSR_MHPMCOUNTER4H = 12'hB84,
438
- CSR_MHPMCOUNTER5H = 12'hB85,
439
- CSR_MHPMCOUNTER6H = 12'hB86,
440
- CSR_MHPMCOUNTER7H = 12'hB87,
441
- CSR_MHPMCOUNTER8H = 12'hB88,
442
- CSR_MHPMCOUNTER9H = 12'hB89,
443
- CSR_MHPMCOUNTER10H = 12'hB8A,
444
- CSR_MHPMCOUNTER11H = 12'hB8B,
445
- CSR_MHPMCOUNTER12H = 12'hB8C,
446
- CSR_MHPMCOUNTER13H = 12'hB8D,
447
- CSR_MHPMCOUNTER14H = 12'hB8E,
448
- CSR_MHPMCOUNTER15H = 12'hB8F,
449
- CSR_MHPMCOUNTER16H = 12'hB90,
450
- CSR_MHPMCOUNTER17H = 12'hB91,
451
- CSR_MHPMCOUNTER18H = 12'hB92,
452
- CSR_MHPMCOUNTER19H = 12'hB93,
453
- CSR_MHPMCOUNTER20H = 12'hB94,
454
- CSR_MHPMCOUNTER21H = 12'hB95,
455
- CSR_MHPMCOUNTER22H = 12'hB96,
456
- CSR_MHPMCOUNTER23H = 12'hB97,
457
- CSR_MHPMCOUNTER24H = 12'hB98,
458
- CSR_MHPMCOUNTER25H = 12'hB99,
459
- CSR_MHPMCOUNTER26H = 12'hB9A,
460
- CSR_MHPMCOUNTER27H = 12'hB9B,
461
- CSR_MHPMCOUNTER28H = 12'hB9C,
462
- CSR_MHPMCOUNTER29H = 12'hB9D,
463
- CSR_MHPMCOUNTER30H = 12'hB9E,
464
- CSR_MHPMCOUNTER31H = 12'hB9F,
465
- CSR_CPUCTRL = 12'h7C0,
466
- CSR_SECURESEED = 12'h7C1
467
- } csr_num_e;
468
- // CSR pmp-related offsets
469
- parameter logic [11:0] CSR_OFF_PMP_CFG = 12'h3A0; // pmp_cfg @ 12'h3a0 - 12'h3a3
470
- parameter logic [11:0] CSR_OFF_PMP_ADDR = 12'h3B0; // pmp_addr @ 12'h3b0 - 12'h3bf
471
- // CSR status bits
472
- parameter int unsigned CSR_MSTATUS_MIE_BIT = 3;
473
- parameter int unsigned CSR_MSTATUS_MPIE_BIT = 7;
474
- parameter int unsigned CSR_MSTATUS_MPP_BIT_LOW = 11;
475
- parameter int unsigned CSR_MSTATUS_MPP_BIT_HIGH = 12;
476
- parameter int unsigned CSR_MSTATUS_MPRV_BIT = 17;
477
- parameter int unsigned CSR_MSTATUS_TW_BIT = 21;
478
- // CSR machine ISA
479
- parameter logic [1:0] CSR_MISA_MXL = 2'd1; // M-XLEN: XLEN in M-Mode for RV32
480
- // CSR interrupt pending/enable bits
481
- parameter int unsigned CSR_MSIX_BIT = 3;
482
- parameter int unsigned CSR_MTIX_BIT = 7;
483
- parameter int unsigned CSR_MEIX_BIT = 11;
484
- parameter int unsigned CSR_MFIX_BIT_LOW = 16;
485
- parameter int unsigned CSR_MFIX_BIT_HIGH = 31;
486
- // CSR Machine Security Configuration bits
487
- parameter int unsigned CSR_MSECCFG_MML_BIT = 0;
488
- parameter int unsigned CSR_MSECCFG_MMWP_BIT = 1;
489
- parameter int unsigned CSR_MSECCFG_RLB_BIT = 2;
490
- // Machine Vendor ID - OpenHW JEDEC ID is '2 decimal (bank 13)'
491
- parameter MVENDORID_OFFSET = 7'h2; // Final byte without parity bit
492
- parameter MVENDORID_BANK = 25'hC; // Number of continuation codes
493
- // Machine Architecture ID (https://github.com/riscv/riscv-isa-manual/blob/master/marchid.md)
494
- parameter MARCHID = 32'd35;
495
- localparam logic [31:0] CSR_MVENDORID_VALUE = {MVENDORID_BANK, MVENDORID_OFFSET};
496
- localparam logic [31:0] CSR_MARCHID_VALUE = MARCHID;
497
- // Implementation ID
498
- // 0 indicates this field is not implemeted. cve2 implementors may wish to indicate an RTL/netlist
499
- // version here using their own unique encoding (e.g. 32 bits of the git hash of the implemented
500
- // commit).
501
- localparam logic [31:0] CSR_MIMPID_VALUE = 32'b0;
502
- // Machine Configuration Pointer
503
- // 0 indicates the configuration data structure does not eixst. cve2 implementors may wish to
504
- // alter this to point to their system specific configuration data structure.
505
- localparam logic [31:0] CSR_MCONFIGPTR_VALUE = 32'b0;
506
- // RVFI CSR element
507
- typedef struct packed {
508
- bit [63:0] rdata;
509
- bit [63:0] rmask;
510
- bit [63:0] wdata;
511
- bit [63:0] wmask;
512
- } rvfi_csr_elmt_t;
513
- // RVFI CSR structure
514
- typedef struct packed {
515
- rvfi_csr_elmt_t fflags;
516
- rvfi_csr_elmt_t frm;
517
- rvfi_csr_elmt_t fcsr;
518
- rvfi_csr_elmt_t ftran;
519
- rvfi_csr_elmt_t dcsr;
520
- rvfi_csr_elmt_t dpc;
521
- rvfi_csr_elmt_t dscratch0;
522
- rvfi_csr_elmt_t dscratch1;
523
- rvfi_csr_elmt_t sstatus;
524
- rvfi_csr_elmt_t sie;
525
- rvfi_csr_elmt_t sip;
526
- rvfi_csr_elmt_t stvec;
527
- rvfi_csr_elmt_t scounteren;
528
- rvfi_csr_elmt_t sscratch;
529
- rvfi_csr_elmt_t sepc;
530
- rvfi_csr_elmt_t scause;
531
- rvfi_csr_elmt_t stval;
532
- rvfi_csr_elmt_t satp;
533
- rvfi_csr_elmt_t mstatus;
534
- rvfi_csr_elmt_t mstatush;
535
- rvfi_csr_elmt_t misa;
536
- rvfi_csr_elmt_t medeleg;
537
- rvfi_csr_elmt_t mideleg;
538
- rvfi_csr_elmt_t mie;
539
- rvfi_csr_elmt_t mtvec;
540
- rvfi_csr_elmt_t mcounteren;
541
- rvfi_csr_elmt_t mscratch;
542
- rvfi_csr_elmt_t mepc;
543
- rvfi_csr_elmt_t mcause;
544
- rvfi_csr_elmt_t mtval;
545
- rvfi_csr_elmt_t mip;
546
- rvfi_csr_elmt_t menvcfg;
547
- rvfi_csr_elmt_t menvcfgh;
548
- rvfi_csr_elmt_t mvendorid;
549
- rvfi_csr_elmt_t marchid;
550
- rvfi_csr_elmt_t mhartid;
551
- rvfi_csr_elmt_t mcountinhibit;
552
- rvfi_csr_elmt_t mcycle;
553
- rvfi_csr_elmt_t mcycleh;
554
- rvfi_csr_elmt_t minstret;
555
- rvfi_csr_elmt_t minstreth;
556
- rvfi_csr_elmt_t cycle;
557
- rvfi_csr_elmt_t cycleh;
558
- rvfi_csr_elmt_t instret;
559
- rvfi_csr_elmt_t instreth;
560
- rvfi_csr_elmt_t dcache;
561
- rvfi_csr_elmt_t icache;
562
- rvfi_csr_elmt_t acc_cons;
563
- rvfi_csr_elmt_t pmpcfg0;
564
- rvfi_csr_elmt_t pmpcfg1;
565
- rvfi_csr_elmt_t pmpcfg2;
566
- rvfi_csr_elmt_t pmpcfg3;
567
- rvfi_csr_elmt_t pmpaddr0;
568
- rvfi_csr_elmt_t pmpaddr1;
569
- rvfi_csr_elmt_t pmpaddr2;
570
- rvfi_csr_elmt_t pmpaddr3;
571
- rvfi_csr_elmt_t pmpaddr4;
572
- rvfi_csr_elmt_t pmpaddr5;
573
- rvfi_csr_elmt_t pmpaddr6;
574
- rvfi_csr_elmt_t pmpaddr7;
575
- rvfi_csr_elmt_t pmpaddr8;
576
- rvfi_csr_elmt_t pmpaddr9;
577
- rvfi_csr_elmt_t pmpaddr10;
578
- rvfi_csr_elmt_t pmpaddr11;
579
- rvfi_csr_elmt_t pmpaddr12;
580
- rvfi_csr_elmt_t pmpaddr13;
581
- rvfi_csr_elmt_t pmpaddr14;
582
- rvfi_csr_elmt_t pmpaddr15;
583
- } rvfi_csr_t;
584
- // CV-X-IF
585
- parameter int unsigned X_NUM_RS = 3;
586
- parameter int unsigned X_ID_WIDTH = 4;
587
- parameter int unsigned X_RFR_WIDTH = 32;
588
- parameter int unsigned X_RFW_WIDTH = 32;
589
- parameter int unsigned X_HARTID_WIDTH = 32;
590
- parameter int unsigned X_DUAL_READ = 0;
591
- parameter int unsigned X_DUAL_WRITE = 0;
592
- parameter int unsigned X_INSTR_INFLIGHT = 2**X_ID_WIDTH;
593
- typedef logic [X_NUM_RS+X_DUAL_READ-1:0] readregflags_t;
594
- typedef logic [X_DUAL_WRITE:0] writeregflags_t;
595
- typedef logic [X_ID_WIDTH-1:0] id_t;
596
- typedef logic [X_HARTID_WIDTH-1:0] hartid_t;
597
- // Issue Interface
598
- typedef struct packed {
599
- logic [31:0] instr;
600
- hartid_t hartid;
601
- id_t id;
602
- } x_issue_req_t;
603
- typedef struct packed {
604
- logic accept;
605
- writeregflags_t writeback;
606
- readregflags_t register_read;
607
- } x_issue_resp_t;
608
- // Register Interface
609
- typedef struct packed {
610
- hartid_t hartid;
611
- id_t id;
612
- logic [X_NUM_RS-1:0][X_RFR_WIDTH-1:0] rs;
613
- readregflags_t rs_valid;
614
- } x_register_t;
615
- // Commit Interface
616
- typedef struct packed {
617
- hartid_t hartid;
618
- id_t id;
619
- logic commit_kill;
620
- } x_commit_t;
621
- // Result Interface
622
- typedef struct packed {
623
- hartid_t hartid;
624
- id_t id;
625
- logic [X_RFW_WIDTH-1:0] data;
626
- logic [4:0] rd;
627
- writeregflags_t we;
628
- } x_result_t;
629
- endpackage
630
- // Copyright (c) 2025 Eclipse Foundation
631
- // Copyright lowRISC contributors.
632
- // Copyright 2018 ETH Zurich and University of Bologna, see also CREDITS.md.
633
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
634
- // SPDX-License-Identifier: Apache-2.0
635
- /**
636
- * Slow Multiplier and Division
637
- *
638
- * Baugh-Wooley multiplier and Long Division
639
- */
640
- // Copyright lowRISC contributors.
641
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
642
- // SPDX-License-Identifier: Apache-2.0
643
- // Macros and helper code for using assertions.
644
- // - Provides default clk and rst options to simplify code
645
- // - Provides boiler plate template for common assertions
646
- ///////////////////
647
- // Helper macros //
648
- ///////////////////
649
- // Default clk and reset signals used by assertion macros below.
650
- // Converts an arbitrary block of code into a Verilog string
651
- // ASSERT_ERROR logs an error message with either `uvm_error or with $error.
652
- //
653
- // This somewhat duplicates `DV_ERROR macro defined in hw/dv/sv/dv_utils/dv_macros.svh. The reason
654
- // for redefining it here is to avoid creating a dependency.
655
- // This macro is suitable for conditionally triggering lint errors, e.g., if a Sec parameter takes
656
- // on a non-default value. This may be required for pre-silicon/FPGA evaluation but we don't want
657
- // to allow this for tapeout.
658
- // The basic helper macros are actually defined in "implementation headers". The macros should do
659
- // the same thing in each case (except for the dummy flavour), but in a way that the respective
660
- // tools support.
661
- //
662
- // If the tool supports assertions in some form, we also define INC_ASSERT (which can be used to
663
- // hide signal definitions that are only used for assertions).
664
- //
665
- // The list of basic macros supported is:
666
- //
667
- // ASSERT_I: Immediate assertion. Note that immediate assertions are sensitive to simulation
668
- // glitches.
669
- //
670
- // ASSERT_INIT: Assertion in initial block. Can be used for things like parameter checking.
671
- //
672
- // ASSERT_INIT_NET: Assertion in initial block. Can be used for initial value of a net.
673
- //
674
- // ASSERT_FINAL: Assertion in final block. Can be used for things like queues being empty at end of
675
- // sim, all credits returned at end of sim, state machines in idle at end of sim.
676
- //
677
- // ASSERT: Assert a concurrent property directly. It can be called as a module (or
678
- // interface) body item.
679
- //
680
- // Note: We use (__rst !== '0) in the disable iff statements instead of (__rst ==
681
- // '1). This properly disables the assertion in cases when reset is X at the
682
- // beginning of a simulation. For that case, (reset == '1) does not disable the
683
- // assertion.
684
- //
685
- // ASSERT_NEVER: Assert a concurrent property NEVER happens
686
- //
687
- // ASSERT_KNOWN: Assert that signal has a known value (each bit is either '0' or '1') after reset.
688
- // It can be called as a module (or interface) body item.
689
- //
690
- // COVER: Cover a concurrent property
691
- //
692
- // ASSUME: Assume a concurrent property
693
- //
694
- // ASSUME_I: Assume an immediate property
695
- // Copyright lowRISC contributors.
696
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
697
- // SPDX-License-Identifier: Apache-2.0
698
- // Macro bodies included by prim_assert.sv for tools that don't support assertions. See
699
- // prim_assert.sv for documentation for each of the macros.
700
- //////////////////////////////
701
- // Complex assertion macros //
702
- //////////////////////////////
703
- // Assert that signal is an active-high pulse with pulse length of 1 clock cycle
704
- // Assert that a property is true only when an enable signal is set. It can be called as a module
705
- // (or interface) body item.
706
- // Assert that signal has a known value (each bit is either '0' or '1') after reset if enable is
707
- // set. It can be called as a module (or interface) body item.
708
- //////////////////////////////////
709
- // For formal verification only //
710
- //////////////////////////////////
711
- // Note that the existing set of ASSERT macros specified above shall be used for FPV,
712
- // thereby ensuring that the assertions are evaluated during DV simulations as well.
713
- // ASSUME_FPV
714
- // Assume a concurrent property during formal verification only.
715
- // ASSUME_I_FPV
716
- // Assume a concurrent property during formal verification only.
717
- // COVER_FPV
718
- // Cover a concurrent property during formal verification
719
- // Copyright lowRISC contributors.
720
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
721
- // SPDX-License-Identifier: Apache-2.0
722
- // // Macros and helper code for security countermeasures.
723
- // Helper macros
724
- // macros for security countermeasures
725
- // PRIM_ASSERT_SEC_CM_SVH
726
- // PRIM_ASSERT_SV
727
- module cve2_multdiv_slow
728
- (
729
- input logic clk_i,
730
- input logic rst_ni,
731
- input logic mult_en_i, // dynamic enable signal, for FSM control
732
- input logic div_en_i, // dynamic enable signal, for FSM control
733
- input logic mult_sel_i, // static decoder output, for data muxes
734
- input logic div_sel_i, // static decoder output, for data muxes
735
- input cve2_pkg::md_op_e operator_i,
736
- input logic [1:0] signed_mode_i,
737
- input logic [31:0] op_a_i,
738
- input logic [31:0] op_b_i,
739
- input logic [33:0] alu_adder_ext_i,
740
- input logic [31:0] alu_adder_i,
741
- input logic equal_to_zero_i,
742
- output logic [32:0] alu_operand_a_o,
743
- output logic [32:0] alu_operand_b_o,
744
- input logic [33:0] imd_val_q_i[2],
745
- output logic [33:0] imd_val_d_o[2],
746
- output logic [1:0] imd_val_we_o,
747
- input logic multdiv_ready_id_i,
748
- output logic [31:0] multdiv_result_o,
749
- output logic valid_o
750
- );
751
- import cve2_pkg::*;
752
- typedef enum logic [2:0] {
753
- MD_IDLE, MD_ABS_A, MD_ABS_B, MD_COMP, MD_LAST, MD_CHANGE_SIGN, MD_FINISH
754
- } md_fsm_e;
755
- md_fsm_e md_state_q, md_state_d;
756
- logic [32:0] accum_window_q, accum_window_d;
757
- logic unused_imd_val0;
758
- logic [ 1:0] unused_imd_val1;
759
- logic [32:0] res_adder_l;
760
- logic [32:0] res_adder_h;
761
- logic [ 4:0] multdiv_count_q, multdiv_count_d;
762
- logic [32:0] op_b_shift_q, op_b_shift_d;
763
- logic [32:0] op_a_shift_q, op_a_shift_d;
764
- logic [32:0] op_a_ext, op_b_ext;
765
- logic [32:0] one_shift;
766
- logic [32:0] op_a_bw_pp, op_a_bw_last_pp;
767
- logic [31:0] b_0;
768
- logic sign_a, sign_b;
769
- logic [32:0] next_quotient;
770
- logic [31:0] next_remainder;
771
- logic [31:0] op_numerator_q, op_numerator_d;
772
- logic is_greater_equal;
773
- logic div_change_sign, rem_change_sign;
774
- logic div_by_zero_d, div_by_zero_q;
775
- logic multdiv_hold;
776
- logic multdiv_en;
777
- // (accum_window_q + op_a_shift_q)
778
- assign res_adder_l = alu_adder_ext_i[32:0];
779
- // (accum_window_q + op_a_shift_q)>>1
780
- assign res_adder_h = alu_adder_ext_i[33:1];
781
- /////////////////////
782
- // ALU Operand MUX //
783
- /////////////////////
784
- // Intermediate value register shared with ALU
785
- assign imd_val_d_o[0] = {1'b0,accum_window_d};
786
- assign imd_val_we_o[0] = ~multdiv_hold;
787
- assign accum_window_q = imd_val_q_i[0][32:0];
788
- assign unused_imd_val0 = imd_val_q_i[0][33];
789
- assign imd_val_d_o[1] = {2'b00, op_numerator_d};
790
- assign imd_val_we_o[1] = multdiv_en;
791
- assign op_numerator_q = imd_val_q_i[1][31:0];
792
- assign unused_imd_val1 = imd_val_q_i[1][33:32];
793
- always_comb begin
794
- alu_operand_a_o = accum_window_q;
795
- unique case (operator_i)
796
- MD_OP_MULL: begin
797
- alu_operand_b_o = op_a_bw_pp;
798
- end
799
- MD_OP_MULH: begin
800
- alu_operand_b_o = (md_state_q == MD_LAST) ? op_a_bw_last_pp : op_a_bw_pp;
801
- end
802
- MD_OP_DIV,
803
- MD_OP_REM: begin
804
- unique case (md_state_q)
805
- MD_IDLE: begin
806
- // 0 - B = 0 iff B == 0
807
- alu_operand_a_o = {32'h0 , 1'b1};
808
- alu_operand_b_o = {~op_b_i, 1'b1};
809
- end
810
- MD_ABS_A: begin
811
- // ABS(A) = 0 - A
812
- alu_operand_a_o = {32'h0 , 1'b1};
813
- alu_operand_b_o = {~op_a_i, 1'b1};
814
- end
815
- MD_ABS_B: begin
816
- // ABS(B) = 0 - B
817
- alu_operand_a_o = {32'h0 , 1'b1};
818
- alu_operand_b_o = {~op_b_i, 1'b1};
819
- end
820
- MD_CHANGE_SIGN: begin
821
- // ABS(Quotient) = 0 - Quotient (or Reminder)
822
- alu_operand_a_o = {32'h0 , 1'b1};
823
- alu_operand_b_o = {~accum_window_q[31:0], 1'b1};
824
- end
825
- default: begin
826
- // Division
827
- alu_operand_a_o = {accum_window_q[31:0], 1'b1}; // it contains the remainder
828
- alu_operand_b_o = {~op_b_shift_q[31:0], 1'b1}; // -denominator two's compliment
829
- end
830
- endcase
831
- end
832
- default: begin
833
- alu_operand_a_o = accum_window_q;
834
- alu_operand_b_o = {~op_b_shift_q[31:0], 1'b1};
835
- end
836
- endcase
837
- end
838
- // Multiplier partial product calculation
839
- assign b_0 = {32{op_b_shift_q[0]}};
840
- assign op_a_bw_pp = { ~(op_a_shift_q[32] & op_b_shift_q[0]), (op_a_shift_q[31:0] & b_0) };
841
- assign op_a_bw_last_pp = { (op_a_shift_q[32] & op_b_shift_q[0]), ~(op_a_shift_q[31:0] & b_0) };
842
- // Sign extend the input operands
843
- assign sign_a = op_a_i[31] & signed_mode_i[0];
844
- assign sign_b = op_b_i[31] & signed_mode_i[1];
845
- assign op_a_ext = {sign_a, op_a_i};
846
- assign op_b_ext = {sign_b, op_b_i};
847
- // Divider calculations
848
- // The adder in the ALU computes Remainder - Divisor. If Remainder - Divisor >= 0,
849
- // is_greater_equal is true, the next Remainder is the subtraction result and the Quotient
850
- // multdiv_count_q-th bit is set to 1.
851
- assign is_greater_equal = (accum_window_q[31] == op_b_shift_q[31]) ?
852
- ~res_adder_h[31] : accum_window_q[31];
853
- assign one_shift = {32'b0, 1'b1} << multdiv_count_q;
854
- assign next_remainder = is_greater_equal ? res_adder_h[31:0] : accum_window_q[31:0];
855
- assign next_quotient = is_greater_equal ? op_a_shift_q | one_shift : op_a_shift_q;
856
- assign div_change_sign = (sign_a ^ sign_b) & ~div_by_zero_q;
857
- assign rem_change_sign = sign_a;
858
- always_comb begin
859
- multdiv_count_d = multdiv_count_q;
860
- accum_window_d = accum_window_q;
861
- op_b_shift_d = op_b_shift_q;
862
- op_a_shift_d = op_a_shift_q;
863
- op_numerator_d = op_numerator_q;
864
- md_state_d = md_state_q;
865
- multdiv_hold = 1'b0;
866
- div_by_zero_d = div_by_zero_q;
867
- if (mult_sel_i || div_sel_i) begin
868
- unique case (md_state_q)
869
- MD_IDLE: begin
870
- unique case (operator_i)
871
- MD_OP_MULL: begin
872
- op_a_shift_d = op_a_ext << 1;
873
- accum_window_d = { ~(op_a_ext[32] & op_b_i[0]),
874
- op_a_ext[31:0] & {32{op_b_i[0]}} };
875
- op_b_shift_d = op_b_ext >> 1;
876
- // Proceed with multiplication by 0/1 in data-independent time mode
877
- // SEC_CM: CORE.DATA_REG_SW.SCA
878
- md_state_d = ((op_b_ext >> 1) == 0) ? MD_LAST : MD_COMP;
879
- end
880
- MD_OP_MULH: begin
881
- op_a_shift_d = op_a_ext;
882
- accum_window_d = { 1'b1, ~(op_a_ext[32] & op_b_i[0]),
883
- op_a_ext[31:1] & {31{op_b_i[0]}} };
884
- op_b_shift_d = op_b_ext >> 1;
885
- md_state_d = MD_COMP;
886
- end
887
- MD_OP_DIV: begin
888
- // Check if the denominator is 0
889
- // quotient for division by 0 is specified to be -1
890
- // Note with data-independent time option, the full divide operation will proceed as
891
- // normal and will naturally return -1
892
- accum_window_d = {33{1'b1}};
893
- // SEC_CM: CORE.DATA_REG_SW.SCA
894
- md_state_d = equal_to_zero_i ? MD_FINISH : MD_ABS_A;
895
- // Record that this is a div by zero to stop the sign change at the end of the
896
- // division (in data_ind_timing mode).
897
- div_by_zero_d = equal_to_zero_i;
898
- end
899
- MD_OP_REM: begin
900
- // Check if the denominator is 0
901
- // remainder for division by 0 is specified to be the numerator (operand a)
902
- // Note with data-independent time option, the full divide operation will proceed as
903
- // normal and will naturally return operand a
904
- accum_window_d = op_a_ext;
905
- // SEC_CM: CORE.DATA_REG_SW.SCA
906
- md_state_d = equal_to_zero_i ? MD_FINISH : MD_ABS_A;
907
- end
908
- default:;
909
- endcase
910
- multdiv_count_d = 5'd31;
911
- end
912
- MD_ABS_A: begin
913
- // quotient
914
- op_a_shift_d = '0;
915
- // A abs value
916
- op_numerator_d = sign_a ? alu_adder_i : op_a_i;
917
- md_state_d = MD_ABS_B;
918
- end
919
- MD_ABS_B: begin
920
- // remainder
921
- accum_window_d = {32'h0, op_numerator_q[31]};
922
- // B abs value
923
- op_b_shift_d = sign_b ? {1'b0, alu_adder_i} : {1'b0, op_b_i};
924
- md_state_d = MD_COMP;
925
- end
926
- MD_COMP: begin
927
- multdiv_count_d = multdiv_count_q - 5'h1;
928
- unique case (operator_i)
929
- MD_OP_MULL: begin
930
- accum_window_d = res_adder_l;
931
- op_a_shift_d = op_a_shift_q << 1;
932
- op_b_shift_d = op_b_shift_q >> 1;
933
- // Multiplication is complete once op_b is zero, unless in data_ind_timing mode where
934
- // the maximum possible shift-add operations will be completed regardless of op_b
935
- // SEC_CM: CORE.DATA_REG_SW.SCA
936
- md_state_d = ((op_b_shift_d == 0) ||
937
- (multdiv_count_q == 5'd1)) ? MD_LAST : MD_COMP;
938
- end
939
- MD_OP_MULH: begin
940
- accum_window_d = res_adder_h;
941
- op_a_shift_d = op_a_shift_q;
942
- op_b_shift_d = op_b_shift_q >> 1;
943
- md_state_d = (multdiv_count_q == 5'd1) ? MD_LAST : MD_COMP;
944
- end
945
- MD_OP_DIV,
946
- MD_OP_REM: begin
947
- accum_window_d = {next_remainder[31:0], op_numerator_q[multdiv_count_d]};
948
- op_a_shift_d = next_quotient;
949
- md_state_d = (multdiv_count_q == 5'd1) ? MD_LAST : MD_COMP;
950
- end
951
- default: ;
952
- endcase
953
- end
954
- MD_LAST: begin
955
- unique case (operator_i)
956
- MD_OP_MULL: begin
957
- accum_window_d = res_adder_l;
958
- // Note no state transition will occur if multdiv_hold is set
959
- md_state_d = MD_IDLE;
960
- multdiv_hold = ~multdiv_ready_id_i;
961
- end
962
- MD_OP_MULH: begin
963
- accum_window_d = res_adder_l;
964
- md_state_d = MD_IDLE;
965
- // Note no state transition will occur if multdiv_hold is set
966
- md_state_d = MD_IDLE;
967
- multdiv_hold = ~multdiv_ready_id_i;
968
- end
969
- MD_OP_DIV: begin
970
- // this time we save the quotient in accum_window_q since we do not need anymore the
971
- // remainder
972
- accum_window_d = next_quotient;
973
- md_state_d = MD_CHANGE_SIGN;
974
- end
975
- MD_OP_REM: begin
976
- // this time we do not save the quotient anymore since we need only the remainder
977
- accum_window_d = {1'b0, next_remainder[31:0]};
978
- md_state_d = MD_CHANGE_SIGN;
979
- end
980
- default: ;
981
- endcase
982
- end
983
- MD_CHANGE_SIGN: begin
984
- md_state_d = MD_FINISH;
985
- unique case (operator_i)
986
- MD_OP_DIV:
987
- accum_window_d = div_change_sign ? {1'b0,alu_adder_i} : accum_window_q;
988
- MD_OP_REM:
989
- accum_window_d = rem_change_sign ? {1'b0,alu_adder_i} : accum_window_q;
990
- default: ;
991
- endcase
992
- end
993
- MD_FINISH: begin
994
- // Note no state transition will occur if multdiv_hold is set
995
- md_state_d = MD_IDLE;
996
- multdiv_hold = ~multdiv_ready_id_i;
997
- end
998
- default: begin
999
- md_state_d = MD_IDLE;
1000
- end
1001
- endcase // md_state_q
1002
- end // (mult_sel_i || div_sel_i)
1003
- end
1004
- //////////////////////////////////////////
1005
- // Mutliplier / Divider state registers //
1006
- //////////////////////////////////////////
1007
- assign multdiv_en = (mult_en_i | div_en_i) & ~multdiv_hold;
1008
- always_ff @(posedge clk_i or negedge rst_ni) begin
1009
- if (!rst_ni) begin
1010
- multdiv_count_q <= 5'h0;
1011
- op_b_shift_q <= 33'h0;
1012
- op_a_shift_q <= 33'h0;
1013
- md_state_q <= MD_IDLE;
1014
- div_by_zero_q <= 1'b0;
1015
- end else if (multdiv_en) begin
1016
- multdiv_count_q <= multdiv_count_d;
1017
- op_b_shift_q <= op_b_shift_d;
1018
- op_a_shift_q <= op_a_shift_d;
1019
- md_state_q <= md_state_d;
1020
- div_by_zero_q <= div_by_zero_d;
1021
- end
1022
- end
1023
- /////////////
1024
- // Outputs //
1025
- /////////////
1026
- assign valid_o = (md_state_q == MD_FINISH) |
1027
- (md_state_q == MD_LAST &
1028
- (operator_i == MD_OP_MULL |
1029
- operator_i == MD_OP_MULH));
1030
- assign multdiv_result_o = div_en_i ? accum_window_q[31:0] : res_adder_l[31:0];
1031
- ////////////////
1032
- // Assertions //
1033
- ////////////////
1034
- // State must be valid.
1035
- endmodule
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p10/mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"conditional_statement": [[28548, 34336], [34597, 35025], [34794, 35025]], "blocking_assignment": [[33686, 33709], [30493, 30519], [30703, 30729], [28294, 28328], [33544, 33576], [32011, 32046], [30854, 30901], [29402, 29433]], "always_construct": [[25551, 27022], [34542, 35031], [28232, 34342]], "case_statement": [[32507, 33633], [33720, 34003], [25611, 27016], [28589, 34299], [28647, 30692], [25872, 26866], [31286, 32461]], "ansi_port_declaration": [[22940, 22971], [23526, 23563], [23566, 23607], [23825, 23869], [23370, 23409], [23872, 23914], [23009, 23087]], "continuous_assign": [[27353, 27401], [25006, 25049], [25173, 25220], [25223, 25262], [25361, 25410], [27776, 27889], [27218, 27314], [28132, 28193]], "parameter_declaration": [[16850, 16895], [16993, 17037], [13787, 13814], [16802, 16847], [16898, 16943], [16946, 16990], [13622, 13688], [16755, 16799]], "nonblocking_assignment": [[34822, 34858], [34865, 34898], [34945, 34976], [34983, 35017], [34905, 34938]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p11/all_mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"module_program_interface_instantiation": [], "continuous_assign": [[20455, 20639], [20673, 20863], [21059, 21133], [21507, 21652], [21725, 21885], [22114, 22390], [22397, 22548], [22555, 22703], [23341, 23604], [26771, 26813], [27023, 27081]], "blocking_assignment": [[22736, 22766], [22837, 22867], [22894, 22941], [22968, 23015], [23058, 23192], [23233, 23263], [23708, 23743], [24011, 24183], [24238, 24359], [24416, 24482], [24556, 24727], [25018, 25082], [25276, 25506], [25743, 25817], [26197, 26244], [26334, 26722]], "nonblocking_assignment": [], "case_statement": [[22775, 23279], [23882, 24768]], "conditional_statement": [[23752, 25532], [24802, 25520], [26035, 26748], [26079, 26736]], "always_construct": [[22710, 23289], [23682, 25542], [25606, 26766]], "parameter_declaration": [[6471, 6520], [6523, 6571], [6594, 6628], [6631, 6665], [6668, 6702], [12379, 12461], [12464, 12546], [12570, 12622], [12625, 12677], [12680, 12733], [12736, 12789], [12792, 12845], [12848, 12901], [12925, 13002], [13044, 13089], [13092, 13137], [13140, 13186], [13189, 13235], [13238, 13284], [13332, 13380], [13383, 13431], [13434, 13482], [13551, 13619], [13622, 13688], [13787, 13814], [16708, 16752], [16755, 16799], [16802, 16847], [16850, 16895], [16898, 16943], [16946, 16990], [16993, 17037], [17040, 17096], [18688, 18730], [18787, 18829], [18867, 18908]], "ansi_port_declaration": [[18936, 18974], [18977, 19016], [19042, 19108], [19111, 19177], [19180, 19230], [19233, 19293], [19326, 19386], [19389, 19449], [19452, 19511]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p11/cve2_pmp.sv DELETED
@@ -1,798 +0,0 @@
1
- // Copyright (c) 2025 Eclipse Foundation
2
- // Copyright lowRISC contributors.
3
- // Copyright 2017 ETH Zurich and University of Bologna, see also CREDITS.md.
4
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
5
- // SPDX-License-Identifier: Apache-2.0
6
- /**
7
- * Package with constants used by CVE2
8
- */
9
- package cve2_pkg;
10
- ////////////////
11
- // IO Structs //
12
- ////////////////
13
- typedef struct packed {
14
- logic [31:0] current_pc;
15
- logic [31:0] next_pc;
16
- logic [31:0] last_data_addr;
17
- logic [31:0] exception_addr;
18
- } crash_dump_t;
19
- typedef struct packed {
20
- logic dummy_instr_id;
21
- logic [4:0] raddr_a;
22
- logic [4:0] waddr_a;
23
- logic we_a;
24
- logic [4:0] raddr_b;
25
- } core2rf_t;
26
- /////////////////////
27
- // Parameter Enums //
28
- /////////////////////
29
- typedef enum integer {
30
- RV32MNone = 0,
31
- RV32MSlow = 1,
32
- RV32MFast = 2,
33
- RV32MSingleCycle = 3
34
- } rv32m_e;
35
- typedef enum integer {
36
- RV32BNone = 0,
37
- RV32BBalanced = 1,
38
- RV32BOTEarlGrey = 2,
39
- RV32BFull = 3
40
- } rv32b_e;
41
- /////////////
42
- // Opcodes //
43
- /////////////
44
- typedef enum logic [6:0] {
45
- OPCODE_LOAD = 7'h03,
46
- OPCODE_MISC_MEM = 7'h0f,
47
- OPCODE_OP_IMM = 7'h13,
48
- OPCODE_AUIPC = 7'h17,
49
- OPCODE_STORE = 7'h23,
50
- OPCODE_OP = 7'h33,
51
- OPCODE_LUI = 7'h37,
52
- OPCODE_BRANCH = 7'h63,
53
- OPCODE_JALR = 7'h67,
54
- OPCODE_JAL = 7'h6f,
55
- OPCODE_SYSTEM = 7'h73
56
- } opcode_e;
57
- ////////////////////
58
- // ALU operations //
59
- ////////////////////
60
- typedef enum logic [6:0] {
61
- // Arithmetics
62
- ALU_ADD,
63
- ALU_SUB,
64
- // Logics
65
- ALU_XOR,
66
- ALU_OR,
67
- ALU_AND,
68
- // RV32B
69
- ALU_XNOR,
70
- ALU_ORN,
71
- ALU_ANDN,
72
- // Shifts
73
- ALU_SRA,
74
- ALU_SRL,
75
- ALU_SLL,
76
- // RV32B
77
- ALU_SRO,
78
- ALU_SLO,
79
- ALU_ROR,
80
- ALU_ROL,
81
- ALU_GREV,
82
- ALU_GORC,
83
- ALU_SHFL,
84
- ALU_UNSHFL,
85
- ALU_XPERM_N,
86
- ALU_XPERM_B,
87
- ALU_XPERM_H,
88
- // Address Calculations
89
- // RV32B
90
- ALU_SH1ADD,
91
- ALU_SH2ADD,
92
- ALU_SH3ADD,
93
- // Comparisons
94
- ALU_LT,
95
- ALU_LTU,
96
- ALU_GE,
97
- ALU_GEU,
98
- ALU_EQ,
99
- ALU_NE,
100
- // RV32B
101
- ALU_MIN,
102
- ALU_MINU,
103
- ALU_MAX,
104
- ALU_MAXU,
105
- // Pack
106
- // RV32B
107
- ALU_PACK,
108
- ALU_PACKU,
109
- ALU_PACKH,
110
- // Sign-Extend
111
- // RV32B
112
- ALU_SEXTB,
113
- ALU_SEXTH,
114
- // Bitcounting
115
- // RV32B
116
- ALU_CLZ,
117
- ALU_CTZ,
118
- ALU_CPOP,
119
- // Set lower than
120
- ALU_SLT,
121
- ALU_SLTU,
122
- // Ternary Bitmanip Operations
123
- // RV32B
124
- ALU_CMOV,
125
- ALU_CMIX,
126
- ALU_FSL,
127
- ALU_FSR,
128
- // Single-Bit Operations
129
- // RV32B
130
- ALU_BSET,
131
- ALU_BCLR,
132
- ALU_BINV,
133
- ALU_BEXT,
134
- // Bit Compress / Decompress
135
- // RV32B
136
- ALU_BCOMPRESS,
137
- ALU_BDECOMPRESS,
138
- // Bit Field Place
139
- // RV32B
140
- ALU_BFP,
141
- // Carry-less Multiply
142
- // RV32B
143
- ALU_CLMUL,
144
- ALU_CLMULR,
145
- ALU_CLMULH,
146
- // Cyclic Redundancy Check
147
- ALU_CRC32_B,
148
- ALU_CRC32C_B,
149
- ALU_CRC32_H,
150
- ALU_CRC32C_H,
151
- ALU_CRC32_W,
152
- ALU_CRC32C_W
153
- } alu_op_e;
154
- typedef enum logic [1:0] {
155
- // Multiplier/divider
156
- MD_OP_MULL,
157
- MD_OP_MULH,
158
- MD_OP_DIV,
159
- MD_OP_REM
160
- } md_op_e;
161
- //////////////////////////////////
162
- // Control and status registers //
163
- //////////////////////////////////
164
- // CSR operations
165
- typedef enum logic [1:0] {
166
- CSR_OP_READ,
167
- CSR_OP_WRITE,
168
- CSR_OP_SET,
169
- CSR_OP_CLEAR
170
- } csr_op_e;
171
- // Privileged mode
172
- typedef enum logic[1:0] {
173
- PRIV_LVL_M = 2'b11,
174
- PRIV_LVL_H = 2'b10,
175
- PRIV_LVL_S = 2'b01,
176
- PRIV_LVL_U = 2'b00
177
- } priv_lvl_e;
178
- // Constants for the dcsr.xdebugver fields
179
- typedef enum logic[3:0] {
180
- XDEBUGVER_NO = 4'd0, // no external debug support
181
- XDEBUGVER_STD = 4'd4, // external debug according to RISC-V debug spec
182
- XDEBUGVER_NONSTD = 4'd15 // debug not conforming to RISC-V debug spec
183
- } x_debug_ver_e;
184
- //////////////
185
- // WB stage //
186
- //////////////
187
- // Type of instruction present in writeback stage
188
- typedef enum logic[1:0] {
189
- WB_INSTR_LOAD, // Instruction is awaiting load data
190
- WB_INSTR_STORE, // Instruction is awaiting store response
191
- WB_INSTR_OTHER // Instruction doesn't fit into above categories
192
- } wb_instr_type_e;
193
- //////////////
194
- // ID stage //
195
- //////////////
196
- // Operand a selection
197
- typedef enum logic[1:0] {
198
- OP_A_REG_A,
199
- OP_A_FWD,
200
- OP_A_CURRPC,
201
- OP_A_IMM
202
- } op_a_sel_e;
203
- // Immediate a selection
204
- typedef enum logic {
205
- IMM_A_Z,
206
- IMM_A_ZERO
207
- } imm_a_sel_e;
208
- // Operand b selection
209
- typedef enum logic {
210
- OP_B_REG_B,
211
- OP_B_IMM
212
- } op_b_sel_e;
213
- // Immediate b selection
214
- typedef enum logic [2:0] {
215
- IMM_B_I,
216
- IMM_B_S,
217
- IMM_B_B,
218
- IMM_B_U,
219
- IMM_B_J,
220
- IMM_B_INCR_PC,
221
- IMM_B_INCR_ADDR
222
- } imm_b_sel_e;
223
- // Regfile write data selection
224
- typedef enum {
225
- RF_WD_EX,
226
- RF_WD_CSR,
227
- RF_WD_COPROC // Only used when XInterface = 1
228
- } rf_wd_sel_e;
229
- //////////////
230
- // IF stage //
231
- //////////////
232
- // PC mux selection
233
- typedef enum logic [2:0] {
234
- PC_BOOT,
235
- PC_JUMP,
236
- PC_EXC,
237
- PC_ERET,
238
- PC_DRET,
239
- PC_BP
240
- } pc_sel_e;
241
- // Exception PC mux selection
242
- typedef enum logic [1:0] {
243
- EXC_PC_EXC,
244
- EXC_PC_IRQ,
245
- EXC_PC_DBD,
246
- EXC_PC_DBG_EXC // Exception while in debug mode
247
- } exc_pc_sel_e;
248
- // Interrupt requests
249
- typedef struct packed {
250
- logic irq_software;
251
- logic irq_timer;
252
- logic irq_external;
253
- logic [15:0] irq_fast; // 16 fast interrupts
254
- } irqs_t;
255
- // Exception cause
256
- typedef enum logic [6:0] {
257
- EXC_CAUSE_IRQ_SOFTWARE_M = {1'b1, 6'd03},
258
- EXC_CAUSE_IRQ_TIMER_M = {1'b1, 6'd07},
259
- EXC_CAUSE_IRQ_EXTERNAL_M = {1'b1, 6'd11},
260
- // EXC_CAUSE_IRQ_FAST_0 = {1'b1, 6'd16},
261
- // EXC_CAUSE_IRQ_FAST_15 = {1'b1, 6'd31},
262
- EXC_CAUSE_IRQ_NM = {1'b1, 6'd32},
263
- EXC_CAUSE_INSN_ADDR_MISA = {1'b0, 6'd00},
264
- EXC_CAUSE_INSTR_ACCESS_FAULT = {1'b0, 6'd01},
265
- EXC_CAUSE_ILLEGAL_INSN = {1'b0, 6'd02},
266
- EXC_CAUSE_BREAKPOINT = {1'b0, 6'd03},
267
- EXC_CAUSE_LOAD_ACCESS_FAULT = {1'b0, 6'd05},
268
- EXC_CAUSE_STORE_ACCESS_FAULT = {1'b0, 6'd07},
269
- EXC_CAUSE_ECALL_UMODE = {1'b0, 6'd08},
270
- EXC_CAUSE_ECALL_MMODE = {1'b0, 6'd11}
271
- } exc_cause_e;
272
- // Debug cause
273
- typedef enum logic [2:0] {
274
- DBG_CAUSE_NONE = 3'h0,
275
- DBG_CAUSE_EBREAK = 3'h1,
276
- DBG_CAUSE_TRIGGER = 3'h2,
277
- DBG_CAUSE_HALTREQ = 3'h3,
278
- DBG_CAUSE_STEP = 3'h4
279
- } dbg_cause_e;
280
- // PMP constants
281
- parameter int unsigned PMP_MAX_REGIONS = 16;
282
- parameter int unsigned PMP_CFG_W = 8;
283
- // PMP acces type
284
- parameter int unsigned PMP_I = 0;
285
- parameter int unsigned PMP_I2 = 1;
286
- parameter int unsigned PMP_D = 2;
287
- typedef enum logic [1:0] {
288
- PMP_ACC_EXEC = 2'b00,
289
- PMP_ACC_WRITE = 2'b01,
290
- PMP_ACC_READ = 2'b10
291
- } pmp_req_e;
292
- // PMP cfg structures
293
- typedef enum logic [1:0] {
294
- PMP_MODE_OFF = 2'b00,
295
- PMP_MODE_TOR = 2'b01,
296
- PMP_MODE_NA4 = 2'b10,
297
- PMP_MODE_NAPOT = 2'b11
298
- } pmp_cfg_mode_e;
299
- typedef struct packed {
300
- logic lock;
301
- pmp_cfg_mode_e mode;
302
- logic exec;
303
- logic write;
304
- logic read;
305
- } pmp_cfg_t;
306
- // Machine Security Configuration (ePMP)
307
- typedef struct packed {
308
- logic rlb; // Rule Locking Bypass
309
- logic mmwp; // Machine Mode Whitelist Policy
310
- logic mml; // Machine Mode Lockdown
311
- } pmp_mseccfg_t;
312
- // CSRs
313
- typedef enum logic[11:0] {
314
- // Machine information
315
- CSR_MVENDORID = 12'hF11,
316
- CSR_MARCHID = 12'hF12,
317
- CSR_MIMPID = 12'hF13,
318
- CSR_MHARTID = 12'hF14,
319
- CSR_MCONFIGPTR = 12'hF15,
320
- // Machine trap setup
321
- CSR_MSTATUS = 12'h300,
322
- CSR_MISA = 12'h301,
323
- CSR_MIE = 12'h304,
324
- CSR_MTVEC = 12'h305,
325
- CSR_MCOUNTEREN= 12'h306,
326
- CSR_MSTATUSH = 12'h310,
327
- CSR_MENVCFG = 12'h30A,
328
- CSR_MENVCFGH = 12'h31A,
329
- // Machine trap handling
330
- CSR_MSCRATCH = 12'h340,
331
- CSR_MEPC = 12'h341,
332
- CSR_MCAUSE = 12'h342,
333
- CSR_MTVAL = 12'h343,
334
- CSR_MIP = 12'h344,
335
- // Physical memory protection
336
- CSR_PMPCFG0 = 12'h3A0,
337
- CSR_PMPCFG1 = 12'h3A1,
338
- CSR_PMPCFG2 = 12'h3A2,
339
- CSR_PMPCFG3 = 12'h3A3,
340
- CSR_PMPADDR0 = 12'h3B0,
341
- CSR_PMPADDR1 = 12'h3B1,
342
- CSR_PMPADDR2 = 12'h3B2,
343
- CSR_PMPADDR3 = 12'h3B3,
344
- CSR_PMPADDR4 = 12'h3B4,
345
- CSR_PMPADDR5 = 12'h3B5,
346
- CSR_PMPADDR6 = 12'h3B6,
347
- CSR_PMPADDR7 = 12'h3B7,
348
- CSR_PMPADDR8 = 12'h3B8,
349
- CSR_PMPADDR9 = 12'h3B9,
350
- CSR_PMPADDR10 = 12'h3BA,
351
- CSR_PMPADDR11 = 12'h3BB,
352
- CSR_PMPADDR12 = 12'h3BC,
353
- CSR_PMPADDR13 = 12'h3BD,
354
- CSR_PMPADDR14 = 12'h3BE,
355
- CSR_PMPADDR15 = 12'h3BF,
356
- // ePMP control
357
- CSR_MSECCFG = 12'h747,
358
- CSR_MSECCFGH = 12'h757,
359
- // Debug trigger
360
- CSR_TSELECT = 12'h7A0,
361
- CSR_TDATA1 = 12'h7A1,
362
- CSR_TDATA2 = 12'h7A2,
363
- CSR_TDATA3 = 12'h7A3,
364
- CSR_MCONTEXT = 12'h7A8,
365
- CSR_SCONTEXT = 12'h7AA,
366
- // Debug/trace
367
- CSR_DCSR = 12'h7b0,
368
- CSR_DPC = 12'h7b1,
369
- // Debug
370
- CSR_DSCRATCH0 = 12'h7b2, // optional
371
- CSR_DSCRATCH1 = 12'h7b3, // optional
372
- // Machine Counter/Timers
373
- CSR_MCOUNTINHIBIT = 12'h320,
374
- CSR_MHPMEVENT3 = 12'h323,
375
- CSR_MHPMEVENT4 = 12'h324,
376
- CSR_MHPMEVENT5 = 12'h325,
377
- CSR_MHPMEVENT6 = 12'h326,
378
- CSR_MHPMEVENT7 = 12'h327,
379
- CSR_MHPMEVENT8 = 12'h328,
380
- CSR_MHPMEVENT9 = 12'h329,
381
- CSR_MHPMEVENT10 = 12'h32A,
382
- CSR_MHPMEVENT11 = 12'h32B,
383
- CSR_MHPMEVENT12 = 12'h32C,
384
- CSR_MHPMEVENT13 = 12'h32D,
385
- CSR_MHPMEVENT14 = 12'h32E,
386
- CSR_MHPMEVENT15 = 12'h32F,
387
- CSR_MHPMEVENT16 = 12'h330,
388
- CSR_MHPMEVENT17 = 12'h331,
389
- CSR_MHPMEVENT18 = 12'h332,
390
- CSR_MHPMEVENT19 = 12'h333,
391
- CSR_MHPMEVENT20 = 12'h334,
392
- CSR_MHPMEVENT21 = 12'h335,
393
- CSR_MHPMEVENT22 = 12'h336,
394
- CSR_MHPMEVENT23 = 12'h337,
395
- CSR_MHPMEVENT24 = 12'h338,
396
- CSR_MHPMEVENT25 = 12'h339,
397
- CSR_MHPMEVENT26 = 12'h33A,
398
- CSR_MHPMEVENT27 = 12'h33B,
399
- CSR_MHPMEVENT28 = 12'h33C,
400
- CSR_MHPMEVENT29 = 12'h33D,
401
- CSR_MHPMEVENT30 = 12'h33E,
402
- CSR_MHPMEVENT31 = 12'h33F,
403
- CSR_MCYCLE = 12'hB00,
404
- CSR_MINSTRET = 12'hB02,
405
- CSR_MHPMCOUNTER3 = 12'hB03,
406
- CSR_MHPMCOUNTER4 = 12'hB04,
407
- CSR_MHPMCOUNTER5 = 12'hB05,
408
- CSR_MHPMCOUNTER6 = 12'hB06,
409
- CSR_MHPMCOUNTER7 = 12'hB07,
410
- CSR_MHPMCOUNTER8 = 12'hB08,
411
- CSR_MHPMCOUNTER9 = 12'hB09,
412
- CSR_MHPMCOUNTER10 = 12'hB0A,
413
- CSR_MHPMCOUNTER11 = 12'hB0B,
414
- CSR_MHPMCOUNTER12 = 12'hB0C,
415
- CSR_MHPMCOUNTER13 = 12'hB0D,
416
- CSR_MHPMCOUNTER14 = 12'hB0E,
417
- CSR_MHPMCOUNTER15 = 12'hB0F,
418
- CSR_MHPMCOUNTER16 = 12'hB10,
419
- CSR_MHPMCOUNTER17 = 12'hB11,
420
- CSR_MHPMCOUNTER18 = 12'hB12,
421
- CSR_MHPMCOUNTER19 = 12'hB13,
422
- CSR_MHPMCOUNTER20 = 12'hB14,
423
- CSR_MHPMCOUNTER21 = 12'hB15,
424
- CSR_MHPMCOUNTER22 = 12'hB16,
425
- CSR_MHPMCOUNTER23 = 12'hB17,
426
- CSR_MHPMCOUNTER24 = 12'hB18,
427
- CSR_MHPMCOUNTER25 = 12'hB19,
428
- CSR_MHPMCOUNTER26 = 12'hB1A,
429
- CSR_MHPMCOUNTER27 = 12'hB1B,
430
- CSR_MHPMCOUNTER28 = 12'hB1C,
431
- CSR_MHPMCOUNTER29 = 12'hB1D,
432
- CSR_MHPMCOUNTER30 = 12'hB1E,
433
- CSR_MHPMCOUNTER31 = 12'hB1F,
434
- CSR_MCYCLEH = 12'hB80,
435
- CSR_MINSTRETH = 12'hB82,
436
- CSR_MHPMCOUNTER3H = 12'hB83,
437
- CSR_MHPMCOUNTER4H = 12'hB84,
438
- CSR_MHPMCOUNTER5H = 12'hB85,
439
- CSR_MHPMCOUNTER6H = 12'hB86,
440
- CSR_MHPMCOUNTER7H = 12'hB87,
441
- CSR_MHPMCOUNTER8H = 12'hB88,
442
- CSR_MHPMCOUNTER9H = 12'hB89,
443
- CSR_MHPMCOUNTER10H = 12'hB8A,
444
- CSR_MHPMCOUNTER11H = 12'hB8B,
445
- CSR_MHPMCOUNTER12H = 12'hB8C,
446
- CSR_MHPMCOUNTER13H = 12'hB8D,
447
- CSR_MHPMCOUNTER14H = 12'hB8E,
448
- CSR_MHPMCOUNTER15H = 12'hB8F,
449
- CSR_MHPMCOUNTER16H = 12'hB90,
450
- CSR_MHPMCOUNTER17H = 12'hB91,
451
- CSR_MHPMCOUNTER18H = 12'hB92,
452
- CSR_MHPMCOUNTER19H = 12'hB93,
453
- CSR_MHPMCOUNTER20H = 12'hB94,
454
- CSR_MHPMCOUNTER21H = 12'hB95,
455
- CSR_MHPMCOUNTER22H = 12'hB96,
456
- CSR_MHPMCOUNTER23H = 12'hB97,
457
- CSR_MHPMCOUNTER24H = 12'hB98,
458
- CSR_MHPMCOUNTER25H = 12'hB99,
459
- CSR_MHPMCOUNTER26H = 12'hB9A,
460
- CSR_MHPMCOUNTER27H = 12'hB9B,
461
- CSR_MHPMCOUNTER28H = 12'hB9C,
462
- CSR_MHPMCOUNTER29H = 12'hB9D,
463
- CSR_MHPMCOUNTER30H = 12'hB9E,
464
- CSR_MHPMCOUNTER31H = 12'hB9F,
465
- CSR_CPUCTRL = 12'h7C0,
466
- CSR_SECURESEED = 12'h7C1
467
- } csr_num_e;
468
- // CSR pmp-related offsets
469
- parameter logic [11:0] CSR_OFF_PMP_CFG = 12'h3A0; // pmp_cfg @ 12'h3a0 - 12'h3a3
470
- parameter logic [11:0] CSR_OFF_PMP_ADDR = 12'h3B0; // pmp_addr @ 12'h3b0 - 12'h3bf
471
- // CSR status bits
472
- parameter int unsigned CSR_MSTATUS_MIE_BIT = 3;
473
- parameter int unsigned CSR_MSTATUS_MPIE_BIT = 7;
474
- parameter int unsigned CSR_MSTATUS_MPP_BIT_LOW = 11;
475
- parameter int unsigned CSR_MSTATUS_MPP_BIT_HIGH = 12;
476
- parameter int unsigned CSR_MSTATUS_MPRV_BIT = 17;
477
- parameter int unsigned CSR_MSTATUS_TW_BIT = 21;
478
- // CSR machine ISA
479
- parameter logic [1:0] CSR_MISA_MXL = 2'd1; // M-XLEN: XLEN in M-Mode for RV32
480
- // CSR interrupt pending/enable bits
481
- parameter int unsigned CSR_MSIX_BIT = 3;
482
- parameter int unsigned CSR_MTIX_BIT = 7;
483
- parameter int unsigned CSR_MEIX_BIT = 11;
484
- parameter int unsigned CSR_MFIX_BIT_LOW = 16;
485
- parameter int unsigned CSR_MFIX_BIT_HIGH = 31;
486
- // CSR Machine Security Configuration bits
487
- parameter int unsigned CSR_MSECCFG_MML_BIT = 0;
488
- parameter int unsigned CSR_MSECCFG_MMWP_BIT = 1;
489
- parameter int unsigned CSR_MSECCFG_RLB_BIT = 2;
490
- // Machine Vendor ID - OpenHW JEDEC ID is '2 decimal (bank 13)'
491
- parameter MVENDORID_OFFSET = 7'h2; // Final byte without parity bit
492
- parameter MVENDORID_BANK = 25'hC; // Number of continuation codes
493
- // Machine Architecture ID (https://github.com/riscv/riscv-isa-manual/blob/master/marchid.md)
494
- parameter MARCHID = 32'd35;
495
- localparam logic [31:0] CSR_MVENDORID_VALUE = {MVENDORID_BANK, MVENDORID_OFFSET};
496
- localparam logic [31:0] CSR_MARCHID_VALUE = MARCHID;
497
- // Implementation ID
498
- // 0 indicates this field is not implemeted. cve2 implementors may wish to indicate an RTL/netlist
499
- // version here using their own unique encoding (e.g. 32 bits of the git hash of the implemented
500
- // commit).
501
- localparam logic [31:0] CSR_MIMPID_VALUE = 32'b0;
502
- // Machine Configuration Pointer
503
- // 0 indicates the configuration data structure does not eixst. cve2 implementors may wish to
504
- // alter this to point to their system specific configuration data structure.
505
- localparam logic [31:0] CSR_MCONFIGPTR_VALUE = 32'b0;
506
- // RVFI CSR element
507
- typedef struct packed {
508
- bit [63:0] rdata;
509
- bit [63:0] rmask;
510
- bit [63:0] wdata;
511
- bit [63:0] wmask;
512
- } rvfi_csr_elmt_t;
513
- // RVFI CSR structure
514
- typedef struct packed {
515
- rvfi_csr_elmt_t fflags;
516
- rvfi_csr_elmt_t frm;
517
- rvfi_csr_elmt_t fcsr;
518
- rvfi_csr_elmt_t ftran;
519
- rvfi_csr_elmt_t dcsr;
520
- rvfi_csr_elmt_t dpc;
521
- rvfi_csr_elmt_t dscratch0;
522
- rvfi_csr_elmt_t dscratch1;
523
- rvfi_csr_elmt_t sstatus;
524
- rvfi_csr_elmt_t sie;
525
- rvfi_csr_elmt_t sip;
526
- rvfi_csr_elmt_t stvec;
527
- rvfi_csr_elmt_t scounteren;
528
- rvfi_csr_elmt_t sscratch;
529
- rvfi_csr_elmt_t sepc;
530
- rvfi_csr_elmt_t scause;
531
- rvfi_csr_elmt_t stval;
532
- rvfi_csr_elmt_t satp;
533
- rvfi_csr_elmt_t mstatus;
534
- rvfi_csr_elmt_t mstatush;
535
- rvfi_csr_elmt_t misa;
536
- rvfi_csr_elmt_t medeleg;
537
- rvfi_csr_elmt_t mideleg;
538
- rvfi_csr_elmt_t mie;
539
- rvfi_csr_elmt_t mtvec;
540
- rvfi_csr_elmt_t mcounteren;
541
- rvfi_csr_elmt_t mscratch;
542
- rvfi_csr_elmt_t mepc;
543
- rvfi_csr_elmt_t mcause;
544
- rvfi_csr_elmt_t mtval;
545
- rvfi_csr_elmt_t mip;
546
- rvfi_csr_elmt_t menvcfg;
547
- rvfi_csr_elmt_t menvcfgh;
548
- rvfi_csr_elmt_t mvendorid;
549
- rvfi_csr_elmt_t marchid;
550
- rvfi_csr_elmt_t mhartid;
551
- rvfi_csr_elmt_t mcountinhibit;
552
- rvfi_csr_elmt_t mcycle;
553
- rvfi_csr_elmt_t mcycleh;
554
- rvfi_csr_elmt_t minstret;
555
- rvfi_csr_elmt_t minstreth;
556
- rvfi_csr_elmt_t cycle;
557
- rvfi_csr_elmt_t cycleh;
558
- rvfi_csr_elmt_t instret;
559
- rvfi_csr_elmt_t instreth;
560
- rvfi_csr_elmt_t dcache;
561
- rvfi_csr_elmt_t icache;
562
- rvfi_csr_elmt_t acc_cons;
563
- rvfi_csr_elmt_t pmpcfg0;
564
- rvfi_csr_elmt_t pmpcfg1;
565
- rvfi_csr_elmt_t pmpcfg2;
566
- rvfi_csr_elmt_t pmpcfg3;
567
- rvfi_csr_elmt_t pmpaddr0;
568
- rvfi_csr_elmt_t pmpaddr1;
569
- rvfi_csr_elmt_t pmpaddr2;
570
- rvfi_csr_elmt_t pmpaddr3;
571
- rvfi_csr_elmt_t pmpaddr4;
572
- rvfi_csr_elmt_t pmpaddr5;
573
- rvfi_csr_elmt_t pmpaddr6;
574
- rvfi_csr_elmt_t pmpaddr7;
575
- rvfi_csr_elmt_t pmpaddr8;
576
- rvfi_csr_elmt_t pmpaddr9;
577
- rvfi_csr_elmt_t pmpaddr10;
578
- rvfi_csr_elmt_t pmpaddr11;
579
- rvfi_csr_elmt_t pmpaddr12;
580
- rvfi_csr_elmt_t pmpaddr13;
581
- rvfi_csr_elmt_t pmpaddr14;
582
- rvfi_csr_elmt_t pmpaddr15;
583
- } rvfi_csr_t;
584
- // CV-X-IF
585
- parameter int unsigned X_NUM_RS = 3;
586
- parameter int unsigned X_ID_WIDTH = 4;
587
- parameter int unsigned X_RFR_WIDTH = 32;
588
- parameter int unsigned X_RFW_WIDTH = 32;
589
- parameter int unsigned X_HARTID_WIDTH = 32;
590
- parameter int unsigned X_DUAL_READ = 0;
591
- parameter int unsigned X_DUAL_WRITE = 0;
592
- parameter int unsigned X_INSTR_INFLIGHT = 2**X_ID_WIDTH;
593
- typedef logic [X_NUM_RS+X_DUAL_READ-1:0] readregflags_t;
594
- typedef logic [X_DUAL_WRITE:0] writeregflags_t;
595
- typedef logic [X_ID_WIDTH-1:0] id_t;
596
- typedef logic [X_HARTID_WIDTH-1:0] hartid_t;
597
- // Issue Interface
598
- typedef struct packed {
599
- logic [31:0] instr;
600
- hartid_t hartid;
601
- id_t id;
602
- } x_issue_req_t;
603
- typedef struct packed {
604
- logic accept;
605
- writeregflags_t writeback;
606
- readregflags_t register_read;
607
- } x_issue_resp_t;
608
- // Register Interface
609
- typedef struct packed {
610
- hartid_t hartid;
611
- id_t id;
612
- logic [X_NUM_RS-1:0][X_RFR_WIDTH-1:0] rs;
613
- readregflags_t rs_valid;
614
- } x_register_t;
615
- // Commit Interface
616
- typedef struct packed {
617
- hartid_t hartid;
618
- id_t id;
619
- logic commit_kill;
620
- } x_commit_t;
621
- // Result Interface
622
- typedef struct packed {
623
- hartid_t hartid;
624
- id_t id;
625
- logic [X_RFW_WIDTH-1:0] data;
626
- logic [4:0] rd;
627
- writeregflags_t we;
628
- } x_result_t;
629
- endpackage
630
- // Copyright (c) 2025 Eclipse Foundation
631
- // Copyright lowRISC contributors.
632
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
633
- // SPDX-License-Identifier: Apache-2.0
634
- // The CVE2 does not officially support Physical Memory Protection (PMP), as
635
- // defined by rule PVL-40 of the CV32E20 core functional requirements.
636
- module cve2_pmp #(
637
- // Granularity of NAPOT access,
638
- // 0 = No restriction, 1 = 8 byte, 2 = 16 byte, 3 = 32 byte, etc.
639
- parameter int unsigned PMPGranularity = 0,
640
- // Number of access channels (e.g. i-side + d-side)
641
- parameter int unsigned PMPNumChan = 2,
642
- // Number of implemented regions
643
- parameter int unsigned PMPNumRegions = 4
644
- ) (
645
- // Clock and Reset
646
- input logic clk_i,
647
- input logic rst_ni,
648
- // Interface to CSRs
649
- input cve2_pkg::pmp_cfg_t csr_pmp_cfg_i [PMPNumRegions],
650
- input logic [33:0] csr_pmp_addr_i [PMPNumRegions],
651
- input cve2_pkg::pmp_mseccfg_t csr_pmp_mseccfg_i,
652
- input cve2_pkg::priv_lvl_e priv_mode_i [PMPNumChan],
653
- // Access checking channels
654
- input logic [33:0] pmp_req_addr_i [PMPNumChan],
655
- input cve2_pkg::pmp_req_e pmp_req_type_i [PMPNumChan],
656
- output logic pmp_req_err_o [PMPNumChan]
657
- );
658
- import cve2_pkg::*;
659
- // Access Checking Signals
660
- logic [33:0] region_start_addr [PMPNumRegions];
661
- logic [33:PMPGranularity+2] region_addr_mask [PMPNumRegions];
662
- logic [PMPNumChan-1:0][PMPNumRegions-1:0] region_match_gt;
663
- logic [PMPNumChan-1:0][PMPNumRegions-1:0] region_match_lt;
664
- logic [PMPNumChan-1:0][PMPNumRegions-1:0] region_match_eq;
665
- logic [PMPNumChan-1:0][PMPNumRegions-1:0] region_match_all;
666
- logic [PMPNumChan-1:0][PMPNumRegions-1:0] region_basic_perm_check;
667
- logic [PMPNumChan-1:0][PMPNumRegions-1:0] region_mml_perm_check;
668
- logic [PMPNumChan-1:0] access_fault;
669
- $warning("CVE2 does not officially support PMP, see rule PVL-40.");
670
- // ---------------
671
- // Access checking
672
- // ---------------
673
- for (genvar r = 0; r < PMPNumRegions; r++) begin : g_addr_exp
674
- // Start address for TOR matching
675
- if (r == 0) begin : g_entry0
676
- assign region_start_addr[r] = (csr_pmp_cfg_i[r].mode == PMP_MODE_TOR) ? 34'h000000000 :
677
- csr_pmp_addr_i[r];
678
- end else begin : g_oth
679
- assign region_start_addr[r] = (csr_pmp_cfg_i[r].mode == PMP_MODE_TOR) ? csr_pmp_addr_i[r-1] :
680
- csr_pmp_addr_i[r];
681
- end
682
- // Address mask for NA matching
683
- for (genvar b = PMPGranularity + 2; b < 34; b++) begin : g_bitmask
684
- if (b == 2) begin : g_bit0
685
- // Always mask bit 2 for NAPOT
686
- assign region_addr_mask[r][b] = (csr_pmp_cfg_i[r].mode != PMP_MODE_NAPOT);
687
- end else begin : g_others
688
- // We will mask this bit if it is within the programmed granule
689
- // i.e. addr = yyyy 0111
690
- // ^
691
- // | This bit pos is the top of the mask, all lower bits set
692
- // thus mask = 1111 0000
693
- if (PMPGranularity == 0) begin : g_region_addr_mask_zero_granularity
694
- assign region_addr_mask[r][b] = (csr_pmp_cfg_i[r].mode != PMP_MODE_NAPOT) |
695
- ~&csr_pmp_addr_i[r][b-1:2];
696
- end else begin : g_region_addr_mask_other_granularity
697
- assign region_addr_mask[r][b] = (csr_pmp_cfg_i[r].mode != PMP_MODE_NAPOT) |
698
- ~&csr_pmp_addr_i[r][b-1:PMPGranularity+1];
699
- end
700
- end
701
- end
702
- end
703
- for (genvar c = 0; c < PMPNumChan; c++) begin : g_access_check
704
- for (genvar r = 0; r < PMPNumRegions; r++) begin : g_regions
705
- // Comparators are sized according to granularity
706
- assign region_match_eq[c][r] = (pmp_req_addr_i[c][33:PMPGranularity+2] &
707
- region_addr_mask[r]) ==
708
- (region_start_addr[r][33:PMPGranularity+2] &
709
- region_addr_mask[r]);
710
- assign region_match_gt[c][r] = pmp_req_addr_i[c][33:PMPGranularity+2] >
711
- region_start_addr[r][33:PMPGranularity+2];
712
- assign region_match_lt[c][r] = pmp_req_addr_i[c][33:PMPGranularity+2] <
713
- csr_pmp_addr_i[r][33:PMPGranularity+2];
714
- always_comb begin
715
- region_match_all[c][r] = 1'b0;
716
- unique case (csr_pmp_cfg_i[r].mode)
717
- PMP_MODE_OFF: region_match_all[c][r] = 1'b0;
718
- PMP_MODE_NA4: region_match_all[c][r] = region_match_eq[c][r];
719
- PMP_MODE_NAPOT: region_match_all[c][r] = region_match_eq[c][r];
720
- PMP_MODE_TOR: begin
721
- region_match_all[c][r] = (region_match_eq[c][r] | region_match_gt[c][r]) &
722
- region_match_lt[c][r];
723
- end
724
- default: region_match_all[c][r] = 1'b0;
725
- endcase
726
- end
727
- // Check specific required permissions
728
- assign region_basic_perm_check[c][r] =
729
- ((pmp_req_type_i[c] == PMP_ACC_EXEC) & csr_pmp_cfg_i[r].exec) |
730
- ((pmp_req_type_i[c] == PMP_ACC_WRITE) & csr_pmp_cfg_i[r].write) |
731
- ((pmp_req_type_i[c] == PMP_ACC_READ) & csr_pmp_cfg_i[r].read);
732
- // Compute permission checks that apply when MSECCFG.MML is set.
733
- always_comb begin
734
- region_mml_perm_check[c][r] = 1'b0;
735
- if (!csr_pmp_cfg_i[r].read && csr_pmp_cfg_i[r].write) begin
736
- // Special-case shared regions where R = 0, W = 1
737
- unique case ({csr_pmp_cfg_i[r].lock, csr_pmp_cfg_i[r].exec})
738
- // Read/write in M, read only in S/U
739
- 2'b00: region_mml_perm_check[c][r] =
740
- (pmp_req_type_i[c] == PMP_ACC_READ) |
741
- ((pmp_req_type_i[c] == PMP_ACC_WRITE) & (priv_mode_i[c] == PRIV_LVL_M));
742
- // Read/write in M/S/U
743
- 2'b01: region_mml_perm_check[c][r] =
744
- (pmp_req_type_i[c] == PMP_ACC_READ) | (pmp_req_type_i[c] == PMP_ACC_WRITE);
745
- // Execute only on M/S/U
746
- 2'b10: region_mml_perm_check[c][r] = (pmp_req_type_i[c] == PMP_ACC_EXEC);
747
- // Read/execute in M, execute only on S/U
748
- 2'b11: region_mml_perm_check[c][r] =
749
- (pmp_req_type_i[c] == PMP_ACC_EXEC) |
750
- ((pmp_req_type_i[c] == PMP_ACC_READ) & (priv_mode_i[c] == PRIV_LVL_M));
751
- default: ;
752
- endcase
753
- end else begin
754
- if (csr_pmp_cfg_i[r].read & csr_pmp_cfg_i[r].write & csr_pmp_cfg_i[r].exec
755
- & csr_pmp_cfg_i[r].lock) begin
756
- // Special-case shared read only region when R = 1, W = 1, X = 1, L = 1
757
- region_mml_perm_check[c][r] = pmp_req_type_i[c] == PMP_ACC_READ;
758
- end else begin
759
- // Otherwise use basic permission check. Permission is always denied if in S/U mode and
760
- // L is set or if in M mode and L is unset.
761
- region_mml_perm_check[c][r] =
762
- priv_mode_i[c] == PRIV_LVL_M ? csr_pmp_cfg_i[r].lock & region_basic_perm_check[c][r] :
763
- ~csr_pmp_cfg_i[r].lock & region_basic_perm_check[c][r];
764
- end
765
- end
766
- end
767
- end
768
- // Access fault determination / prioritization
769
- always_comb begin
770
- // When MSECCFG.MMWP is set default deny always, otherwise allow for M-mode, deny for other
771
- // modes
772
- access_fault[c] = csr_pmp_mseccfg_i.mmwp | (priv_mode_i[c] != PRIV_LVL_M);
773
- // PMP entries are statically prioritized, from 0 to N-1
774
- // The lowest-numbered PMP entry which matches an address determines accessability
775
- for (int r = PMPNumRegions - 1; r >= 0; r--) begin
776
- if (region_match_all[c][r]) begin
777
- if (csr_pmp_mseccfg_i.mml) begin
778
- // When MSECCFG.MML is set use MML specific permission check
779
- access_fault[c] = ~region_mml_perm_check[c][r];
780
- end else begin
781
- // Otherwise use original PMP behaviour
782
- access_fault[c] = (priv_mode_i[c] == PRIV_LVL_M) ?
783
- // For M-mode, any region which matches with the L-bit clear, or with sufficient
784
- // access permissions will be allowed
785
- (csr_pmp_cfg_i[r].lock & ~region_basic_perm_check[c][r]) :
786
- // For other modes, the lock bit doesn't matter
787
- ~region_basic_perm_check[c][r];
788
- end
789
- end
790
- end
791
- end
792
- assign pmp_req_err_o[c] = access_fault[c];
793
- end
794
- // RLB, rule locking bypass, is only relevant to cve2_cs_registers which controls writes to the
795
- // PMP CSRs. Tie to unused signal here to prevent lint warnings.
796
- logic unused_csr_pmp_mseccfg_rlb;
797
- assign unused_csr_pmp_mseccfg_rlb = csr_pmp_mseccfg_i.rlb;
798
- endmodule
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p11/mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"conditional_statement": [[26079, 26736], [23752, 25532], [24802, 25520], [26035, 26748]], "blocking_assignment": [[25018, 25082], [24556, 24727], [22968, 23015], [24011, 24183], [22736, 22766], [22894, 22941], [23708, 23743], [25743, 25817]], "always_construct": [[25606, 26766], [23682, 25542], [22710, 23289]], "case_statement": [[23882, 24768], [22775, 23279]], "ansi_port_declaration": [[18977, 19016], [19326, 19386], [19180, 19230], [19452, 19511], [18936, 18974], [19389, 19449], [19111, 19177]], "continuous_assign": [[22114, 22390], [22397, 22548], [23341, 23604], [26771, 26813], [21059, 21133], [27023, 27081], [20455, 20639], [20673, 20863]], "parameter_declaration": [[13332, 13380], [6668, 6702], [12464, 12546], [12680, 12733], [12736, 12789], [13092, 13137], [6471, 6520], [13622, 13688], [12379, 12461], [6631, 6665]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p12/all_mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"module_program_interface_instantiation": [[16491, 17279]], "continuous_assign": [[6448, 6500], [6503, 6553], [6556, 6595], [7167, 7313], [7704, 7958], [8124, 8263], [8351, 8462], [8509, 8573], [8576, 8640], [9436, 9497], [9580, 9712], [9715, 9887], [9890, 9990], [10221, 10267], [10350, 10387], [10667, 10715], [10889, 10976], [11128, 11170], [11211, 11268], [11364, 11467], [11520, 11592], [11641, 11688], [11765, 11980], [12033, 12095], [12100, 12160], [12223, 12296], [12299, 12396], [12399, 12475], [12478, 12547], [12550, 12626], [12629, 12676], [12679, 12724], [15528, 15581], [15952, 15981], [16133, 16201], [16430, 16488], [17425, 17540], [17543, 17590], [17659, 17705], [17780, 17844], [18660, 18728], [18781, 18815], [19158, 19223], [19226, 19479], [19689, 19857], [19860, 19916], [20345, 20466], [20623, 20833], [21005, 21192], [21199, 21475], [21543, 21700], [21703, 21854], [21937, 21995], [21998, 22024], [22567, 22599], [22602, 22645], [22648, 22675]], "blocking_assignment": [[8849, 8883], [8890, 8922], [8929, 8957], [9007, 9027], [9057, 9087], [9145, 9169], [9176, 9198], [9205, 9228], [9235, 9259]], "nonblocking_assignment": [[10073, 10092], [10137, 10166], [12876, 12890], [12916, 12935], [13101, 13118], [13129, 13146], [13197, 13222], [13233, 13256], [18965, 18985], [19031, 19062], [19562, 19581], [19626, 19655], [22161, 22190], [22197, 22226], [22233, 22261], [22268, 22296], [22322, 22358], [22365, 22403], [22410, 22454], [22461, 22502]], "case_statement": [], "conditional_statement": [[8794, 9267], [8964, 9097], [10048, 10174], [10106, 10174], [12851, 12943], [13072, 13268], [13164, 13268], [18940, 19070], [18999, 19070], [19537, 19663], [19595, 19663], [22136, 22510]], "always_construct": [[8772, 9273], [9993, 10180], [12796, 12949], [13013, 13278], [18885, 19076], [19482, 19669], [22081, 22516]], "parameter_declaration": [[4806, 4841]], "ansi_port_declaration": [[4848, 4882], [4885, 4920], [4944, 5017], [5020, 5055], [5074, 5113], [5116, 5154], [5157, 5196], [5199, 5236], [5256, 5296], [5299, 5339], [5342, 5381], [5384, 5424], [5427, 5465], [5468, 5511], [13924, 13950], [13953, 13980], [13983, 14009], [14012, 14041], [14044, 14071], [14074, 14102], [14105, 14133], [14136, 14164], [14167, 14194], [14197, 14223], [14226, 14258], [14313, 14345], [14348, 14380], [14383, 14416], [14419, 14453], [14456, 14488], [14491, 14526], [14557, 14583]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p12/cve2_prefetch_buffer.sv DELETED
@@ -1,491 +0,0 @@
1
- // Copyright (c) 2025 Eclipse Foundation
2
- // Copyright lowRISC contributors.
3
- // Copyright 2018 ETH Zurich and University of Bologna, see also CREDITS.md.
4
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
5
- // SPDX-License-Identifier: Apache-2.0
6
- /**
7
- * Fetch Fifo for 32 bit memory interface
8
- *
9
- * input port: send address and data to the FIFO
10
- * clear_i clears the FIFO for the following cycle, including any new request
11
- */
12
- // Copyright lowRISC contributors.
13
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
14
- // SPDX-License-Identifier: Apache-2.0
15
- // Macros and helper code for using assertions.
16
- // - Provides default clk and rst options to simplify code
17
- // - Provides boiler plate template for common assertions
18
- ///////////////////
19
- // Helper macros //
20
- ///////////////////
21
- // Default clk and reset signals used by assertion macros below.
22
- // Converts an arbitrary block of code into a Verilog string
23
- // ASSERT_ERROR logs an error message with either `uvm_error or with $error.
24
- //
25
- // This somewhat duplicates `DV_ERROR macro defined in hw/dv/sv/dv_utils/dv_macros.svh. The reason
26
- // for redefining it here is to avoid creating a dependency.
27
- // This macro is suitable for conditionally triggering lint errors, e.g., if a Sec parameter takes
28
- // on a non-default value. This may be required for pre-silicon/FPGA evaluation but we don't want
29
- // to allow this for tapeout.
30
- // The basic helper macros are actually defined in "implementation headers". The macros should do
31
- // the same thing in each case (except for the dummy flavour), but in a way that the respective
32
- // tools support.
33
- //
34
- // If the tool supports assertions in some form, we also define INC_ASSERT (which can be used to
35
- // hide signal definitions that are only used for assertions).
36
- //
37
- // The list of basic macros supported is:
38
- //
39
- // ASSERT_I: Immediate assertion. Note that immediate assertions are sensitive to simulation
40
- // glitches.
41
- //
42
- // ASSERT_INIT: Assertion in initial block. Can be used for things like parameter checking.
43
- //
44
- // ASSERT_INIT_NET: Assertion in initial block. Can be used for initial value of a net.
45
- //
46
- // ASSERT_FINAL: Assertion in final block. Can be used for things like queues being empty at end of
47
- // sim, all credits returned at end of sim, state machines in idle at end of sim.
48
- //
49
- // ASSERT: Assert a concurrent property directly. It can be called as a module (or
50
- // interface) body item.
51
- //
52
- // Note: We use (__rst !== '0) in the disable iff statements instead of (__rst ==
53
- // '1). This properly disables the assertion in cases when reset is X at the
54
- // beginning of a simulation. For that case, (reset == '1) does not disable the
55
- // assertion.
56
- //
57
- // ASSERT_NEVER: Assert a concurrent property NEVER happens
58
- //
59
- // ASSERT_KNOWN: Assert that signal has a known value (each bit is either '0' or '1') after reset.
60
- // It can be called as a module (or interface) body item.
61
- //
62
- // COVER: Cover a concurrent property
63
- //
64
- // ASSUME: Assume a concurrent property
65
- //
66
- // ASSUME_I: Assume an immediate property
67
- // Copyright lowRISC contributors.
68
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
69
- // SPDX-License-Identifier: Apache-2.0
70
- // Macro bodies included by prim_assert.sv for tools that don't support assertions. See
71
- // prim_assert.sv for documentation for each of the macros.
72
- //////////////////////////////
73
- // Complex assertion macros //
74
- //////////////////////////////
75
- // Assert that signal is an active-high pulse with pulse length of 1 clock cycle
76
- // Assert that a property is true only when an enable signal is set. It can be called as a module
77
- // (or interface) body item.
78
- // Assert that signal has a known value (each bit is either '0' or '1') after reset if enable is
79
- // set. It can be called as a module (or interface) body item.
80
- //////////////////////////////////
81
- // For formal verification only //
82
- //////////////////////////////////
83
- // Note that the existing set of ASSERT macros specified above shall be used for FPV,
84
- // thereby ensuring that the assertions are evaluated during DV simulations as well.
85
- // ASSUME_FPV
86
- // Assume a concurrent property during formal verification only.
87
- // ASSUME_I_FPV
88
- // Assume a concurrent property during formal verification only.
89
- // COVER_FPV
90
- // Cover a concurrent property during formal verification
91
- // Copyright lowRISC contributors.
92
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
93
- // SPDX-License-Identifier: Apache-2.0
94
- // // Macros and helper code for security countermeasures.
95
- // Helper macros
96
- // macros for security countermeasures
97
- // PRIM_ASSERT_SEC_CM_SVH
98
- // PRIM_ASSERT_SV
99
- module cve2_fetch_fifo #(
100
- parameter int unsigned NUM_REQS = 2
101
- ) (
102
- input logic clk_i,
103
- input logic rst_ni,
104
- // control signals
105
- input logic clear_i, // clears the contents of the FIFO
106
- output logic [NUM_REQS-1:0] busy_o,
107
- // input port
108
- input logic in_valid_i,
109
- input logic [31:0] in_addr_i,
110
- input logic [31:0] in_rdata_i,
111
- input logic in_err_i,
112
- // output port
113
- output logic out_valid_o,
114
- input logic out_ready_i,
115
- output logic [31:0] out_addr_o,
116
- output logic [31:0] out_rdata_o,
117
- output logic out_err_o,
118
- output logic out_err_plus2_o
119
- );
120
- localparam int unsigned DEPTH = NUM_REQS+1;
121
- // index 0 is used for output
122
- logic [DEPTH-1:0] [31:0] rdata_d, rdata_q;
123
- logic [DEPTH-1:0] err_d, err_q;
124
- logic [DEPTH-1:0] valid_d, valid_q;
125
- logic [DEPTH-1:0] lowest_free_entry;
126
- logic [DEPTH-1:0] valid_pushed, valid_popped;
127
- logic [DEPTH-1:0] entry_en;
128
- logic pop_fifo;
129
- logic [31:0] rdata, rdata_unaligned;
130
- logic err, err_unaligned, err_plus2;
131
- logic valid, valid_unaligned;
132
- logic aligned_is_compressed, unaligned_is_compressed;
133
- logic addr_incr_two;
134
- logic [31:1] instr_addr_next;
135
- logic [31:1] instr_addr_d, instr_addr_q;
136
- logic instr_addr_en;
137
- logic unused_addr_in;
138
- /////////////////
139
- // Output port //
140
- /////////////////
141
- assign rdata = valid_q[0] ? rdata_q[0] : in_rdata_i;
142
- assign err = valid_q[0] ? err_q[0] : in_err_i;
143
- assign valid = valid_q[0] | in_valid_i;
144
- // The FIFO contains word aligned memory fetches, but the instructions contained in each entry
145
- // might be half-word aligned (due to compressed instructions)
146
- // e.g.
147
- // | 31 16 | 15 0 |
148
- // FIFO entry 0 | Instr 1 [15:0] | Instr 0 [15:0] |
149
- // FIFO entry 1 | Instr 2 [15:0] | Instr 1 [31:16] |
150
- //
151
- // The FIFO also has a direct bypass path, so a complete instruction might be made up of data
152
- // from the FIFO and new incoming data.
153
- //
154
- // Construct the output data for an unaligned instruction
155
- assign rdata_unaligned = valid_q[1] ? {rdata_q[1][15:0], rdata[31:16]} :
156
- {in_rdata_i[15:0], rdata[31:16]};
157
- // If entry[1] is valid, an error can come from entry[0] or entry[1], unless the
158
- // instruction in entry[0] is compressed (entry[1] is a new instruction)
159
- // If entry[1] is not valid, and entry[0] is, an error can come from entry[0] or the incoming
160
- // data, unless the instruction in entry[0] is compressed
161
- // If entry[0] is not valid, the error must come from the incoming data
162
- assign err_unaligned = valid_q[1] ? ((err_q[1] & ~unaligned_is_compressed) | err_q[0]) :
163
- ((valid_q[0] & err_q[0]) |
164
- (in_err_i & (~valid_q[0] | ~unaligned_is_compressed)));
165
- // Record when an error is caused by the second half of an unaligned 32bit instruction.
166
- // Only needs to be correct when unaligned and if err_unaligned is set
167
- assign err_plus2 = valid_q[1] ? (err_q[1] & ~err_q[0]) :
168
- (in_err_i & valid_q[0] & ~err_q[0]);
169
- // An uncompressed unaligned instruction is only valid if both parts are available
170
- assign valid_unaligned = valid_q[1] ? 1'b1 :
171
- (valid_q[0] & in_valid_i);
172
- // If there is an error, rdata is unknown
173
- assign unaligned_is_compressed = (rdata[17:16] != 2'b11) & ~err;
174
- assign aligned_is_compressed = (rdata[ 1: 0] != 2'b11) & ~err;
175
- ////////////////////////////////////////
176
- // Instruction aligner (if unaligned) //
177
- ////////////////////////////////////////
178
- always_comb begin
179
- if (out_addr_o[1]) begin
180
- // unaligned case
181
- out_rdata_o = rdata_unaligned;
182
- out_err_o = err_unaligned;
183
- out_err_plus2_o = err_plus2;
184
- if (unaligned_is_compressed) begin
185
- out_valid_o = valid;
186
- end else begin
187
- out_valid_o = valid_unaligned;
188
- end
189
- end else begin
190
- // aligned case
191
- out_rdata_o = rdata;
192
- out_err_o = err;
193
- out_err_plus2_o = 1'b0;
194
- out_valid_o = valid;
195
- end
196
- end
197
- /////////////////////////
198
- // Instruction address //
199
- /////////////////////////
200
- // Update the address on branches and every time an instruction is driven
201
- assign instr_addr_en = clear_i | (out_ready_i & out_valid_o);
202
- // Increment the address by two every time a compressed instruction is popped
203
- assign addr_incr_two = instr_addr_q[1] ? unaligned_is_compressed :
204
- aligned_is_compressed;
205
- assign instr_addr_next = (instr_addr_q[31:1] +
206
- // Increment address by 4 or 2
207
- {29'd0,~addr_incr_two,addr_incr_two});
208
- assign instr_addr_d = clear_i ? in_addr_i[31:1] :
209
- instr_addr_next;
210
- always_ff @(posedge clk_i or negedge rst_ni) begin
211
- if (!rst_ni) begin
212
- instr_addr_q <= '0;
213
- end else if (instr_addr_en) begin
214
- instr_addr_q <= instr_addr_d;
215
- end
216
- end
217
- // Output PC of current instruction
218
- assign out_addr_o = {instr_addr_q, 1'b0};
219
- // The LSB of the address is unused, since all addresses are halfword aligned
220
- assign unused_addr_in = in_addr_i[0];
221
- /////////////////
222
- // FIFO status //
223
- /////////////////
224
- // Indicate the fill level of fifo-entries. This is used to determine when a new request can be
225
- // made on the bus. The prefetch buffer only needs to know about the upper entries which overlap
226
- // with NUM_REQS.
227
- assign busy_o = valid_q[DEPTH-1:DEPTH-NUM_REQS];
228
- /////////////////////
229
- // FIFO management //
230
- /////////////////////
231
- // Since an entry can contain unaligned instructions, popping an entry can leave the entry valid
232
- assign pop_fifo = out_ready_i & out_valid_o & (~aligned_is_compressed | out_addr_o[1]);
233
- for (genvar i = 0; i < (DEPTH - 1); i++) begin : g_fifo_next
234
- // Calculate lowest free entry (write pointer)
235
- if (i == 0) begin : g_ent0
236
- assign lowest_free_entry[i] = ~valid_q[i];
237
- end else begin : g_ent_others
238
- assign lowest_free_entry[i] = ~valid_q[i] & valid_q[i-1];
239
- end
240
- // An entry is set when an incoming request chooses the lowest available entry
241
- assign valid_pushed[i] = (in_valid_i & lowest_free_entry[i]) |
242
- valid_q[i];
243
- // Popping the FIFO shifts all entries down
244
- assign valid_popped[i] = pop_fifo ? valid_pushed[i+1] : valid_pushed[i];
245
- // All entries are wiped out on a clear
246
- assign valid_d[i] = valid_popped[i] & ~clear_i;
247
- // data flops are enabled if there is new data to shift into it, or
248
- assign entry_en[i] = (valid_pushed[i+1] & pop_fifo) |
249
- // a new request is incoming and this is the lowest free entry
250
- (in_valid_i & lowest_free_entry[i] & ~pop_fifo);
251
- // take the next entry or the incoming data
252
- assign rdata_d[i] = valid_q[i+1] ? rdata_q[i+1] : in_rdata_i;
253
- assign err_d [i] = valid_q[i+1] ? err_q [i+1] : in_err_i;
254
- end
255
- // The top entry is similar but with simpler muxing
256
- assign lowest_free_entry[DEPTH-1] = ~valid_q[DEPTH-1] & valid_q[DEPTH-2];
257
- assign valid_pushed [DEPTH-1] = valid_q[DEPTH-1] | (in_valid_i & lowest_free_entry[DEPTH-1]);
258
- assign valid_popped [DEPTH-1] = pop_fifo ? 1'b0 : valid_pushed[DEPTH-1];
259
- assign valid_d [DEPTH-1] = valid_popped[DEPTH-1] & ~clear_i;
260
- assign entry_en[DEPTH-1] = in_valid_i & lowest_free_entry[DEPTH-1];
261
- assign rdata_d [DEPTH-1] = in_rdata_i;
262
- assign err_d [DEPTH-1] = in_err_i;
263
- ////////////////////
264
- // FIFO registers //
265
- ////////////////////
266
- always_ff @(posedge clk_i or negedge rst_ni) begin
267
- if (!rst_ni) begin
268
- valid_q <= '0;
269
- end else begin
270
- valid_q <= valid_d;
271
- end
272
- end
273
- for (genvar i = 0; i < DEPTH; i++) begin : g_fifo_regs
274
- always_ff @(posedge clk_i or negedge rst_ni) begin
275
- if (!rst_ni) begin
276
- rdata_q[i] <= '0;
277
- err_q[i] <= '0;
278
- end else if (entry_en[i]) begin
279
- rdata_q[i] <= rdata_d[i];
280
- err_q[i] <= err_d[i];
281
- end
282
- end
283
- end
284
- ////////////////
285
- // Assertions //
286
- ////////////////
287
- // Must not push and pop simultaneously when FIFO full.
288
- // Must not push to FIFO when full.
289
- endmodule
290
- // Copyright (c) 2025 Eclipse Foundation
291
- // Copyright lowRISC contributors.
292
- // Copyright 2018 ETH Zurich and University of Bologna, see also CREDITS.md.
293
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
294
- // SPDX-License-Identifier: Apache-2.0
295
- /**
296
- * Prefetcher Buffer for 32 bit memory interface
297
- *
298
- * Prefetch Buffer that caches instructions. This cuts overly long critical
299
- * paths to the instruction cache.
300
- */
301
- module cve2_prefetch_buffer #(
302
- ) (
303
- input logic clk_i,
304
- input logic rst_ni,
305
- input logic req_i,
306
- input logic branch_i,
307
- input logic [31:0] addr_i,
308
- input logic ready_i,
309
- output logic valid_o,
310
- output logic [31:0] rdata_o,
311
- output logic [31:0] addr_o,
312
- output logic err_o,
313
- output logic err_plus2_o,
314
- // goes to instruction memory / instruction cache
315
- output logic instr_req_o,
316
- input logic instr_gnt_i,
317
- output logic [31:0] instr_addr_o,
318
- input logic [31:0] instr_rdata_i,
319
- input logic instr_err_i,
320
- input logic instr_rvalid_i,
321
- // Prefetch Buffer Status
322
- output logic busy_o
323
- );
324
- localparam int unsigned NUM_REQS = 2;
325
- logic valid_new_req, valid_req;
326
- logic valid_req_d, valid_req_q;
327
- logic discard_req_d, discard_req_q;
328
- logic [NUM_REQS-1:0] rdata_outstanding_n, rdata_outstanding_s, rdata_outstanding_q;
329
- logic [NUM_REQS-1:0] branch_discard_n, branch_discard_s, branch_discard_q;
330
- logic [NUM_REQS-1:0] rdata_outstanding_rev;
331
- logic [31:0] stored_addr_d, stored_addr_q;
332
- logic stored_addr_en;
333
- logic [31:0] fetch_addr_d, fetch_addr_q;
334
- logic fetch_addr_en;
335
- logic [31:0] instr_addr, instr_addr_w_aligned;
336
- logic fifo_valid;
337
- logic [31:0] fifo_addr;
338
- logic fifo_ready;
339
- logic fifo_clear;
340
- logic [NUM_REQS-1:0] fifo_busy;
341
- logic valid_raw;
342
- ////////////////////////////
343
- // Prefetch buffer status //
344
- ////////////////////////////
345
- assign busy_o = (|rdata_outstanding_q) | instr_req_o;
346
- //////////////////////////////////////////////
347
- // Fetch fifo - consumes addresses and data //
348
- //////////////////////////////////////////////
349
- // A branch will invalidate any previously fetched instructions.
350
- // Note that the FENCE.I instruction relies on this flushing behaviour on branch. If it is
351
- // altered the FENCE.I implementation may require changes.
352
- assign fifo_clear = branch_i;
353
- // Reversed version of rdata_outstanding_q which can be overlaid with fifo fill state
354
- for (genvar i = 0; i < NUM_REQS; i++) begin : gen_rd_rev
355
- assign rdata_outstanding_rev[i] = rdata_outstanding_q[NUM_REQS-1-i];
356
- end
357
- // The fifo is ready to accept a new request if it is not full - including space reserved for
358
- // requests already outstanding.
359
- // Overlay the fifo fill state with the outstanding requests to see if there is space.
360
- assign fifo_ready = ~&(fifo_busy | rdata_outstanding_rev);
361
- cve2_fetch_fifo #(
362
- .NUM_REQS (NUM_REQS)
363
- ) fifo_i (
364
- .clk_i ( clk_i ),
365
- .rst_ni ( rst_ni ),
366
- .clear_i ( fifo_clear ),
367
- .busy_o ( fifo_busy ),
368
- .in_valid_i ( fifo_valid ),
369
- .in_addr_i ( fifo_addr ),
370
- .in_rdata_i ( instr_rdata_i ),
371
- .in_err_i ( instr_err_i ),
372
- .out_valid_o ( valid_raw ),
373
- .out_ready_i ( ready_i ),
374
- .out_rdata_o ( rdata_o ),
375
- .out_addr_o ( addr_o ),
376
- .out_err_o ( err_o ),
377
- .out_err_plus2_o ( err_plus2_o )
378
- );
379
- //////////////
380
- // Requests //
381
- //////////////
382
- // Make a new request any time there is space in the FIFO, and space in the request queue
383
- assign valid_new_req = req_i & (fifo_ready | branch_i) &
384
- ~rdata_outstanding_q[NUM_REQS-1];
385
- assign valid_req = valid_req_q | valid_new_req;
386
- // Hold the request stable for requests that didn't get granted
387
- assign valid_req_d = valid_req & ~instr_gnt_i;
388
- // Record whether an outstanding bus request is cancelled by a branch
389
- assign discard_req_d = valid_req_q & (branch_i | discard_req_q);
390
- ////////////////
391
- // Fetch addr //
392
- ////////////////
393
- // Two addresses are tracked in the prefetch buffer:
394
- // 1. stored_addr_q - This is the address issued on the bus. It stays stable until
395
- // the request is granted.
396
- // 2. fetch_addr_q - This is our next address to fetch from. It is updated on branches to
397
- // capture the new address, and then for each new request issued.
398
- // A third address is tracked in the fetch FIFO itself:
399
- // 3. instr_addr_q - This is the address at the head of the FIFO, efectively our oldest fetched
400
- // address. This address is updated on branches, and does its own increment
401
- // each time the FIFO is popped.
402
- // 1. stored_addr_q
403
- // Only update stored_addr_q for new ungranted requests
404
- assign stored_addr_en = valid_new_req & ~valid_req_q & ~instr_gnt_i;
405
- // Store whatever address was issued on the bus
406
- assign stored_addr_d = instr_addr;
407
- // CPU resets with a branch, so no need to reset these addresses
408
- always_ff @(posedge clk_i or negedge rst_ni) begin
409
- if (!rst_ni) begin
410
- stored_addr_q <= '0;
411
- end else if (stored_addr_en) begin
412
- stored_addr_q <= stored_addr_d;
413
- end
414
- end
415
- // 2. fetch_addr_q
416
- // Update on a branch or as soon as a request is issued
417
- assign fetch_addr_en = branch_i | (valid_new_req & ~valid_req_q);
418
- assign fetch_addr_d = (branch_i ? addr_i :
419
- {fetch_addr_q[31:2], 2'b00}) +
420
- // Current address + 4
421
- {{29{1'b0}},(valid_new_req & ~valid_req_q),2'b00};
422
- always_ff @(posedge clk_i or negedge rst_ni) begin
423
- if (!rst_ni) begin
424
- fetch_addr_q <= '0;
425
- end else if (fetch_addr_en) begin
426
- fetch_addr_q <= fetch_addr_d;
427
- end
428
- end
429
- // Address mux
430
- assign instr_addr = valid_req_q ? stored_addr_q :
431
- branch_i ? addr_i :
432
- fetch_addr_q;
433
- assign instr_addr_w_aligned = {instr_addr[31:2], 2'b00};
434
- ///////////////////////////////
435
- // Request outstanding queue //
436
- ///////////////////////////////
437
- for (genvar i = 0; i < NUM_REQS; i++) begin : g_outstanding_reqs
438
- // Request 0 (always the oldest outstanding request)
439
- if (i == 0) begin : g_req0
440
- // A request becomes outstanding once granted, and is cleared once the rvalid is received.
441
- // Outstanding requests shift down the queue towards entry 0.
442
- assign rdata_outstanding_n[i] = (valid_req & instr_gnt_i) |
443
- rdata_outstanding_q[i];
444
- // If a branch is received at any point while a request is outstanding, it must be tracked
445
- // to ensure we discard the data once received
446
- assign branch_discard_n[i] = (valid_req & instr_gnt_i & discard_req_d) |
447
- (branch_i & rdata_outstanding_q[i]) |
448
- branch_discard_q[i];
449
- end else begin : g_reqtop
450
- // Entries > 0 consider the FIFO fill state to calculate their next state (by checking
451
- // whether the previous entry is valid)
452
- assign rdata_outstanding_n[i] = (valid_req & instr_gnt_i &
453
- rdata_outstanding_q[i-1]) |
454
- rdata_outstanding_q[i];
455
- assign branch_discard_n[i] = (valid_req & instr_gnt_i & discard_req_d &
456
- rdata_outstanding_q[i-1]) |
457
- (branch_i & rdata_outstanding_q[i]) |
458
- branch_discard_q[i];
459
- end
460
- end
461
- // Shift the entries down on each instr_rvalid_i
462
- assign rdata_outstanding_s = instr_rvalid_i ? {1'b0,rdata_outstanding_n[NUM_REQS-1:1]} :
463
- rdata_outstanding_n;
464
- assign branch_discard_s = instr_rvalid_i ? {1'b0,branch_discard_n[NUM_REQS-1:1]} :
465
- branch_discard_n;
466
- // Push a new entry to the FIFO once complete (and not cancelled by a branch)
467
- assign fifo_valid = instr_rvalid_i & ~branch_discard_q[0];
468
- assign fifo_addr = addr_i;
469
- ///////////////
470
- // Registers //
471
- ///////////////
472
- always_ff @(posedge clk_i or negedge rst_ni) begin
473
- if (!rst_ni) begin
474
- valid_req_q <= 1'b0;
475
- discard_req_q <= 1'b0;
476
- rdata_outstanding_q <= 'b0;
477
- branch_discard_q <= 'b0;
478
- end else begin
479
- valid_req_q <= valid_req_d;
480
- discard_req_q <= discard_req_d;
481
- rdata_outstanding_q <= rdata_outstanding_s;
482
- branch_discard_q <= branch_discard_s;
483
- end
484
- end
485
- /////////////
486
- // Outputs //
487
- /////////////
488
- assign instr_req_o = valid_req;
489
- assign instr_addr_o = instr_addr_w_aligned;
490
- assign valid_o = valid_raw;
491
- endmodule
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p12/mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"conditional_statement": [[19537, 19663], [19595, 19663], [10106, 10174], [8964, 9097], [10048, 10174], [18999, 19070], [12851, 12943], [18940, 19070], [13164, 13268]], "blocking_assignment": [[8890, 8922], [9057, 9087], [9205, 9228], [8849, 8883], [9007, 9027], [9176, 9198], [8929, 8957], [9145, 9169]], "module_program_interface_instantiation": [[16491, 17279]], "always_construct": [[18885, 19076], [8772, 9273], [12796, 12949], [22081, 22516], [9993, 10180], [13013, 13278], [19482, 19669]], "ansi_port_declaration": [[5157, 5196], [5074, 5113], [4848, 4882], [14419, 14453], [5468, 5511], [4885, 4920], [14136, 14164]], "continuous_assign": [[6503, 6553], [17780, 17844], [15528, 15581], [21998, 22024], [12100, 12160], [17425, 17540], [20623, 20833], [11520, 11592], [9715, 9887]], "parameter_declaration": [[4806, 4841]], "nonblocking_assignment": [[13233, 13256], [19626, 19655], [22410, 22454], [19031, 19062], [22322, 22358], [13197, 13222], [22365, 22403], [10137, 10166], [12916, 12935], [22461, 22502]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p13/all_mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"module_program_interface_instantiation": [], "continuous_assign": [[25959, 26004], [26009, 26054], [26059, 26101], [26200, 26365], [26370, 26462], [26465, 26511], [26514, 26557], [26711, 26863], [26866, 26909]], "blocking_assignment": [], "nonblocking_assignment": [], "case_statement": [], "conditional_statement": [], "always_construct": [], "parameter_declaration": [[6471, 6520], [6523, 6571], [6594, 6628], [6631, 6665], [6668, 6702], [12379, 12461], [12464, 12546], [12570, 12622], [12625, 12677], [12680, 12733], [12736, 12789], [12792, 12845], [12848, 12901], [12925, 13002], [13044, 13089], [13092, 13137], [13140, 13186], [13189, 13235], [13238, 13284], [13332, 13380], [13383, 13431], [13434, 13482], [13551, 13619], [13622, 13688], [13787, 13814], [16708, 16752], [16755, 16799], [16802, 16847], [16850, 16895], [16898, 16943], [16946, 16990], [16993, 17037], [17040, 17096]], "ansi_port_declaration": [[24864, 24903], [24906, 24946], [24949, 24990], [24993, 25051], [25054, 25109], [25112, 25165], [25168, 25232], [25235, 25282], [25285, 25332], [25335, 25379], [25382, 25430], [25433, 25478], [25481, 25528], [25531, 25578], [25581, 25625], [25628, 25678], [25681, 25728]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p13/cve2_wb.sv DELETED
@@ -1,796 +0,0 @@
1
- // Copyright (c) 2025 Eclipse Foundation
2
- // Copyright lowRISC contributors.
3
- // Copyright 2017 ETH Zurich and University of Bologna, see also CREDITS.md.
4
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
5
- // SPDX-License-Identifier: Apache-2.0
6
- /**
7
- * Package with constants used by CVE2
8
- */
9
- package cve2_pkg;
10
- ////////////////
11
- // IO Structs //
12
- ////////////////
13
- typedef struct packed {
14
- logic [31:0] current_pc;
15
- logic [31:0] next_pc;
16
- logic [31:0] last_data_addr;
17
- logic [31:0] exception_addr;
18
- } crash_dump_t;
19
- typedef struct packed {
20
- logic dummy_instr_id;
21
- logic [4:0] raddr_a;
22
- logic [4:0] waddr_a;
23
- logic we_a;
24
- logic [4:0] raddr_b;
25
- } core2rf_t;
26
- /////////////////////
27
- // Parameter Enums //
28
- /////////////////////
29
- typedef enum integer {
30
- RV32MNone = 0,
31
- RV32MSlow = 1,
32
- RV32MFast = 2,
33
- RV32MSingleCycle = 3
34
- } rv32m_e;
35
- typedef enum integer {
36
- RV32BNone = 0,
37
- RV32BBalanced = 1,
38
- RV32BOTEarlGrey = 2,
39
- RV32BFull = 3
40
- } rv32b_e;
41
- /////////////
42
- // Opcodes //
43
- /////////////
44
- typedef enum logic [6:0] {
45
- OPCODE_LOAD = 7'h03,
46
- OPCODE_MISC_MEM = 7'h0f,
47
- OPCODE_OP_IMM = 7'h13,
48
- OPCODE_AUIPC = 7'h17,
49
- OPCODE_STORE = 7'h23,
50
- OPCODE_OP = 7'h33,
51
- OPCODE_LUI = 7'h37,
52
- OPCODE_BRANCH = 7'h63,
53
- OPCODE_JALR = 7'h67,
54
- OPCODE_JAL = 7'h6f,
55
- OPCODE_SYSTEM = 7'h73
56
- } opcode_e;
57
- ////////////////////
58
- // ALU operations //
59
- ////////////////////
60
- typedef enum logic [6:0] {
61
- // Arithmetics
62
- ALU_ADD,
63
- ALU_SUB,
64
- // Logics
65
- ALU_XOR,
66
- ALU_OR,
67
- ALU_AND,
68
- // RV32B
69
- ALU_XNOR,
70
- ALU_ORN,
71
- ALU_ANDN,
72
- // Shifts
73
- ALU_SRA,
74
- ALU_SRL,
75
- ALU_SLL,
76
- // RV32B
77
- ALU_SRO,
78
- ALU_SLO,
79
- ALU_ROR,
80
- ALU_ROL,
81
- ALU_GREV,
82
- ALU_GORC,
83
- ALU_SHFL,
84
- ALU_UNSHFL,
85
- ALU_XPERM_N,
86
- ALU_XPERM_B,
87
- ALU_XPERM_H,
88
- // Address Calculations
89
- // RV32B
90
- ALU_SH1ADD,
91
- ALU_SH2ADD,
92
- ALU_SH3ADD,
93
- // Comparisons
94
- ALU_LT,
95
- ALU_LTU,
96
- ALU_GE,
97
- ALU_GEU,
98
- ALU_EQ,
99
- ALU_NE,
100
- // RV32B
101
- ALU_MIN,
102
- ALU_MINU,
103
- ALU_MAX,
104
- ALU_MAXU,
105
- // Pack
106
- // RV32B
107
- ALU_PACK,
108
- ALU_PACKU,
109
- ALU_PACKH,
110
- // Sign-Extend
111
- // RV32B
112
- ALU_SEXTB,
113
- ALU_SEXTH,
114
- // Bitcounting
115
- // RV32B
116
- ALU_CLZ,
117
- ALU_CTZ,
118
- ALU_CPOP,
119
- // Set lower than
120
- ALU_SLT,
121
- ALU_SLTU,
122
- // Ternary Bitmanip Operations
123
- // RV32B
124
- ALU_CMOV,
125
- ALU_CMIX,
126
- ALU_FSL,
127
- ALU_FSR,
128
- // Single-Bit Operations
129
- // RV32B
130
- ALU_BSET,
131
- ALU_BCLR,
132
- ALU_BINV,
133
- ALU_BEXT,
134
- // Bit Compress / Decompress
135
- // RV32B
136
- ALU_BCOMPRESS,
137
- ALU_BDECOMPRESS,
138
- // Bit Field Place
139
- // RV32B
140
- ALU_BFP,
141
- // Carry-less Multiply
142
- // RV32B
143
- ALU_CLMUL,
144
- ALU_CLMULR,
145
- ALU_CLMULH,
146
- // Cyclic Redundancy Check
147
- ALU_CRC32_B,
148
- ALU_CRC32C_B,
149
- ALU_CRC32_H,
150
- ALU_CRC32C_H,
151
- ALU_CRC32_W,
152
- ALU_CRC32C_W
153
- } alu_op_e;
154
- typedef enum logic [1:0] {
155
- // Multiplier/divider
156
- MD_OP_MULL,
157
- MD_OP_MULH,
158
- MD_OP_DIV,
159
- MD_OP_REM
160
- } md_op_e;
161
- //////////////////////////////////
162
- // Control and status registers //
163
- //////////////////////////////////
164
- // CSR operations
165
- typedef enum logic [1:0] {
166
- CSR_OP_READ,
167
- CSR_OP_WRITE,
168
- CSR_OP_SET,
169
- CSR_OP_CLEAR
170
- } csr_op_e;
171
- // Privileged mode
172
- typedef enum logic[1:0] {
173
- PRIV_LVL_M = 2'b11,
174
- PRIV_LVL_H = 2'b10,
175
- PRIV_LVL_S = 2'b01,
176
- PRIV_LVL_U = 2'b00
177
- } priv_lvl_e;
178
- // Constants for the dcsr.xdebugver fields
179
- typedef enum logic[3:0] {
180
- XDEBUGVER_NO = 4'd0, // no external debug support
181
- XDEBUGVER_STD = 4'd4, // external debug according to RISC-V debug spec
182
- XDEBUGVER_NONSTD = 4'd15 // debug not conforming to RISC-V debug spec
183
- } x_debug_ver_e;
184
- //////////////
185
- // WB stage //
186
- //////////////
187
- // Type of instruction present in writeback stage
188
- typedef enum logic[1:0] {
189
- WB_INSTR_LOAD, // Instruction is awaiting load data
190
- WB_INSTR_STORE, // Instruction is awaiting store response
191
- WB_INSTR_OTHER // Instruction doesn't fit into above categories
192
- } wb_instr_type_e;
193
- //////////////
194
- // ID stage //
195
- //////////////
196
- // Operand a selection
197
- typedef enum logic[1:0] {
198
- OP_A_REG_A,
199
- OP_A_FWD,
200
- OP_A_CURRPC,
201
- OP_A_IMM
202
- } op_a_sel_e;
203
- // Immediate a selection
204
- typedef enum logic {
205
- IMM_A_Z,
206
- IMM_A_ZERO
207
- } imm_a_sel_e;
208
- // Operand b selection
209
- typedef enum logic {
210
- OP_B_REG_B,
211
- OP_B_IMM
212
- } op_b_sel_e;
213
- // Immediate b selection
214
- typedef enum logic [2:0] {
215
- IMM_B_I,
216
- IMM_B_S,
217
- IMM_B_B,
218
- IMM_B_U,
219
- IMM_B_J,
220
- IMM_B_INCR_PC,
221
- IMM_B_INCR_ADDR
222
- } imm_b_sel_e;
223
- // Regfile write data selection
224
- typedef enum {
225
- RF_WD_EX,
226
- RF_WD_CSR,
227
- RF_WD_COPROC // Only used when XInterface = 1
228
- } rf_wd_sel_e;
229
- //////////////
230
- // IF stage //
231
- //////////////
232
- // PC mux selection
233
- typedef enum logic [2:0] {
234
- PC_BOOT,
235
- PC_JUMP,
236
- PC_EXC,
237
- PC_ERET,
238
- PC_DRET,
239
- PC_BP
240
- } pc_sel_e;
241
- // Exception PC mux selection
242
- typedef enum logic [1:0] {
243
- EXC_PC_EXC,
244
- EXC_PC_IRQ,
245
- EXC_PC_DBD,
246
- EXC_PC_DBG_EXC // Exception while in debug mode
247
- } exc_pc_sel_e;
248
- // Interrupt requests
249
- typedef struct packed {
250
- logic irq_software;
251
- logic irq_timer;
252
- logic irq_external;
253
- logic [15:0] irq_fast; // 16 fast interrupts
254
- } irqs_t;
255
- // Exception cause
256
- typedef enum logic [6:0] {
257
- EXC_CAUSE_IRQ_SOFTWARE_M = {1'b1, 6'd03},
258
- EXC_CAUSE_IRQ_TIMER_M = {1'b1, 6'd07},
259
- EXC_CAUSE_IRQ_EXTERNAL_M = {1'b1, 6'd11},
260
- // EXC_CAUSE_IRQ_FAST_0 = {1'b1, 6'd16},
261
- // EXC_CAUSE_IRQ_FAST_15 = {1'b1, 6'd31},
262
- EXC_CAUSE_IRQ_NM = {1'b1, 6'd32},
263
- EXC_CAUSE_INSN_ADDR_MISA = {1'b0, 6'd00},
264
- EXC_CAUSE_INSTR_ACCESS_FAULT = {1'b0, 6'd01},
265
- EXC_CAUSE_ILLEGAL_INSN = {1'b0, 6'd02},
266
- EXC_CAUSE_BREAKPOINT = {1'b0, 6'd03},
267
- EXC_CAUSE_LOAD_ACCESS_FAULT = {1'b0, 6'd05},
268
- EXC_CAUSE_STORE_ACCESS_FAULT = {1'b0, 6'd07},
269
- EXC_CAUSE_ECALL_UMODE = {1'b0, 6'd08},
270
- EXC_CAUSE_ECALL_MMODE = {1'b0, 6'd11}
271
- } exc_cause_e;
272
- // Debug cause
273
- typedef enum logic [2:0] {
274
- DBG_CAUSE_NONE = 3'h0,
275
- DBG_CAUSE_EBREAK = 3'h1,
276
- DBG_CAUSE_TRIGGER = 3'h2,
277
- DBG_CAUSE_HALTREQ = 3'h3,
278
- DBG_CAUSE_STEP = 3'h4
279
- } dbg_cause_e;
280
- // PMP constants
281
- parameter int unsigned PMP_MAX_REGIONS = 16;
282
- parameter int unsigned PMP_CFG_W = 8;
283
- // PMP acces type
284
- parameter int unsigned PMP_I = 0;
285
- parameter int unsigned PMP_I2 = 1;
286
- parameter int unsigned PMP_D = 2;
287
- typedef enum logic [1:0] {
288
- PMP_ACC_EXEC = 2'b00,
289
- PMP_ACC_WRITE = 2'b01,
290
- PMP_ACC_READ = 2'b10
291
- } pmp_req_e;
292
- // PMP cfg structures
293
- typedef enum logic [1:0] {
294
- PMP_MODE_OFF = 2'b00,
295
- PMP_MODE_TOR = 2'b01,
296
- PMP_MODE_NA4 = 2'b10,
297
- PMP_MODE_NAPOT = 2'b11
298
- } pmp_cfg_mode_e;
299
- typedef struct packed {
300
- logic lock;
301
- pmp_cfg_mode_e mode;
302
- logic exec;
303
- logic write;
304
- logic read;
305
- } pmp_cfg_t;
306
- // Machine Security Configuration (ePMP)
307
- typedef struct packed {
308
- logic rlb; // Rule Locking Bypass
309
- logic mmwp; // Machine Mode Whitelist Policy
310
- logic mml; // Machine Mode Lockdown
311
- } pmp_mseccfg_t;
312
- // CSRs
313
- typedef enum logic[11:0] {
314
- // Machine information
315
- CSR_MVENDORID = 12'hF11,
316
- CSR_MARCHID = 12'hF12,
317
- CSR_MIMPID = 12'hF13,
318
- CSR_MHARTID = 12'hF14,
319
- CSR_MCONFIGPTR = 12'hF15,
320
- // Machine trap setup
321
- CSR_MSTATUS = 12'h300,
322
- CSR_MISA = 12'h301,
323
- CSR_MIE = 12'h304,
324
- CSR_MTVEC = 12'h305,
325
- CSR_MCOUNTEREN= 12'h306,
326
- CSR_MSTATUSH = 12'h310,
327
- CSR_MENVCFG = 12'h30A,
328
- CSR_MENVCFGH = 12'h31A,
329
- // Machine trap handling
330
- CSR_MSCRATCH = 12'h340,
331
- CSR_MEPC = 12'h341,
332
- CSR_MCAUSE = 12'h342,
333
- CSR_MTVAL = 12'h343,
334
- CSR_MIP = 12'h344,
335
- // Physical memory protection
336
- CSR_PMPCFG0 = 12'h3A0,
337
- CSR_PMPCFG1 = 12'h3A1,
338
- CSR_PMPCFG2 = 12'h3A2,
339
- CSR_PMPCFG3 = 12'h3A3,
340
- CSR_PMPADDR0 = 12'h3B0,
341
- CSR_PMPADDR1 = 12'h3B1,
342
- CSR_PMPADDR2 = 12'h3B2,
343
- CSR_PMPADDR3 = 12'h3B3,
344
- CSR_PMPADDR4 = 12'h3B4,
345
- CSR_PMPADDR5 = 12'h3B5,
346
- CSR_PMPADDR6 = 12'h3B6,
347
- CSR_PMPADDR7 = 12'h3B7,
348
- CSR_PMPADDR8 = 12'h3B8,
349
- CSR_PMPADDR9 = 12'h3B9,
350
- CSR_PMPADDR10 = 12'h3BA,
351
- CSR_PMPADDR11 = 12'h3BB,
352
- CSR_PMPADDR12 = 12'h3BC,
353
- CSR_PMPADDR13 = 12'h3BD,
354
- CSR_PMPADDR14 = 12'h3BE,
355
- CSR_PMPADDR15 = 12'h3BF,
356
- // ePMP control
357
- CSR_MSECCFG = 12'h747,
358
- CSR_MSECCFGH = 12'h757,
359
- // Debug trigger
360
- CSR_TSELECT = 12'h7A0,
361
- CSR_TDATA1 = 12'h7A1,
362
- CSR_TDATA2 = 12'h7A2,
363
- CSR_TDATA3 = 12'h7A3,
364
- CSR_MCONTEXT = 12'h7A8,
365
- CSR_SCONTEXT = 12'h7AA,
366
- // Debug/trace
367
- CSR_DCSR = 12'h7b0,
368
- CSR_DPC = 12'h7b1,
369
- // Debug
370
- CSR_DSCRATCH0 = 12'h7b2, // optional
371
- CSR_DSCRATCH1 = 12'h7b3, // optional
372
- // Machine Counter/Timers
373
- CSR_MCOUNTINHIBIT = 12'h320,
374
- CSR_MHPMEVENT3 = 12'h323,
375
- CSR_MHPMEVENT4 = 12'h324,
376
- CSR_MHPMEVENT5 = 12'h325,
377
- CSR_MHPMEVENT6 = 12'h326,
378
- CSR_MHPMEVENT7 = 12'h327,
379
- CSR_MHPMEVENT8 = 12'h328,
380
- CSR_MHPMEVENT9 = 12'h329,
381
- CSR_MHPMEVENT10 = 12'h32A,
382
- CSR_MHPMEVENT11 = 12'h32B,
383
- CSR_MHPMEVENT12 = 12'h32C,
384
- CSR_MHPMEVENT13 = 12'h32D,
385
- CSR_MHPMEVENT14 = 12'h32E,
386
- CSR_MHPMEVENT15 = 12'h32F,
387
- CSR_MHPMEVENT16 = 12'h330,
388
- CSR_MHPMEVENT17 = 12'h331,
389
- CSR_MHPMEVENT18 = 12'h332,
390
- CSR_MHPMEVENT19 = 12'h333,
391
- CSR_MHPMEVENT20 = 12'h334,
392
- CSR_MHPMEVENT21 = 12'h335,
393
- CSR_MHPMEVENT22 = 12'h336,
394
- CSR_MHPMEVENT23 = 12'h337,
395
- CSR_MHPMEVENT24 = 12'h338,
396
- CSR_MHPMEVENT25 = 12'h339,
397
- CSR_MHPMEVENT26 = 12'h33A,
398
- CSR_MHPMEVENT27 = 12'h33B,
399
- CSR_MHPMEVENT28 = 12'h33C,
400
- CSR_MHPMEVENT29 = 12'h33D,
401
- CSR_MHPMEVENT30 = 12'h33E,
402
- CSR_MHPMEVENT31 = 12'h33F,
403
- CSR_MCYCLE = 12'hB00,
404
- CSR_MINSTRET = 12'hB02,
405
- CSR_MHPMCOUNTER3 = 12'hB03,
406
- CSR_MHPMCOUNTER4 = 12'hB04,
407
- CSR_MHPMCOUNTER5 = 12'hB05,
408
- CSR_MHPMCOUNTER6 = 12'hB06,
409
- CSR_MHPMCOUNTER7 = 12'hB07,
410
- CSR_MHPMCOUNTER8 = 12'hB08,
411
- CSR_MHPMCOUNTER9 = 12'hB09,
412
- CSR_MHPMCOUNTER10 = 12'hB0A,
413
- CSR_MHPMCOUNTER11 = 12'hB0B,
414
- CSR_MHPMCOUNTER12 = 12'hB0C,
415
- CSR_MHPMCOUNTER13 = 12'hB0D,
416
- CSR_MHPMCOUNTER14 = 12'hB0E,
417
- CSR_MHPMCOUNTER15 = 12'hB0F,
418
- CSR_MHPMCOUNTER16 = 12'hB10,
419
- CSR_MHPMCOUNTER17 = 12'hB11,
420
- CSR_MHPMCOUNTER18 = 12'hB12,
421
- CSR_MHPMCOUNTER19 = 12'hB13,
422
- CSR_MHPMCOUNTER20 = 12'hB14,
423
- CSR_MHPMCOUNTER21 = 12'hB15,
424
- CSR_MHPMCOUNTER22 = 12'hB16,
425
- CSR_MHPMCOUNTER23 = 12'hB17,
426
- CSR_MHPMCOUNTER24 = 12'hB18,
427
- CSR_MHPMCOUNTER25 = 12'hB19,
428
- CSR_MHPMCOUNTER26 = 12'hB1A,
429
- CSR_MHPMCOUNTER27 = 12'hB1B,
430
- CSR_MHPMCOUNTER28 = 12'hB1C,
431
- CSR_MHPMCOUNTER29 = 12'hB1D,
432
- CSR_MHPMCOUNTER30 = 12'hB1E,
433
- CSR_MHPMCOUNTER31 = 12'hB1F,
434
- CSR_MCYCLEH = 12'hB80,
435
- CSR_MINSTRETH = 12'hB82,
436
- CSR_MHPMCOUNTER3H = 12'hB83,
437
- CSR_MHPMCOUNTER4H = 12'hB84,
438
- CSR_MHPMCOUNTER5H = 12'hB85,
439
- CSR_MHPMCOUNTER6H = 12'hB86,
440
- CSR_MHPMCOUNTER7H = 12'hB87,
441
- CSR_MHPMCOUNTER8H = 12'hB88,
442
- CSR_MHPMCOUNTER9H = 12'hB89,
443
- CSR_MHPMCOUNTER10H = 12'hB8A,
444
- CSR_MHPMCOUNTER11H = 12'hB8B,
445
- CSR_MHPMCOUNTER12H = 12'hB8C,
446
- CSR_MHPMCOUNTER13H = 12'hB8D,
447
- CSR_MHPMCOUNTER14H = 12'hB8E,
448
- CSR_MHPMCOUNTER15H = 12'hB8F,
449
- CSR_MHPMCOUNTER16H = 12'hB90,
450
- CSR_MHPMCOUNTER17H = 12'hB91,
451
- CSR_MHPMCOUNTER18H = 12'hB92,
452
- CSR_MHPMCOUNTER19H = 12'hB93,
453
- CSR_MHPMCOUNTER20H = 12'hB94,
454
- CSR_MHPMCOUNTER21H = 12'hB95,
455
- CSR_MHPMCOUNTER22H = 12'hB96,
456
- CSR_MHPMCOUNTER23H = 12'hB97,
457
- CSR_MHPMCOUNTER24H = 12'hB98,
458
- CSR_MHPMCOUNTER25H = 12'hB99,
459
- CSR_MHPMCOUNTER26H = 12'hB9A,
460
- CSR_MHPMCOUNTER27H = 12'hB9B,
461
- CSR_MHPMCOUNTER28H = 12'hB9C,
462
- CSR_MHPMCOUNTER29H = 12'hB9D,
463
- CSR_MHPMCOUNTER30H = 12'hB9E,
464
- CSR_MHPMCOUNTER31H = 12'hB9F,
465
- CSR_CPUCTRL = 12'h7C0,
466
- CSR_SECURESEED = 12'h7C1
467
- } csr_num_e;
468
- // CSR pmp-related offsets
469
- parameter logic [11:0] CSR_OFF_PMP_CFG = 12'h3A0; // pmp_cfg @ 12'h3a0 - 12'h3a3
470
- parameter logic [11:0] CSR_OFF_PMP_ADDR = 12'h3B0; // pmp_addr @ 12'h3b0 - 12'h3bf
471
- // CSR status bits
472
- parameter int unsigned CSR_MSTATUS_MIE_BIT = 3;
473
- parameter int unsigned CSR_MSTATUS_MPIE_BIT = 7;
474
- parameter int unsigned CSR_MSTATUS_MPP_BIT_LOW = 11;
475
- parameter int unsigned CSR_MSTATUS_MPP_BIT_HIGH = 12;
476
- parameter int unsigned CSR_MSTATUS_MPRV_BIT = 17;
477
- parameter int unsigned CSR_MSTATUS_TW_BIT = 21;
478
- // CSR machine ISA
479
- parameter logic [1:0] CSR_MISA_MXL = 2'd1; // M-XLEN: XLEN in M-Mode for RV32
480
- // CSR interrupt pending/enable bits
481
- parameter int unsigned CSR_MSIX_BIT = 3;
482
- parameter int unsigned CSR_MTIX_BIT = 7;
483
- parameter int unsigned CSR_MEIX_BIT = 11;
484
- parameter int unsigned CSR_MFIX_BIT_LOW = 16;
485
- parameter int unsigned CSR_MFIX_BIT_HIGH = 31;
486
- // CSR Machine Security Configuration bits
487
- parameter int unsigned CSR_MSECCFG_MML_BIT = 0;
488
- parameter int unsigned CSR_MSECCFG_MMWP_BIT = 1;
489
- parameter int unsigned CSR_MSECCFG_RLB_BIT = 2;
490
- // Machine Vendor ID - OpenHW JEDEC ID is '2 decimal (bank 13)'
491
- parameter MVENDORID_OFFSET = 7'h2; // Final byte without parity bit
492
- parameter MVENDORID_BANK = 25'hC; // Number of continuation codes
493
- // Machine Architecture ID (https://github.com/riscv/riscv-isa-manual/blob/master/marchid.md)
494
- parameter MARCHID = 32'd35;
495
- localparam logic [31:0] CSR_MVENDORID_VALUE = {MVENDORID_BANK, MVENDORID_OFFSET};
496
- localparam logic [31:0] CSR_MARCHID_VALUE = MARCHID;
497
- // Implementation ID
498
- // 0 indicates this field is not implemeted. cve2 implementors may wish to indicate an RTL/netlist
499
- // version here using their own unique encoding (e.g. 32 bits of the git hash of the implemented
500
- // commit).
501
- localparam logic [31:0] CSR_MIMPID_VALUE = 32'b0;
502
- // Machine Configuration Pointer
503
- // 0 indicates the configuration data structure does not eixst. cve2 implementors may wish to
504
- // alter this to point to their system specific configuration data structure.
505
- localparam logic [31:0] CSR_MCONFIGPTR_VALUE = 32'b0;
506
- // RVFI CSR element
507
- typedef struct packed {
508
- bit [63:0] rdata;
509
- bit [63:0] rmask;
510
- bit [63:0] wdata;
511
- bit [63:0] wmask;
512
- } rvfi_csr_elmt_t;
513
- // RVFI CSR structure
514
- typedef struct packed {
515
- rvfi_csr_elmt_t fflags;
516
- rvfi_csr_elmt_t frm;
517
- rvfi_csr_elmt_t fcsr;
518
- rvfi_csr_elmt_t ftran;
519
- rvfi_csr_elmt_t dcsr;
520
- rvfi_csr_elmt_t dpc;
521
- rvfi_csr_elmt_t dscratch0;
522
- rvfi_csr_elmt_t dscratch1;
523
- rvfi_csr_elmt_t sstatus;
524
- rvfi_csr_elmt_t sie;
525
- rvfi_csr_elmt_t sip;
526
- rvfi_csr_elmt_t stvec;
527
- rvfi_csr_elmt_t scounteren;
528
- rvfi_csr_elmt_t sscratch;
529
- rvfi_csr_elmt_t sepc;
530
- rvfi_csr_elmt_t scause;
531
- rvfi_csr_elmt_t stval;
532
- rvfi_csr_elmt_t satp;
533
- rvfi_csr_elmt_t mstatus;
534
- rvfi_csr_elmt_t mstatush;
535
- rvfi_csr_elmt_t misa;
536
- rvfi_csr_elmt_t medeleg;
537
- rvfi_csr_elmt_t mideleg;
538
- rvfi_csr_elmt_t mie;
539
- rvfi_csr_elmt_t mtvec;
540
- rvfi_csr_elmt_t mcounteren;
541
- rvfi_csr_elmt_t mscratch;
542
- rvfi_csr_elmt_t mepc;
543
- rvfi_csr_elmt_t mcause;
544
- rvfi_csr_elmt_t mtval;
545
- rvfi_csr_elmt_t mip;
546
- rvfi_csr_elmt_t menvcfg;
547
- rvfi_csr_elmt_t menvcfgh;
548
- rvfi_csr_elmt_t mvendorid;
549
- rvfi_csr_elmt_t marchid;
550
- rvfi_csr_elmt_t mhartid;
551
- rvfi_csr_elmt_t mcountinhibit;
552
- rvfi_csr_elmt_t mcycle;
553
- rvfi_csr_elmt_t mcycleh;
554
- rvfi_csr_elmt_t minstret;
555
- rvfi_csr_elmt_t minstreth;
556
- rvfi_csr_elmt_t cycle;
557
- rvfi_csr_elmt_t cycleh;
558
- rvfi_csr_elmt_t instret;
559
- rvfi_csr_elmt_t instreth;
560
- rvfi_csr_elmt_t dcache;
561
- rvfi_csr_elmt_t icache;
562
- rvfi_csr_elmt_t acc_cons;
563
- rvfi_csr_elmt_t pmpcfg0;
564
- rvfi_csr_elmt_t pmpcfg1;
565
- rvfi_csr_elmt_t pmpcfg2;
566
- rvfi_csr_elmt_t pmpcfg3;
567
- rvfi_csr_elmt_t pmpaddr0;
568
- rvfi_csr_elmt_t pmpaddr1;
569
- rvfi_csr_elmt_t pmpaddr2;
570
- rvfi_csr_elmt_t pmpaddr3;
571
- rvfi_csr_elmt_t pmpaddr4;
572
- rvfi_csr_elmt_t pmpaddr5;
573
- rvfi_csr_elmt_t pmpaddr6;
574
- rvfi_csr_elmt_t pmpaddr7;
575
- rvfi_csr_elmt_t pmpaddr8;
576
- rvfi_csr_elmt_t pmpaddr9;
577
- rvfi_csr_elmt_t pmpaddr10;
578
- rvfi_csr_elmt_t pmpaddr11;
579
- rvfi_csr_elmt_t pmpaddr12;
580
- rvfi_csr_elmt_t pmpaddr13;
581
- rvfi_csr_elmt_t pmpaddr14;
582
- rvfi_csr_elmt_t pmpaddr15;
583
- } rvfi_csr_t;
584
- // CV-X-IF
585
- parameter int unsigned X_NUM_RS = 3;
586
- parameter int unsigned X_ID_WIDTH = 4;
587
- parameter int unsigned X_RFR_WIDTH = 32;
588
- parameter int unsigned X_RFW_WIDTH = 32;
589
- parameter int unsigned X_HARTID_WIDTH = 32;
590
- parameter int unsigned X_DUAL_READ = 0;
591
- parameter int unsigned X_DUAL_WRITE = 0;
592
- parameter int unsigned X_INSTR_INFLIGHT = 2**X_ID_WIDTH;
593
- typedef logic [X_NUM_RS+X_DUAL_READ-1:0] readregflags_t;
594
- typedef logic [X_DUAL_WRITE:0] writeregflags_t;
595
- typedef logic [X_ID_WIDTH-1:0] id_t;
596
- typedef logic [X_HARTID_WIDTH-1:0] hartid_t;
597
- // Issue Interface
598
- typedef struct packed {
599
- logic [31:0] instr;
600
- hartid_t hartid;
601
- id_t id;
602
- } x_issue_req_t;
603
- typedef struct packed {
604
- logic accept;
605
- writeregflags_t writeback;
606
- readregflags_t register_read;
607
- } x_issue_resp_t;
608
- // Register Interface
609
- typedef struct packed {
610
- hartid_t hartid;
611
- id_t id;
612
- logic [X_NUM_RS-1:0][X_RFR_WIDTH-1:0] rs;
613
- readregflags_t rs_valid;
614
- } x_register_t;
615
- // Commit Interface
616
- typedef struct packed {
617
- hartid_t hartid;
618
- id_t id;
619
- logic commit_kill;
620
- } x_commit_t;
621
- // Result Interface
622
- typedef struct packed {
623
- hartid_t hartid;
624
- id_t id;
625
- logic [X_RFW_WIDTH-1:0] data;
626
- logic [4:0] rd;
627
- writeregflags_t we;
628
- } x_result_t;
629
- endpackage
630
- // Copyright (c) 2025 Eclipse Foundation
631
- // Copyright lowRISC contributors.
632
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
633
- // SPDX-License-Identifier: Apache-2.0
634
- /**
635
- * Writeback passthrough
636
- *
637
- * The writeback stage is not present therefore this module acts as
638
- * a simple passthrough to write data direct to the register file.
639
- */
640
- // Copyright lowRISC contributors.
641
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
642
- // SPDX-License-Identifier: Apache-2.0
643
- // Macros and helper code for using assertions.
644
- // - Provides default clk and rst options to simplify code
645
- // - Provides boiler plate template for common assertions
646
- ///////////////////
647
- // Helper macros //
648
- ///////////////////
649
- // Default clk and reset signals used by assertion macros below.
650
- // Converts an arbitrary block of code into a Verilog string
651
- // ASSERT_ERROR logs an error message with either `uvm_error or with $error.
652
- //
653
- // This somewhat duplicates `DV_ERROR macro defined in hw/dv/sv/dv_utils/dv_macros.svh. The reason
654
- // for redefining it here is to avoid creating a dependency.
655
- // This macro is suitable for conditionally triggering lint errors, e.g., if a Sec parameter takes
656
- // on a non-default value. This may be required for pre-silicon/FPGA evaluation but we don't want
657
- // to allow this for tapeout.
658
- // The basic helper macros are actually defined in "implementation headers". The macros should do
659
- // the same thing in each case (except for the dummy flavour), but in a way that the respective
660
- // tools support.
661
- //
662
- // If the tool supports assertions in some form, we also define INC_ASSERT (which can be used to
663
- // hide signal definitions that are only used for assertions).
664
- //
665
- // The list of basic macros supported is:
666
- //
667
- // ASSERT_I: Immediate assertion. Note that immediate assertions are sensitive to simulation
668
- // glitches.
669
- //
670
- // ASSERT_INIT: Assertion in initial block. Can be used for things like parameter checking.
671
- //
672
- // ASSERT_INIT_NET: Assertion in initial block. Can be used for initial value of a net.
673
- //
674
- // ASSERT_FINAL: Assertion in final block. Can be used for things like queues being empty at end of
675
- // sim, all credits returned at end of sim, state machines in idle at end of sim.
676
- //
677
- // ASSERT: Assert a concurrent property directly. It can be called as a module (or
678
- // interface) body item.
679
- //
680
- // Note: We use (__rst !== '0) in the disable iff statements instead of (__rst ==
681
- // '1). This properly disables the assertion in cases when reset is X at the
682
- // beginning of a simulation. For that case, (reset == '1) does not disable the
683
- // assertion.
684
- //
685
- // ASSERT_NEVER: Assert a concurrent property NEVER happens
686
- //
687
- // ASSERT_KNOWN: Assert that signal has a known value (each bit is either '0' or '1') after reset.
688
- // It can be called as a module (or interface) body item.
689
- //
690
- // COVER: Cover a concurrent property
691
- //
692
- // ASSUME: Assume a concurrent property
693
- //
694
- // ASSUME_I: Assume an immediate property
695
- // Copyright lowRISC contributors.
696
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
697
- // SPDX-License-Identifier: Apache-2.0
698
- // Macro bodies included by prim_assert.sv for tools that don't support assertions. See
699
- // prim_assert.sv for documentation for each of the macros.
700
- //////////////////////////////
701
- // Complex assertion macros //
702
- //////////////////////////////
703
- // Assert that signal is an active-high pulse with pulse length of 1 clock cycle
704
- // Assert that a property is true only when an enable signal is set. It can be called as a module
705
- // (or interface) body item.
706
- // Assert that signal has a known value (each bit is either '0' or '1') after reset if enable is
707
- // set. It can be called as a module (or interface) body item.
708
- //////////////////////////////////
709
- // For formal verification only //
710
- //////////////////////////////////
711
- // Note that the existing set of ASSERT macros specified above shall be used for FPV,
712
- // thereby ensuring that the assertions are evaluated during DV simulations as well.
713
- // ASSUME_FPV
714
- // Assume a concurrent property during formal verification only.
715
- // ASSUME_I_FPV
716
- // Assume a concurrent property during formal verification only.
717
- // COVER_FPV
718
- // Cover a concurrent property during formal verification
719
- // Copyright lowRISC contributors.
720
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
721
- // SPDX-License-Identifier: Apache-2.0
722
- // // Macros and helper code for security countermeasures.
723
- // Helper macros
724
- // macros for security countermeasures
725
- // PRIM_ASSERT_SEC_CM_SVH
726
- // PRIM_ASSERT_SV
727
- // Copyright lowRISC contributors.
728
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
729
- // SPDX-License-Identifier: Apache-2.0
730
- // Include FCOV RTL by default. Disable it for synthesis and where explicitly requested (by defining
731
- // DV_FCOV_DISABLE).
732
- // Disable instantiations of FCOV coverpoints or covergroups.
733
- // Instantiates a covergroup in an interface or module.
734
- //
735
- // This macro assumes that a covergroup of the same name as the NAME_ arg is defined in the
736
- // interface or module. It just adds some extra signals and logic to control the creation of the
737
- // covergroup instance with ~bit en_<cg_name>~. This defaults to 0. It is ORed with the external
738
- // COND_ signal. The testbench can modify it at t = 0 based on the test being run.
739
- // NOTE: This is not meant to be invoked inside a class.
740
- //
741
- // NAME_ : Name of the covergroup.
742
- // COND_ : External condition / expr that controls the creation of the covergroup.
743
- // ARGS_ : Arguments to covergroup instance, if any. Args MUST BE wrapped in (..).
744
- // Creates a coverpoint for an expression where only the expression true case is of interest for
745
- // coverage (e.g. where the expression indicates an event has occured).
746
- // Creates a SVA cover that can be used in a covergroup.
747
- //
748
- // This macro creates an unnamed SVA cover from the property (or an expression) `PROP_` and an event
749
- // with the name `EV_NAME_`. When the SVA cover is hit, the event is triggered. A coverpoint can
750
- // cover the `triggered` property of the event.
751
- // Coverage support is not always available but it's useful to include extra fcov signals for
752
- // linting purposes. They need to be marked as unused to avoid warnings.
753
- // Define a signal and expression in the design for capture in functional coverage
754
- // Define a signal and expression in the design for capture in functional coverage depending on
755
- // design configuration. The input GEN_COND_ must be a constant or parameter.
756
- module cve2_wb #(
757
- ) (
758
- input logic clk_i,
759
- input logic rst_ni,
760
- input logic en_wb_i,
761
- input logic instr_is_compressed_id_i,
762
- input logic instr_perf_count_id_i,
763
- output logic perf_instr_ret_wb_o,
764
- output logic perf_instr_ret_compressed_wb_o,
765
- input logic [4:0] rf_waddr_id_i,
766
- input logic [31:0] rf_wdata_id_i,
767
- input logic rf_we_id_i,
768
- input logic [31:0] rf_wdata_lsu_i,
769
- input logic rf_we_lsu_i,
770
- output logic [4:0] rf_waddr_wb_o,
771
- output logic [31:0] rf_wdata_wb_o,
772
- output logic rf_we_wb_o,
773
- input logic lsu_resp_valid_i,
774
- input logic lsu_resp_err_i
775
- );
776
- import cve2_pkg::*;
777
- // 0 == RF write from ID
778
- // 1 == RF write from LSU
779
- logic [31:0] rf_wdata_wb_mux [2];
780
- logic [1:0] rf_wdata_wb_mux_we;
781
- // without writeback stage just pass through register write signals
782
- assign rf_waddr_wb_o = rf_waddr_id_i;
783
- assign rf_wdata_wb_mux[0] = rf_wdata_id_i;
784
- assign rf_wdata_wb_mux_we[0] = rf_we_id_i;
785
- // Increment instruction retire counters for valid instructions which are not lsu errors.
786
- assign perf_instr_ret_wb_o = instr_perf_count_id_i & en_wb_i &
787
- ~(lsu_resp_valid_i & lsu_resp_err_i);
788
- assign perf_instr_ret_compressed_wb_o = perf_instr_ret_wb_o & instr_is_compressed_id_i;
789
- assign rf_wdata_wb_mux[1] = rf_wdata_lsu_i;
790
- assign rf_wdata_wb_mux_we[1] = rf_we_lsu_i;
791
- // RF write data can come from ID results (all RF writes that aren't because of loads will come
792
- // from here) or the LSU (RF writes for load data)
793
- assign rf_wdata_wb_o = ({32{rf_wdata_wb_mux_we[0]}} & rf_wdata_wb_mux[0]) |
794
- ({32{rf_wdata_wb_mux_we[1]}} & rf_wdata_wb_mux[1]);
795
- assign rf_we_wb_o = |rf_wdata_wb_mux_we;
796
- endmodule
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p13/mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"ansi_port_declaration": [[25433, 25478], [24906, 24946], [25235, 25282], [24993, 25051], [25382, 25430], [25335, 25379], [25531, 25578]], "continuous_assign": [[26711, 26863], [26370, 26462], [26866, 26909], [26514, 26557], [26465, 26511], [25959, 26004], [26200, 26365], [26009, 26054]], "parameter_declaration": [[16802, 16847], [13551, 13619], [13787, 13814], [16708, 16752], [13622, 13688], [16898, 16943], [16850, 16895], [16946, 16990]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p2/all_mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"module_program_interface_instantiation": [], "continuous_assign": [[23969, 23998], [24138, 24223], [24226, 24320], [24350, 24488], [24491, 24600], [24689, 24745], [24748, 24801], [24832, 24928], [24931, 25027], [25459, 25540], [25622, 25707], [25732, 25788]], "blocking_assignment": [[25141, 25165], [25206, 25230], [25248, 25272], [25290, 25315], [25333, 25358]], "nonblocking_assignment": [], "case_statement": [[25170, 25388]], "conditional_statement": [], "always_construct": [[25119, 25394]], "parameter_declaration": [[6471, 6520], [6523, 6571], [6594, 6628], [6631, 6665], [6668, 6702], [12379, 12461], [12464, 12546], [12570, 12622], [12625, 12677], [12680, 12733], [12736, 12789], [12792, 12845], [12848, 12901], [12925, 13002], [13044, 13089], [13092, 13137], [13140, 13186], [13189, 13235], [13238, 13284], [13332, 13380], [13383, 13431], [13434, 13482], [13551, 13619], [13622, 13688], [13787, 13814], [16708, 16752], [16755, 16799], [16802, 16847], [16850, 16895], [16898, 16943], [16946, 16990], [16993, 17037], [17040, 17096]], "ansi_port_declaration": [[23297, 23316], [23319, 23339], [23376, 23410], [23413, 23444], [23447, 23481], [23525, 23568], [23571, 23610]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p2/cve2_branch_predict.sv DELETED
@@ -1,792 +0,0 @@
1
- // Copyright (c) 2025 Eclipse Foundation
2
- // Copyright lowRISC contributors.
3
- // Copyright 2017 ETH Zurich and University of Bologna, see also CREDITS.md.
4
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
5
- // SPDX-License-Identifier: Apache-2.0
6
- /**
7
- * Package with constants used by CVE2
8
- */
9
- package cve2_pkg;
10
- ////////////////
11
- // IO Structs //
12
- ////////////////
13
- typedef struct packed {
14
- logic [31:0] current_pc;
15
- logic [31:0] next_pc;
16
- logic [31:0] last_data_addr;
17
- logic [31:0] exception_addr;
18
- } crash_dump_t;
19
- typedef struct packed {
20
- logic dummy_instr_id;
21
- logic [4:0] raddr_a;
22
- logic [4:0] waddr_a;
23
- logic we_a;
24
- logic [4:0] raddr_b;
25
- } core2rf_t;
26
- /////////////////////
27
- // Parameter Enums //
28
- /////////////////////
29
- typedef enum integer {
30
- RV32MNone = 0,
31
- RV32MSlow = 1,
32
- RV32MFast = 2,
33
- RV32MSingleCycle = 3
34
- } rv32m_e;
35
- typedef enum integer {
36
- RV32BNone = 0,
37
- RV32BBalanced = 1,
38
- RV32BOTEarlGrey = 2,
39
- RV32BFull = 3
40
- } rv32b_e;
41
- /////////////
42
- // Opcodes //
43
- /////////////
44
- typedef enum logic [6:0] {
45
- OPCODE_LOAD = 7'h03,
46
- OPCODE_MISC_MEM = 7'h0f,
47
- OPCODE_OP_IMM = 7'h13,
48
- OPCODE_AUIPC = 7'h17,
49
- OPCODE_STORE = 7'h23,
50
- OPCODE_OP = 7'h33,
51
- OPCODE_LUI = 7'h37,
52
- OPCODE_BRANCH = 7'h63,
53
- OPCODE_JALR = 7'h67,
54
- OPCODE_JAL = 7'h6f,
55
- OPCODE_SYSTEM = 7'h73
56
- } opcode_e;
57
- ////////////////////
58
- // ALU operations //
59
- ////////////////////
60
- typedef enum logic [6:0] {
61
- // Arithmetics
62
- ALU_ADD,
63
- ALU_SUB,
64
- // Logics
65
- ALU_XOR,
66
- ALU_OR,
67
- ALU_AND,
68
- // RV32B
69
- ALU_XNOR,
70
- ALU_ORN,
71
- ALU_ANDN,
72
- // Shifts
73
- ALU_SRA,
74
- ALU_SRL,
75
- ALU_SLL,
76
- // RV32B
77
- ALU_SRO,
78
- ALU_SLO,
79
- ALU_ROR,
80
- ALU_ROL,
81
- ALU_GREV,
82
- ALU_GORC,
83
- ALU_SHFL,
84
- ALU_UNSHFL,
85
- ALU_XPERM_N,
86
- ALU_XPERM_B,
87
- ALU_XPERM_H,
88
- // Address Calculations
89
- // RV32B
90
- ALU_SH1ADD,
91
- ALU_SH2ADD,
92
- ALU_SH3ADD,
93
- // Comparisons
94
- ALU_LT,
95
- ALU_LTU,
96
- ALU_GE,
97
- ALU_GEU,
98
- ALU_EQ,
99
- ALU_NE,
100
- // RV32B
101
- ALU_MIN,
102
- ALU_MINU,
103
- ALU_MAX,
104
- ALU_MAXU,
105
- // Pack
106
- // RV32B
107
- ALU_PACK,
108
- ALU_PACKU,
109
- ALU_PACKH,
110
- // Sign-Extend
111
- // RV32B
112
- ALU_SEXTB,
113
- ALU_SEXTH,
114
- // Bitcounting
115
- // RV32B
116
- ALU_CLZ,
117
- ALU_CTZ,
118
- ALU_CPOP,
119
- // Set lower than
120
- ALU_SLT,
121
- ALU_SLTU,
122
- // Ternary Bitmanip Operations
123
- // RV32B
124
- ALU_CMOV,
125
- ALU_CMIX,
126
- ALU_FSL,
127
- ALU_FSR,
128
- // Single-Bit Operations
129
- // RV32B
130
- ALU_BSET,
131
- ALU_BCLR,
132
- ALU_BINV,
133
- ALU_BEXT,
134
- // Bit Compress / Decompress
135
- // RV32B
136
- ALU_BCOMPRESS,
137
- ALU_BDECOMPRESS,
138
- // Bit Field Place
139
- // RV32B
140
- ALU_BFP,
141
- // Carry-less Multiply
142
- // RV32B
143
- ALU_CLMUL,
144
- ALU_CLMULR,
145
- ALU_CLMULH,
146
- // Cyclic Redundancy Check
147
- ALU_CRC32_B,
148
- ALU_CRC32C_B,
149
- ALU_CRC32_H,
150
- ALU_CRC32C_H,
151
- ALU_CRC32_W,
152
- ALU_CRC32C_W
153
- } alu_op_e;
154
- typedef enum logic [1:0] {
155
- // Multiplier/divider
156
- MD_OP_MULL,
157
- MD_OP_MULH,
158
- MD_OP_DIV,
159
- MD_OP_REM
160
- } md_op_e;
161
- //////////////////////////////////
162
- // Control and status registers //
163
- //////////////////////////////////
164
- // CSR operations
165
- typedef enum logic [1:0] {
166
- CSR_OP_READ,
167
- CSR_OP_WRITE,
168
- CSR_OP_SET,
169
- CSR_OP_CLEAR
170
- } csr_op_e;
171
- // Privileged mode
172
- typedef enum logic[1:0] {
173
- PRIV_LVL_M = 2'b11,
174
- PRIV_LVL_H = 2'b10,
175
- PRIV_LVL_S = 2'b01,
176
- PRIV_LVL_U = 2'b00
177
- } priv_lvl_e;
178
- // Constants for the dcsr.xdebugver fields
179
- typedef enum logic[3:0] {
180
- XDEBUGVER_NO = 4'd0, // no external debug support
181
- XDEBUGVER_STD = 4'd4, // external debug according to RISC-V debug spec
182
- XDEBUGVER_NONSTD = 4'd15 // debug not conforming to RISC-V debug spec
183
- } x_debug_ver_e;
184
- //////////////
185
- // WB stage //
186
- //////////////
187
- // Type of instruction present in writeback stage
188
- typedef enum logic[1:0] {
189
- WB_INSTR_LOAD, // Instruction is awaiting load data
190
- WB_INSTR_STORE, // Instruction is awaiting store response
191
- WB_INSTR_OTHER // Instruction doesn't fit into above categories
192
- } wb_instr_type_e;
193
- //////////////
194
- // ID stage //
195
- //////////////
196
- // Operand a selection
197
- typedef enum logic[1:0] {
198
- OP_A_REG_A,
199
- OP_A_FWD,
200
- OP_A_CURRPC,
201
- OP_A_IMM
202
- } op_a_sel_e;
203
- // Immediate a selection
204
- typedef enum logic {
205
- IMM_A_Z,
206
- IMM_A_ZERO
207
- } imm_a_sel_e;
208
- // Operand b selection
209
- typedef enum logic {
210
- OP_B_REG_B,
211
- OP_B_IMM
212
- } op_b_sel_e;
213
- // Immediate b selection
214
- typedef enum logic [2:0] {
215
- IMM_B_I,
216
- IMM_B_S,
217
- IMM_B_B,
218
- IMM_B_U,
219
- IMM_B_J,
220
- IMM_B_INCR_PC,
221
- IMM_B_INCR_ADDR
222
- } imm_b_sel_e;
223
- // Regfile write data selection
224
- typedef enum {
225
- RF_WD_EX,
226
- RF_WD_CSR,
227
- RF_WD_COPROC // Only used when XInterface = 1
228
- } rf_wd_sel_e;
229
- //////////////
230
- // IF stage //
231
- //////////////
232
- // PC mux selection
233
- typedef enum logic [2:0] {
234
- PC_BOOT,
235
- PC_JUMP,
236
- PC_EXC,
237
- PC_ERET,
238
- PC_DRET,
239
- PC_BP
240
- } pc_sel_e;
241
- // Exception PC mux selection
242
- typedef enum logic [1:0] {
243
- EXC_PC_EXC,
244
- EXC_PC_IRQ,
245
- EXC_PC_DBD,
246
- EXC_PC_DBG_EXC // Exception while in debug mode
247
- } exc_pc_sel_e;
248
- // Interrupt requests
249
- typedef struct packed {
250
- logic irq_software;
251
- logic irq_timer;
252
- logic irq_external;
253
- logic [15:0] irq_fast; // 16 fast interrupts
254
- } irqs_t;
255
- // Exception cause
256
- typedef enum logic [6:0] {
257
- EXC_CAUSE_IRQ_SOFTWARE_M = {1'b1, 6'd03},
258
- EXC_CAUSE_IRQ_TIMER_M = {1'b1, 6'd07},
259
- EXC_CAUSE_IRQ_EXTERNAL_M = {1'b1, 6'd11},
260
- // EXC_CAUSE_IRQ_FAST_0 = {1'b1, 6'd16},
261
- // EXC_CAUSE_IRQ_FAST_15 = {1'b1, 6'd31},
262
- EXC_CAUSE_IRQ_NM = {1'b1, 6'd32},
263
- EXC_CAUSE_INSN_ADDR_MISA = {1'b0, 6'd00},
264
- EXC_CAUSE_INSTR_ACCESS_FAULT = {1'b0, 6'd01},
265
- EXC_CAUSE_ILLEGAL_INSN = {1'b0, 6'd02},
266
- EXC_CAUSE_BREAKPOINT = {1'b0, 6'd03},
267
- EXC_CAUSE_LOAD_ACCESS_FAULT = {1'b0, 6'd05},
268
- EXC_CAUSE_STORE_ACCESS_FAULT = {1'b0, 6'd07},
269
- EXC_CAUSE_ECALL_UMODE = {1'b0, 6'd08},
270
- EXC_CAUSE_ECALL_MMODE = {1'b0, 6'd11}
271
- } exc_cause_e;
272
- // Debug cause
273
- typedef enum logic [2:0] {
274
- DBG_CAUSE_NONE = 3'h0,
275
- DBG_CAUSE_EBREAK = 3'h1,
276
- DBG_CAUSE_TRIGGER = 3'h2,
277
- DBG_CAUSE_HALTREQ = 3'h3,
278
- DBG_CAUSE_STEP = 3'h4
279
- } dbg_cause_e;
280
- // PMP constants
281
- parameter int unsigned PMP_MAX_REGIONS = 16;
282
- parameter int unsigned PMP_CFG_W = 8;
283
- // PMP acces type
284
- parameter int unsigned PMP_I = 0;
285
- parameter int unsigned PMP_I2 = 1;
286
- parameter int unsigned PMP_D = 2;
287
- typedef enum logic [1:0] {
288
- PMP_ACC_EXEC = 2'b00,
289
- PMP_ACC_WRITE = 2'b01,
290
- PMP_ACC_READ = 2'b10
291
- } pmp_req_e;
292
- // PMP cfg structures
293
- typedef enum logic [1:0] {
294
- PMP_MODE_OFF = 2'b00,
295
- PMP_MODE_TOR = 2'b01,
296
- PMP_MODE_NA4 = 2'b10,
297
- PMP_MODE_NAPOT = 2'b11
298
- } pmp_cfg_mode_e;
299
- typedef struct packed {
300
- logic lock;
301
- pmp_cfg_mode_e mode;
302
- logic exec;
303
- logic write;
304
- logic read;
305
- } pmp_cfg_t;
306
- // Machine Security Configuration (ePMP)
307
- typedef struct packed {
308
- logic rlb; // Rule Locking Bypass
309
- logic mmwp; // Machine Mode Whitelist Policy
310
- logic mml; // Machine Mode Lockdown
311
- } pmp_mseccfg_t;
312
- // CSRs
313
- typedef enum logic[11:0] {
314
- // Machine information
315
- CSR_MVENDORID = 12'hF11,
316
- CSR_MARCHID = 12'hF12,
317
- CSR_MIMPID = 12'hF13,
318
- CSR_MHARTID = 12'hF14,
319
- CSR_MCONFIGPTR = 12'hF15,
320
- // Machine trap setup
321
- CSR_MSTATUS = 12'h300,
322
- CSR_MISA = 12'h301,
323
- CSR_MIE = 12'h304,
324
- CSR_MTVEC = 12'h305,
325
- CSR_MCOUNTEREN= 12'h306,
326
- CSR_MSTATUSH = 12'h310,
327
- CSR_MENVCFG = 12'h30A,
328
- CSR_MENVCFGH = 12'h31A,
329
- // Machine trap handling
330
- CSR_MSCRATCH = 12'h340,
331
- CSR_MEPC = 12'h341,
332
- CSR_MCAUSE = 12'h342,
333
- CSR_MTVAL = 12'h343,
334
- CSR_MIP = 12'h344,
335
- // Physical memory protection
336
- CSR_PMPCFG0 = 12'h3A0,
337
- CSR_PMPCFG1 = 12'h3A1,
338
- CSR_PMPCFG2 = 12'h3A2,
339
- CSR_PMPCFG3 = 12'h3A3,
340
- CSR_PMPADDR0 = 12'h3B0,
341
- CSR_PMPADDR1 = 12'h3B1,
342
- CSR_PMPADDR2 = 12'h3B2,
343
- CSR_PMPADDR3 = 12'h3B3,
344
- CSR_PMPADDR4 = 12'h3B4,
345
- CSR_PMPADDR5 = 12'h3B5,
346
- CSR_PMPADDR6 = 12'h3B6,
347
- CSR_PMPADDR7 = 12'h3B7,
348
- CSR_PMPADDR8 = 12'h3B8,
349
- CSR_PMPADDR9 = 12'h3B9,
350
- CSR_PMPADDR10 = 12'h3BA,
351
- CSR_PMPADDR11 = 12'h3BB,
352
- CSR_PMPADDR12 = 12'h3BC,
353
- CSR_PMPADDR13 = 12'h3BD,
354
- CSR_PMPADDR14 = 12'h3BE,
355
- CSR_PMPADDR15 = 12'h3BF,
356
- // ePMP control
357
- CSR_MSECCFG = 12'h747,
358
- CSR_MSECCFGH = 12'h757,
359
- // Debug trigger
360
- CSR_TSELECT = 12'h7A0,
361
- CSR_TDATA1 = 12'h7A1,
362
- CSR_TDATA2 = 12'h7A2,
363
- CSR_TDATA3 = 12'h7A3,
364
- CSR_MCONTEXT = 12'h7A8,
365
- CSR_SCONTEXT = 12'h7AA,
366
- // Debug/trace
367
- CSR_DCSR = 12'h7b0,
368
- CSR_DPC = 12'h7b1,
369
- // Debug
370
- CSR_DSCRATCH0 = 12'h7b2, // optional
371
- CSR_DSCRATCH1 = 12'h7b3, // optional
372
- // Machine Counter/Timers
373
- CSR_MCOUNTINHIBIT = 12'h320,
374
- CSR_MHPMEVENT3 = 12'h323,
375
- CSR_MHPMEVENT4 = 12'h324,
376
- CSR_MHPMEVENT5 = 12'h325,
377
- CSR_MHPMEVENT6 = 12'h326,
378
- CSR_MHPMEVENT7 = 12'h327,
379
- CSR_MHPMEVENT8 = 12'h328,
380
- CSR_MHPMEVENT9 = 12'h329,
381
- CSR_MHPMEVENT10 = 12'h32A,
382
- CSR_MHPMEVENT11 = 12'h32B,
383
- CSR_MHPMEVENT12 = 12'h32C,
384
- CSR_MHPMEVENT13 = 12'h32D,
385
- CSR_MHPMEVENT14 = 12'h32E,
386
- CSR_MHPMEVENT15 = 12'h32F,
387
- CSR_MHPMEVENT16 = 12'h330,
388
- CSR_MHPMEVENT17 = 12'h331,
389
- CSR_MHPMEVENT18 = 12'h332,
390
- CSR_MHPMEVENT19 = 12'h333,
391
- CSR_MHPMEVENT20 = 12'h334,
392
- CSR_MHPMEVENT21 = 12'h335,
393
- CSR_MHPMEVENT22 = 12'h336,
394
- CSR_MHPMEVENT23 = 12'h337,
395
- CSR_MHPMEVENT24 = 12'h338,
396
- CSR_MHPMEVENT25 = 12'h339,
397
- CSR_MHPMEVENT26 = 12'h33A,
398
- CSR_MHPMEVENT27 = 12'h33B,
399
- CSR_MHPMEVENT28 = 12'h33C,
400
- CSR_MHPMEVENT29 = 12'h33D,
401
- CSR_MHPMEVENT30 = 12'h33E,
402
- CSR_MHPMEVENT31 = 12'h33F,
403
- CSR_MCYCLE = 12'hB00,
404
- CSR_MINSTRET = 12'hB02,
405
- CSR_MHPMCOUNTER3 = 12'hB03,
406
- CSR_MHPMCOUNTER4 = 12'hB04,
407
- CSR_MHPMCOUNTER5 = 12'hB05,
408
- CSR_MHPMCOUNTER6 = 12'hB06,
409
- CSR_MHPMCOUNTER7 = 12'hB07,
410
- CSR_MHPMCOUNTER8 = 12'hB08,
411
- CSR_MHPMCOUNTER9 = 12'hB09,
412
- CSR_MHPMCOUNTER10 = 12'hB0A,
413
- CSR_MHPMCOUNTER11 = 12'hB0B,
414
- CSR_MHPMCOUNTER12 = 12'hB0C,
415
- CSR_MHPMCOUNTER13 = 12'hB0D,
416
- CSR_MHPMCOUNTER14 = 12'hB0E,
417
- CSR_MHPMCOUNTER15 = 12'hB0F,
418
- CSR_MHPMCOUNTER16 = 12'hB10,
419
- CSR_MHPMCOUNTER17 = 12'hB11,
420
- CSR_MHPMCOUNTER18 = 12'hB12,
421
- CSR_MHPMCOUNTER19 = 12'hB13,
422
- CSR_MHPMCOUNTER20 = 12'hB14,
423
- CSR_MHPMCOUNTER21 = 12'hB15,
424
- CSR_MHPMCOUNTER22 = 12'hB16,
425
- CSR_MHPMCOUNTER23 = 12'hB17,
426
- CSR_MHPMCOUNTER24 = 12'hB18,
427
- CSR_MHPMCOUNTER25 = 12'hB19,
428
- CSR_MHPMCOUNTER26 = 12'hB1A,
429
- CSR_MHPMCOUNTER27 = 12'hB1B,
430
- CSR_MHPMCOUNTER28 = 12'hB1C,
431
- CSR_MHPMCOUNTER29 = 12'hB1D,
432
- CSR_MHPMCOUNTER30 = 12'hB1E,
433
- CSR_MHPMCOUNTER31 = 12'hB1F,
434
- CSR_MCYCLEH = 12'hB80,
435
- CSR_MINSTRETH = 12'hB82,
436
- CSR_MHPMCOUNTER3H = 12'hB83,
437
- CSR_MHPMCOUNTER4H = 12'hB84,
438
- CSR_MHPMCOUNTER5H = 12'hB85,
439
- CSR_MHPMCOUNTER6H = 12'hB86,
440
- CSR_MHPMCOUNTER7H = 12'hB87,
441
- CSR_MHPMCOUNTER8H = 12'hB88,
442
- CSR_MHPMCOUNTER9H = 12'hB89,
443
- CSR_MHPMCOUNTER10H = 12'hB8A,
444
- CSR_MHPMCOUNTER11H = 12'hB8B,
445
- CSR_MHPMCOUNTER12H = 12'hB8C,
446
- CSR_MHPMCOUNTER13H = 12'hB8D,
447
- CSR_MHPMCOUNTER14H = 12'hB8E,
448
- CSR_MHPMCOUNTER15H = 12'hB8F,
449
- CSR_MHPMCOUNTER16H = 12'hB90,
450
- CSR_MHPMCOUNTER17H = 12'hB91,
451
- CSR_MHPMCOUNTER18H = 12'hB92,
452
- CSR_MHPMCOUNTER19H = 12'hB93,
453
- CSR_MHPMCOUNTER20H = 12'hB94,
454
- CSR_MHPMCOUNTER21H = 12'hB95,
455
- CSR_MHPMCOUNTER22H = 12'hB96,
456
- CSR_MHPMCOUNTER23H = 12'hB97,
457
- CSR_MHPMCOUNTER24H = 12'hB98,
458
- CSR_MHPMCOUNTER25H = 12'hB99,
459
- CSR_MHPMCOUNTER26H = 12'hB9A,
460
- CSR_MHPMCOUNTER27H = 12'hB9B,
461
- CSR_MHPMCOUNTER28H = 12'hB9C,
462
- CSR_MHPMCOUNTER29H = 12'hB9D,
463
- CSR_MHPMCOUNTER30H = 12'hB9E,
464
- CSR_MHPMCOUNTER31H = 12'hB9F,
465
- CSR_CPUCTRL = 12'h7C0,
466
- CSR_SECURESEED = 12'h7C1
467
- } csr_num_e;
468
- // CSR pmp-related offsets
469
- parameter logic [11:0] CSR_OFF_PMP_CFG = 12'h3A0; // pmp_cfg @ 12'h3a0 - 12'h3a3
470
- parameter logic [11:0] CSR_OFF_PMP_ADDR = 12'h3B0; // pmp_addr @ 12'h3b0 - 12'h3bf
471
- // CSR status bits
472
- parameter int unsigned CSR_MSTATUS_MIE_BIT = 3;
473
- parameter int unsigned CSR_MSTATUS_MPIE_BIT = 7;
474
- parameter int unsigned CSR_MSTATUS_MPP_BIT_LOW = 11;
475
- parameter int unsigned CSR_MSTATUS_MPP_BIT_HIGH = 12;
476
- parameter int unsigned CSR_MSTATUS_MPRV_BIT = 17;
477
- parameter int unsigned CSR_MSTATUS_TW_BIT = 21;
478
- // CSR machine ISA
479
- parameter logic [1:0] CSR_MISA_MXL = 2'd1; // M-XLEN: XLEN in M-Mode for RV32
480
- // CSR interrupt pending/enable bits
481
- parameter int unsigned CSR_MSIX_BIT = 3;
482
- parameter int unsigned CSR_MTIX_BIT = 7;
483
- parameter int unsigned CSR_MEIX_BIT = 11;
484
- parameter int unsigned CSR_MFIX_BIT_LOW = 16;
485
- parameter int unsigned CSR_MFIX_BIT_HIGH = 31;
486
- // CSR Machine Security Configuration bits
487
- parameter int unsigned CSR_MSECCFG_MML_BIT = 0;
488
- parameter int unsigned CSR_MSECCFG_MMWP_BIT = 1;
489
- parameter int unsigned CSR_MSECCFG_RLB_BIT = 2;
490
- // Machine Vendor ID - OpenHW JEDEC ID is '2 decimal (bank 13)'
491
- parameter MVENDORID_OFFSET = 7'h2; // Final byte without parity bit
492
- parameter MVENDORID_BANK = 25'hC; // Number of continuation codes
493
- // Machine Architecture ID (https://github.com/riscv/riscv-isa-manual/blob/master/marchid.md)
494
- parameter MARCHID = 32'd35;
495
- localparam logic [31:0] CSR_MVENDORID_VALUE = {MVENDORID_BANK, MVENDORID_OFFSET};
496
- localparam logic [31:0] CSR_MARCHID_VALUE = MARCHID;
497
- // Implementation ID
498
- // 0 indicates this field is not implemeted. cve2 implementors may wish to indicate an RTL/netlist
499
- // version here using their own unique encoding (e.g. 32 bits of the git hash of the implemented
500
- // commit).
501
- localparam logic [31:0] CSR_MIMPID_VALUE = 32'b0;
502
- // Machine Configuration Pointer
503
- // 0 indicates the configuration data structure does not eixst. cve2 implementors may wish to
504
- // alter this to point to their system specific configuration data structure.
505
- localparam logic [31:0] CSR_MCONFIGPTR_VALUE = 32'b0;
506
- // RVFI CSR element
507
- typedef struct packed {
508
- bit [63:0] rdata;
509
- bit [63:0] rmask;
510
- bit [63:0] wdata;
511
- bit [63:0] wmask;
512
- } rvfi_csr_elmt_t;
513
- // RVFI CSR structure
514
- typedef struct packed {
515
- rvfi_csr_elmt_t fflags;
516
- rvfi_csr_elmt_t frm;
517
- rvfi_csr_elmt_t fcsr;
518
- rvfi_csr_elmt_t ftran;
519
- rvfi_csr_elmt_t dcsr;
520
- rvfi_csr_elmt_t dpc;
521
- rvfi_csr_elmt_t dscratch0;
522
- rvfi_csr_elmt_t dscratch1;
523
- rvfi_csr_elmt_t sstatus;
524
- rvfi_csr_elmt_t sie;
525
- rvfi_csr_elmt_t sip;
526
- rvfi_csr_elmt_t stvec;
527
- rvfi_csr_elmt_t scounteren;
528
- rvfi_csr_elmt_t sscratch;
529
- rvfi_csr_elmt_t sepc;
530
- rvfi_csr_elmt_t scause;
531
- rvfi_csr_elmt_t stval;
532
- rvfi_csr_elmt_t satp;
533
- rvfi_csr_elmt_t mstatus;
534
- rvfi_csr_elmt_t mstatush;
535
- rvfi_csr_elmt_t misa;
536
- rvfi_csr_elmt_t medeleg;
537
- rvfi_csr_elmt_t mideleg;
538
- rvfi_csr_elmt_t mie;
539
- rvfi_csr_elmt_t mtvec;
540
- rvfi_csr_elmt_t mcounteren;
541
- rvfi_csr_elmt_t mscratch;
542
- rvfi_csr_elmt_t mepc;
543
- rvfi_csr_elmt_t mcause;
544
- rvfi_csr_elmt_t mtval;
545
- rvfi_csr_elmt_t mip;
546
- rvfi_csr_elmt_t menvcfg;
547
- rvfi_csr_elmt_t menvcfgh;
548
- rvfi_csr_elmt_t mvendorid;
549
- rvfi_csr_elmt_t marchid;
550
- rvfi_csr_elmt_t mhartid;
551
- rvfi_csr_elmt_t mcountinhibit;
552
- rvfi_csr_elmt_t mcycle;
553
- rvfi_csr_elmt_t mcycleh;
554
- rvfi_csr_elmt_t minstret;
555
- rvfi_csr_elmt_t minstreth;
556
- rvfi_csr_elmt_t cycle;
557
- rvfi_csr_elmt_t cycleh;
558
- rvfi_csr_elmt_t instret;
559
- rvfi_csr_elmt_t instreth;
560
- rvfi_csr_elmt_t dcache;
561
- rvfi_csr_elmt_t icache;
562
- rvfi_csr_elmt_t acc_cons;
563
- rvfi_csr_elmt_t pmpcfg0;
564
- rvfi_csr_elmt_t pmpcfg1;
565
- rvfi_csr_elmt_t pmpcfg2;
566
- rvfi_csr_elmt_t pmpcfg3;
567
- rvfi_csr_elmt_t pmpaddr0;
568
- rvfi_csr_elmt_t pmpaddr1;
569
- rvfi_csr_elmt_t pmpaddr2;
570
- rvfi_csr_elmt_t pmpaddr3;
571
- rvfi_csr_elmt_t pmpaddr4;
572
- rvfi_csr_elmt_t pmpaddr5;
573
- rvfi_csr_elmt_t pmpaddr6;
574
- rvfi_csr_elmt_t pmpaddr7;
575
- rvfi_csr_elmt_t pmpaddr8;
576
- rvfi_csr_elmt_t pmpaddr9;
577
- rvfi_csr_elmt_t pmpaddr10;
578
- rvfi_csr_elmt_t pmpaddr11;
579
- rvfi_csr_elmt_t pmpaddr12;
580
- rvfi_csr_elmt_t pmpaddr13;
581
- rvfi_csr_elmt_t pmpaddr14;
582
- rvfi_csr_elmt_t pmpaddr15;
583
- } rvfi_csr_t;
584
- // CV-X-IF
585
- parameter int unsigned X_NUM_RS = 3;
586
- parameter int unsigned X_ID_WIDTH = 4;
587
- parameter int unsigned X_RFR_WIDTH = 32;
588
- parameter int unsigned X_RFW_WIDTH = 32;
589
- parameter int unsigned X_HARTID_WIDTH = 32;
590
- parameter int unsigned X_DUAL_READ = 0;
591
- parameter int unsigned X_DUAL_WRITE = 0;
592
- parameter int unsigned X_INSTR_INFLIGHT = 2**X_ID_WIDTH;
593
- typedef logic [X_NUM_RS+X_DUAL_READ-1:0] readregflags_t;
594
- typedef logic [X_DUAL_WRITE:0] writeregflags_t;
595
- typedef logic [X_ID_WIDTH-1:0] id_t;
596
- typedef logic [X_HARTID_WIDTH-1:0] hartid_t;
597
- // Issue Interface
598
- typedef struct packed {
599
- logic [31:0] instr;
600
- hartid_t hartid;
601
- id_t id;
602
- } x_issue_req_t;
603
- typedef struct packed {
604
- logic accept;
605
- writeregflags_t writeback;
606
- readregflags_t register_read;
607
- } x_issue_resp_t;
608
- // Register Interface
609
- typedef struct packed {
610
- hartid_t hartid;
611
- id_t id;
612
- logic [X_NUM_RS-1:0][X_RFR_WIDTH-1:0] rs;
613
- readregflags_t rs_valid;
614
- } x_register_t;
615
- // Commit Interface
616
- typedef struct packed {
617
- hartid_t hartid;
618
- id_t id;
619
- logic commit_kill;
620
- } x_commit_t;
621
- // Result Interface
622
- typedef struct packed {
623
- hartid_t hartid;
624
- id_t id;
625
- logic [X_RFW_WIDTH-1:0] data;
626
- logic [4:0] rd;
627
- writeregflags_t we;
628
- } x_result_t;
629
- endpackage
630
- // Copyright (c) 2025 Eclipse Foundation
631
- // Copyright lowRISC contributors.
632
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
633
- // SPDX-License-Identifier: Apache-2.0
634
- /**
635
- * Branch Predictor
636
- *
637
- * This implements static branch prediction. It takes an instruction and its PC and determines if
638
- * it's a branch or a jump and calculates its target. For jumps it will always predict taken. For
639
- * branches it will predict taken if the PC offset is negative.
640
- *
641
- * This handles both compressed and uncompressed instructions. Compressed instructions must be in
642
- * the lower 16-bits of instr.
643
- *
644
- * The predictor is entirely combinational but takes clk/rst_n signals for use by assertions.
645
- */
646
- // Copyright lowRISC contributors.
647
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
648
- // SPDX-License-Identifier: Apache-2.0
649
- // Macros and helper code for using assertions.
650
- // - Provides default clk and rst options to simplify code
651
- // - Provides boiler plate template for common assertions
652
- ///////////////////
653
- // Helper macros //
654
- ///////////////////
655
- // Default clk and reset signals used by assertion macros below.
656
- // Converts an arbitrary block of code into a Verilog string
657
- // ASSERT_ERROR logs an error message with either `uvm_error or with $error.
658
- //
659
- // This somewhat duplicates `DV_ERROR macro defined in hw/dv/sv/dv_utils/dv_macros.svh. The reason
660
- // for redefining it here is to avoid creating a dependency.
661
- // This macro is suitable for conditionally triggering lint errors, e.g., if a Sec parameter takes
662
- // on a non-default value. This may be required for pre-silicon/FPGA evaluation but we don't want
663
- // to allow this for tapeout.
664
- // The basic helper macros are actually defined in "implementation headers". The macros should do
665
- // the same thing in each case (except for the dummy flavour), but in a way that the respective
666
- // tools support.
667
- //
668
- // If the tool supports assertions in some form, we also define INC_ASSERT (which can be used to
669
- // hide signal definitions that are only used for assertions).
670
- //
671
- // The list of basic macros supported is:
672
- //
673
- // ASSERT_I: Immediate assertion. Note that immediate assertions are sensitive to simulation
674
- // glitches.
675
- //
676
- // ASSERT_INIT: Assertion in initial block. Can be used for things like parameter checking.
677
- //
678
- // ASSERT_INIT_NET: Assertion in initial block. Can be used for initial value of a net.
679
- //
680
- // ASSERT_FINAL: Assertion in final block. Can be used for things like queues being empty at end of
681
- // sim, all credits returned at end of sim, state machines in idle at end of sim.
682
- //
683
- // ASSERT: Assert a concurrent property directly. It can be called as a module (or
684
- // interface) body item.
685
- //
686
- // Note: We use (__rst !== '0) in the disable iff statements instead of (__rst ==
687
- // '1). This properly disables the assertion in cases when reset is X at the
688
- // beginning of a simulation. For that case, (reset == '1) does not disable the
689
- // assertion.
690
- //
691
- // ASSERT_NEVER: Assert a concurrent property NEVER happens
692
- //
693
- // ASSERT_KNOWN: Assert that signal has a known value (each bit is either '0' or '1') after reset.
694
- // It can be called as a module (or interface) body item.
695
- //
696
- // COVER: Cover a concurrent property
697
- //
698
- // ASSUME: Assume a concurrent property
699
- //
700
- // ASSUME_I: Assume an immediate property
701
- // Copyright lowRISC contributors.
702
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
703
- // SPDX-License-Identifier: Apache-2.0
704
- // Macro bodies included by prim_assert.sv for tools that don't support assertions. See
705
- // prim_assert.sv for documentation for each of the macros.
706
- //////////////////////////////
707
- // Complex assertion macros //
708
- //////////////////////////////
709
- // Assert that signal is an active-high pulse with pulse length of 1 clock cycle
710
- // Assert that a property is true only when an enable signal is set. It can be called as a module
711
- // (or interface) body item.
712
- // Assert that signal has a known value (each bit is either '0' or '1') after reset if enable is
713
- // set. It can be called as a module (or interface) body item.
714
- //////////////////////////////////
715
- // For formal verification only //
716
- //////////////////////////////////
717
- // Note that the existing set of ASSERT macros specified above shall be used for FPV,
718
- // thereby ensuring that the assertions are evaluated during DV simulations as well.
719
- // ASSUME_FPV
720
- // Assume a concurrent property during formal verification only.
721
- // ASSUME_I_FPV
722
- // Assume a concurrent property during formal verification only.
723
- // COVER_FPV
724
- // Cover a concurrent property during formal verification
725
- // Copyright lowRISC contributors.
726
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
727
- // SPDX-License-Identifier: Apache-2.0
728
- // // Macros and helper code for security countermeasures.
729
- // Helper macros
730
- // macros for security countermeasures
731
- // PRIM_ASSERT_SEC_CM_SVH
732
- // PRIM_ASSERT_SV
733
- module cve2_branch_predict (
734
- input logic clk_i,
735
- input logic rst_ni,
736
- // Instruction from fetch stage
737
- input logic [31:0] fetch_rdata_i,
738
- input logic [31:0] fetch_pc_i,
739
- input logic fetch_valid_i,
740
- // Prediction for supplied instruction
741
- output logic predict_branch_taken_o,
742
- output logic [31:0] predict_branch_pc_o
743
- );
744
- import cve2_pkg::*;
745
- logic [31:0] imm_j_type;
746
- logic [31:0] imm_b_type;
747
- logic [31:0] imm_cj_type;
748
- logic [31:0] imm_cb_type;
749
- logic [31:0] branch_imm;
750
- logic [31:0] instr;
751
- logic instr_j;
752
- logic instr_b;
753
- logic instr_cj;
754
- logic instr_cb;
755
- logic instr_b_taken;
756
- // Provide short internal name for fetch_rdata_i due to reduce line wrapping
757
- assign instr = fetch_rdata_i;
758
- // Extract and sign-extend to 32-bit the various immediates that may be used to calculate the
759
- // target
760
- // Uncompressed immediates
761
- assign imm_j_type = { {12{instr[31]}}, instr[19:12], instr[20], instr[30:21], 1'b0 };
762
- assign imm_b_type = { {19{instr[31]}}, instr[31], instr[7], instr[30:25], instr[11:8], 1'b0 };
763
- // Compressed immediates
764
- assign imm_cj_type = { {20{instr[12]}}, instr[12], instr[8], instr[10:9], instr[6], instr[7],
765
- instr[2], instr[11], instr[5:3], 1'b0 };
766
- assign imm_cb_type = { {23{instr[12]}}, instr[12], instr[6:5], instr[2], instr[11:10],
767
- instr[4:3], 1'b0};
768
- // Determine if the instruction is a branch or a jump
769
- // Uncompressed branch/jump
770
- assign instr_b = opcode_e'(instr[6:0]) == OPCODE_BRANCH;
771
- assign instr_j = opcode_e'(instr[6:0]) == OPCODE_JAL;
772
- // Compressed branch/jump
773
- assign instr_cb = (instr[1:0] == 2'b01) & ((instr[15:13] == 3'b110) | (instr[15:13] == 3'b111));
774
- assign instr_cj = (instr[1:0] == 2'b01) & ((instr[15:13] == 3'b101) | (instr[15:13] == 3'b001));
775
- // Select out the branch offset for target calculation based upon the instruction type
776
- always_comb begin
777
- branch_imm = imm_b_type;
778
- unique case (1'b1)
779
- instr_j : branch_imm = imm_j_type;
780
- instr_b : branch_imm = imm_b_type;
781
- instr_cj : branch_imm = imm_cj_type;
782
- instr_cb : branch_imm = imm_cb_type;
783
- default : ;
784
- endcase
785
- end
786
- // Determine branch prediction, taken if offset is negative
787
- assign instr_b_taken = (instr_b & imm_b_type[31]) | (instr_cb & imm_cb_type[31]);
788
- // Always predict jumps taken otherwise take prediction from `instr_b_taken`
789
- assign predict_branch_taken_o = fetch_valid_i & (instr_j | instr_cj | instr_b_taken);
790
- // Calculate target
791
- assign predict_branch_pc_o = fetch_pc_i + branch_imm;
792
- endmodule
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p2/mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"blocking_assignment": [[25333, 25358], [25290, 25315], [25206, 25230], [25248, 25272], [25141, 25165]], "always_construct": [[25119, 25394]], "case_statement": [[25170, 25388]], "ansi_port_declaration": [[23525, 23568], [23297, 23316], [23447, 23481], [23319, 23339], [23413, 23444], [23571, 23610], [23376, 23410]], "continuous_assign": [[25732, 25788], [23969, 23998], [24138, 24223], [24748, 24801], [24689, 24745], [24226, 24320], [24350, 24488], [24491, 24600]], "parameter_declaration": [[13551, 13619], [16946, 16990], [16898, 16943], [16993, 17037], [16850, 16895], [16755, 16799], [13622, 13688], [16802, 16847]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p3/all_mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"module_program_interface_instantiation": [], "continuous_assign": [[23478, 23508], [32421, 32470]], "blocking_assignment": [[23681, 23707], [23712, 23735], [23970, 24125], [24166, 24189], [24281, 24433], [24526, 24715], [24838, 24861], [24913, 24936], [25401, 25534], [25675, 25888], [26042, 26166], [26313, 26387], [26498, 26648], [26718, 26741], [27067, 27211], [27254, 27277], [27385, 27536], [27743, 27882], [28008, 28140], [28266, 28398], [28524, 28656], [28879, 28902], [28978, 29001], [29111, 29134], [29323, 29532], [29584, 29607], [30113, 30199], [30238, 30295], [30386, 30517], [30558, 30581], [30836, 30907], [30999, 31059], [31103, 31126], [31343, 31423], [31560, 31588], [31685, 31751], [31897, 32031], [32136, 32159], [32211, 32234], [32367, 32390]], "nonblocking_assignment": [], "case_statement": [[23792, 32412], [23858, 24966], [25271, 29637], [26792, 29172], [27598, 29047], [29942, 32264]], "conditional_statement": [[24138, 24189], [26400, 26664], [26677, 26741], [27228, 27277], [30212, 30295], [30530, 30581], [30632, 31805], [30677, 31144], [31076, 31126], [31186, 31789], [31469, 31771]], "always_construct": [[23592, 32418]], "parameter_declaration": [[6471, 6520], [6523, 6571], [6594, 6628], [6631, 6665], [6668, 6702], [12379, 12461], [12464, 12546], [12570, 12622], [12625, 12677], [12680, 12733], [12736, 12789], [12792, 12845], [12848, 12901], [12925, 13002], [13044, 13089], [13092, 13137], [13140, 13186], [13189, 13235], [13238, 13284], [13332, 13380], [13383, 13431], [13434, 13482], [13551, 13619], [13622, 13688], [13787, 13814], [16708, 16752], [16755, 16799], [16802, 16847], [16850, 16895], [16898, 16943], [16946, 16990], [16993, 17037], [17040, 17096]], "ansi_port_declaration": [[23061, 23087], [23090, 23117], [23120, 23148], [23151, 23179], [23182, 23210], [23213, 23249], [23252, 23287]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p3/cve2_compressed_decoder.sv DELETED
@@ -1,964 +0,0 @@
1
- // Copyright (c) 2025 Eclipse Foundation
2
- // Copyright lowRISC contributors.
3
- // Copyright 2017 ETH Zurich and University of Bologna, see also CREDITS.md.
4
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
5
- // SPDX-License-Identifier: Apache-2.0
6
- /**
7
- * Package with constants used by CVE2
8
- */
9
- package cve2_pkg;
10
- ////////////////
11
- // IO Structs //
12
- ////////////////
13
- typedef struct packed {
14
- logic [31:0] current_pc;
15
- logic [31:0] next_pc;
16
- logic [31:0] last_data_addr;
17
- logic [31:0] exception_addr;
18
- } crash_dump_t;
19
- typedef struct packed {
20
- logic dummy_instr_id;
21
- logic [4:0] raddr_a;
22
- logic [4:0] waddr_a;
23
- logic we_a;
24
- logic [4:0] raddr_b;
25
- } core2rf_t;
26
- /////////////////////
27
- // Parameter Enums //
28
- /////////////////////
29
- typedef enum integer {
30
- RV32MNone = 0,
31
- RV32MSlow = 1,
32
- RV32MFast = 2,
33
- RV32MSingleCycle = 3
34
- } rv32m_e;
35
- typedef enum integer {
36
- RV32BNone = 0,
37
- RV32BBalanced = 1,
38
- RV32BOTEarlGrey = 2,
39
- RV32BFull = 3
40
- } rv32b_e;
41
- /////////////
42
- // Opcodes //
43
- /////////////
44
- typedef enum logic [6:0] {
45
- OPCODE_LOAD = 7'h03,
46
- OPCODE_MISC_MEM = 7'h0f,
47
- OPCODE_OP_IMM = 7'h13,
48
- OPCODE_AUIPC = 7'h17,
49
- OPCODE_STORE = 7'h23,
50
- OPCODE_OP = 7'h33,
51
- OPCODE_LUI = 7'h37,
52
- OPCODE_BRANCH = 7'h63,
53
- OPCODE_JALR = 7'h67,
54
- OPCODE_JAL = 7'h6f,
55
- OPCODE_SYSTEM = 7'h73
56
- } opcode_e;
57
- ////////////////////
58
- // ALU operations //
59
- ////////////////////
60
- typedef enum logic [6:0] {
61
- // Arithmetics
62
- ALU_ADD,
63
- ALU_SUB,
64
- // Logics
65
- ALU_XOR,
66
- ALU_OR,
67
- ALU_AND,
68
- // RV32B
69
- ALU_XNOR,
70
- ALU_ORN,
71
- ALU_ANDN,
72
- // Shifts
73
- ALU_SRA,
74
- ALU_SRL,
75
- ALU_SLL,
76
- // RV32B
77
- ALU_SRO,
78
- ALU_SLO,
79
- ALU_ROR,
80
- ALU_ROL,
81
- ALU_GREV,
82
- ALU_GORC,
83
- ALU_SHFL,
84
- ALU_UNSHFL,
85
- ALU_XPERM_N,
86
- ALU_XPERM_B,
87
- ALU_XPERM_H,
88
- // Address Calculations
89
- // RV32B
90
- ALU_SH1ADD,
91
- ALU_SH2ADD,
92
- ALU_SH3ADD,
93
- // Comparisons
94
- ALU_LT,
95
- ALU_LTU,
96
- ALU_GE,
97
- ALU_GEU,
98
- ALU_EQ,
99
- ALU_NE,
100
- // RV32B
101
- ALU_MIN,
102
- ALU_MINU,
103
- ALU_MAX,
104
- ALU_MAXU,
105
- // Pack
106
- // RV32B
107
- ALU_PACK,
108
- ALU_PACKU,
109
- ALU_PACKH,
110
- // Sign-Extend
111
- // RV32B
112
- ALU_SEXTB,
113
- ALU_SEXTH,
114
- // Bitcounting
115
- // RV32B
116
- ALU_CLZ,
117
- ALU_CTZ,
118
- ALU_CPOP,
119
- // Set lower than
120
- ALU_SLT,
121
- ALU_SLTU,
122
- // Ternary Bitmanip Operations
123
- // RV32B
124
- ALU_CMOV,
125
- ALU_CMIX,
126
- ALU_FSL,
127
- ALU_FSR,
128
- // Single-Bit Operations
129
- // RV32B
130
- ALU_BSET,
131
- ALU_BCLR,
132
- ALU_BINV,
133
- ALU_BEXT,
134
- // Bit Compress / Decompress
135
- // RV32B
136
- ALU_BCOMPRESS,
137
- ALU_BDECOMPRESS,
138
- // Bit Field Place
139
- // RV32B
140
- ALU_BFP,
141
- // Carry-less Multiply
142
- // RV32B
143
- ALU_CLMUL,
144
- ALU_CLMULR,
145
- ALU_CLMULH,
146
- // Cyclic Redundancy Check
147
- ALU_CRC32_B,
148
- ALU_CRC32C_B,
149
- ALU_CRC32_H,
150
- ALU_CRC32C_H,
151
- ALU_CRC32_W,
152
- ALU_CRC32C_W
153
- } alu_op_e;
154
- typedef enum logic [1:0] {
155
- // Multiplier/divider
156
- MD_OP_MULL,
157
- MD_OP_MULH,
158
- MD_OP_DIV,
159
- MD_OP_REM
160
- } md_op_e;
161
- //////////////////////////////////
162
- // Control and status registers //
163
- //////////////////////////////////
164
- // CSR operations
165
- typedef enum logic [1:0] {
166
- CSR_OP_READ,
167
- CSR_OP_WRITE,
168
- CSR_OP_SET,
169
- CSR_OP_CLEAR
170
- } csr_op_e;
171
- // Privileged mode
172
- typedef enum logic[1:0] {
173
- PRIV_LVL_M = 2'b11,
174
- PRIV_LVL_H = 2'b10,
175
- PRIV_LVL_S = 2'b01,
176
- PRIV_LVL_U = 2'b00
177
- } priv_lvl_e;
178
- // Constants for the dcsr.xdebugver fields
179
- typedef enum logic[3:0] {
180
- XDEBUGVER_NO = 4'd0, // no external debug support
181
- XDEBUGVER_STD = 4'd4, // external debug according to RISC-V debug spec
182
- XDEBUGVER_NONSTD = 4'd15 // debug not conforming to RISC-V debug spec
183
- } x_debug_ver_e;
184
- //////////////
185
- // WB stage //
186
- //////////////
187
- // Type of instruction present in writeback stage
188
- typedef enum logic[1:0] {
189
- WB_INSTR_LOAD, // Instruction is awaiting load data
190
- WB_INSTR_STORE, // Instruction is awaiting store response
191
- WB_INSTR_OTHER // Instruction doesn't fit into above categories
192
- } wb_instr_type_e;
193
- //////////////
194
- // ID stage //
195
- //////////////
196
- // Operand a selection
197
- typedef enum logic[1:0] {
198
- OP_A_REG_A,
199
- OP_A_FWD,
200
- OP_A_CURRPC,
201
- OP_A_IMM
202
- } op_a_sel_e;
203
- // Immediate a selection
204
- typedef enum logic {
205
- IMM_A_Z,
206
- IMM_A_ZERO
207
- } imm_a_sel_e;
208
- // Operand b selection
209
- typedef enum logic {
210
- OP_B_REG_B,
211
- OP_B_IMM
212
- } op_b_sel_e;
213
- // Immediate b selection
214
- typedef enum logic [2:0] {
215
- IMM_B_I,
216
- IMM_B_S,
217
- IMM_B_B,
218
- IMM_B_U,
219
- IMM_B_J,
220
- IMM_B_INCR_PC,
221
- IMM_B_INCR_ADDR
222
- } imm_b_sel_e;
223
- // Regfile write data selection
224
- typedef enum {
225
- RF_WD_EX,
226
- RF_WD_CSR,
227
- RF_WD_COPROC // Only used when XInterface = 1
228
- } rf_wd_sel_e;
229
- //////////////
230
- // IF stage //
231
- //////////////
232
- // PC mux selection
233
- typedef enum logic [2:0] {
234
- PC_BOOT,
235
- PC_JUMP,
236
- PC_EXC,
237
- PC_ERET,
238
- PC_DRET,
239
- PC_BP
240
- } pc_sel_e;
241
- // Exception PC mux selection
242
- typedef enum logic [1:0] {
243
- EXC_PC_EXC,
244
- EXC_PC_IRQ,
245
- EXC_PC_DBD,
246
- EXC_PC_DBG_EXC // Exception while in debug mode
247
- } exc_pc_sel_e;
248
- // Interrupt requests
249
- typedef struct packed {
250
- logic irq_software;
251
- logic irq_timer;
252
- logic irq_external;
253
- logic [15:0] irq_fast; // 16 fast interrupts
254
- } irqs_t;
255
- // Exception cause
256
- typedef enum logic [6:0] {
257
- EXC_CAUSE_IRQ_SOFTWARE_M = {1'b1, 6'd03},
258
- EXC_CAUSE_IRQ_TIMER_M = {1'b1, 6'd07},
259
- EXC_CAUSE_IRQ_EXTERNAL_M = {1'b1, 6'd11},
260
- // EXC_CAUSE_IRQ_FAST_0 = {1'b1, 6'd16},
261
- // EXC_CAUSE_IRQ_FAST_15 = {1'b1, 6'd31},
262
- EXC_CAUSE_IRQ_NM = {1'b1, 6'd32},
263
- EXC_CAUSE_INSN_ADDR_MISA = {1'b0, 6'd00},
264
- EXC_CAUSE_INSTR_ACCESS_FAULT = {1'b0, 6'd01},
265
- EXC_CAUSE_ILLEGAL_INSN = {1'b0, 6'd02},
266
- EXC_CAUSE_BREAKPOINT = {1'b0, 6'd03},
267
- EXC_CAUSE_LOAD_ACCESS_FAULT = {1'b0, 6'd05},
268
- EXC_CAUSE_STORE_ACCESS_FAULT = {1'b0, 6'd07},
269
- EXC_CAUSE_ECALL_UMODE = {1'b0, 6'd08},
270
- EXC_CAUSE_ECALL_MMODE = {1'b0, 6'd11}
271
- } exc_cause_e;
272
- // Debug cause
273
- typedef enum logic [2:0] {
274
- DBG_CAUSE_NONE = 3'h0,
275
- DBG_CAUSE_EBREAK = 3'h1,
276
- DBG_CAUSE_TRIGGER = 3'h2,
277
- DBG_CAUSE_HALTREQ = 3'h3,
278
- DBG_CAUSE_STEP = 3'h4
279
- } dbg_cause_e;
280
- // PMP constants
281
- parameter int unsigned PMP_MAX_REGIONS = 16;
282
- parameter int unsigned PMP_CFG_W = 8;
283
- // PMP acces type
284
- parameter int unsigned PMP_I = 0;
285
- parameter int unsigned PMP_I2 = 1;
286
- parameter int unsigned PMP_D = 2;
287
- typedef enum logic [1:0] {
288
- PMP_ACC_EXEC = 2'b00,
289
- PMP_ACC_WRITE = 2'b01,
290
- PMP_ACC_READ = 2'b10
291
- } pmp_req_e;
292
- // PMP cfg structures
293
- typedef enum logic [1:0] {
294
- PMP_MODE_OFF = 2'b00,
295
- PMP_MODE_TOR = 2'b01,
296
- PMP_MODE_NA4 = 2'b10,
297
- PMP_MODE_NAPOT = 2'b11
298
- } pmp_cfg_mode_e;
299
- typedef struct packed {
300
- logic lock;
301
- pmp_cfg_mode_e mode;
302
- logic exec;
303
- logic write;
304
- logic read;
305
- } pmp_cfg_t;
306
- // Machine Security Configuration (ePMP)
307
- typedef struct packed {
308
- logic rlb; // Rule Locking Bypass
309
- logic mmwp; // Machine Mode Whitelist Policy
310
- logic mml; // Machine Mode Lockdown
311
- } pmp_mseccfg_t;
312
- // CSRs
313
- typedef enum logic[11:0] {
314
- // Machine information
315
- CSR_MVENDORID = 12'hF11,
316
- CSR_MARCHID = 12'hF12,
317
- CSR_MIMPID = 12'hF13,
318
- CSR_MHARTID = 12'hF14,
319
- CSR_MCONFIGPTR = 12'hF15,
320
- // Machine trap setup
321
- CSR_MSTATUS = 12'h300,
322
- CSR_MISA = 12'h301,
323
- CSR_MIE = 12'h304,
324
- CSR_MTVEC = 12'h305,
325
- CSR_MCOUNTEREN= 12'h306,
326
- CSR_MSTATUSH = 12'h310,
327
- CSR_MENVCFG = 12'h30A,
328
- CSR_MENVCFGH = 12'h31A,
329
- // Machine trap handling
330
- CSR_MSCRATCH = 12'h340,
331
- CSR_MEPC = 12'h341,
332
- CSR_MCAUSE = 12'h342,
333
- CSR_MTVAL = 12'h343,
334
- CSR_MIP = 12'h344,
335
- // Physical memory protection
336
- CSR_PMPCFG0 = 12'h3A0,
337
- CSR_PMPCFG1 = 12'h3A1,
338
- CSR_PMPCFG2 = 12'h3A2,
339
- CSR_PMPCFG3 = 12'h3A3,
340
- CSR_PMPADDR0 = 12'h3B0,
341
- CSR_PMPADDR1 = 12'h3B1,
342
- CSR_PMPADDR2 = 12'h3B2,
343
- CSR_PMPADDR3 = 12'h3B3,
344
- CSR_PMPADDR4 = 12'h3B4,
345
- CSR_PMPADDR5 = 12'h3B5,
346
- CSR_PMPADDR6 = 12'h3B6,
347
- CSR_PMPADDR7 = 12'h3B7,
348
- CSR_PMPADDR8 = 12'h3B8,
349
- CSR_PMPADDR9 = 12'h3B9,
350
- CSR_PMPADDR10 = 12'h3BA,
351
- CSR_PMPADDR11 = 12'h3BB,
352
- CSR_PMPADDR12 = 12'h3BC,
353
- CSR_PMPADDR13 = 12'h3BD,
354
- CSR_PMPADDR14 = 12'h3BE,
355
- CSR_PMPADDR15 = 12'h3BF,
356
- // ePMP control
357
- CSR_MSECCFG = 12'h747,
358
- CSR_MSECCFGH = 12'h757,
359
- // Debug trigger
360
- CSR_TSELECT = 12'h7A0,
361
- CSR_TDATA1 = 12'h7A1,
362
- CSR_TDATA2 = 12'h7A2,
363
- CSR_TDATA3 = 12'h7A3,
364
- CSR_MCONTEXT = 12'h7A8,
365
- CSR_SCONTEXT = 12'h7AA,
366
- // Debug/trace
367
- CSR_DCSR = 12'h7b0,
368
- CSR_DPC = 12'h7b1,
369
- // Debug
370
- CSR_DSCRATCH0 = 12'h7b2, // optional
371
- CSR_DSCRATCH1 = 12'h7b3, // optional
372
- // Machine Counter/Timers
373
- CSR_MCOUNTINHIBIT = 12'h320,
374
- CSR_MHPMEVENT3 = 12'h323,
375
- CSR_MHPMEVENT4 = 12'h324,
376
- CSR_MHPMEVENT5 = 12'h325,
377
- CSR_MHPMEVENT6 = 12'h326,
378
- CSR_MHPMEVENT7 = 12'h327,
379
- CSR_MHPMEVENT8 = 12'h328,
380
- CSR_MHPMEVENT9 = 12'h329,
381
- CSR_MHPMEVENT10 = 12'h32A,
382
- CSR_MHPMEVENT11 = 12'h32B,
383
- CSR_MHPMEVENT12 = 12'h32C,
384
- CSR_MHPMEVENT13 = 12'h32D,
385
- CSR_MHPMEVENT14 = 12'h32E,
386
- CSR_MHPMEVENT15 = 12'h32F,
387
- CSR_MHPMEVENT16 = 12'h330,
388
- CSR_MHPMEVENT17 = 12'h331,
389
- CSR_MHPMEVENT18 = 12'h332,
390
- CSR_MHPMEVENT19 = 12'h333,
391
- CSR_MHPMEVENT20 = 12'h334,
392
- CSR_MHPMEVENT21 = 12'h335,
393
- CSR_MHPMEVENT22 = 12'h336,
394
- CSR_MHPMEVENT23 = 12'h337,
395
- CSR_MHPMEVENT24 = 12'h338,
396
- CSR_MHPMEVENT25 = 12'h339,
397
- CSR_MHPMEVENT26 = 12'h33A,
398
- CSR_MHPMEVENT27 = 12'h33B,
399
- CSR_MHPMEVENT28 = 12'h33C,
400
- CSR_MHPMEVENT29 = 12'h33D,
401
- CSR_MHPMEVENT30 = 12'h33E,
402
- CSR_MHPMEVENT31 = 12'h33F,
403
- CSR_MCYCLE = 12'hB00,
404
- CSR_MINSTRET = 12'hB02,
405
- CSR_MHPMCOUNTER3 = 12'hB03,
406
- CSR_MHPMCOUNTER4 = 12'hB04,
407
- CSR_MHPMCOUNTER5 = 12'hB05,
408
- CSR_MHPMCOUNTER6 = 12'hB06,
409
- CSR_MHPMCOUNTER7 = 12'hB07,
410
- CSR_MHPMCOUNTER8 = 12'hB08,
411
- CSR_MHPMCOUNTER9 = 12'hB09,
412
- CSR_MHPMCOUNTER10 = 12'hB0A,
413
- CSR_MHPMCOUNTER11 = 12'hB0B,
414
- CSR_MHPMCOUNTER12 = 12'hB0C,
415
- CSR_MHPMCOUNTER13 = 12'hB0D,
416
- CSR_MHPMCOUNTER14 = 12'hB0E,
417
- CSR_MHPMCOUNTER15 = 12'hB0F,
418
- CSR_MHPMCOUNTER16 = 12'hB10,
419
- CSR_MHPMCOUNTER17 = 12'hB11,
420
- CSR_MHPMCOUNTER18 = 12'hB12,
421
- CSR_MHPMCOUNTER19 = 12'hB13,
422
- CSR_MHPMCOUNTER20 = 12'hB14,
423
- CSR_MHPMCOUNTER21 = 12'hB15,
424
- CSR_MHPMCOUNTER22 = 12'hB16,
425
- CSR_MHPMCOUNTER23 = 12'hB17,
426
- CSR_MHPMCOUNTER24 = 12'hB18,
427
- CSR_MHPMCOUNTER25 = 12'hB19,
428
- CSR_MHPMCOUNTER26 = 12'hB1A,
429
- CSR_MHPMCOUNTER27 = 12'hB1B,
430
- CSR_MHPMCOUNTER28 = 12'hB1C,
431
- CSR_MHPMCOUNTER29 = 12'hB1D,
432
- CSR_MHPMCOUNTER30 = 12'hB1E,
433
- CSR_MHPMCOUNTER31 = 12'hB1F,
434
- CSR_MCYCLEH = 12'hB80,
435
- CSR_MINSTRETH = 12'hB82,
436
- CSR_MHPMCOUNTER3H = 12'hB83,
437
- CSR_MHPMCOUNTER4H = 12'hB84,
438
- CSR_MHPMCOUNTER5H = 12'hB85,
439
- CSR_MHPMCOUNTER6H = 12'hB86,
440
- CSR_MHPMCOUNTER7H = 12'hB87,
441
- CSR_MHPMCOUNTER8H = 12'hB88,
442
- CSR_MHPMCOUNTER9H = 12'hB89,
443
- CSR_MHPMCOUNTER10H = 12'hB8A,
444
- CSR_MHPMCOUNTER11H = 12'hB8B,
445
- CSR_MHPMCOUNTER12H = 12'hB8C,
446
- CSR_MHPMCOUNTER13H = 12'hB8D,
447
- CSR_MHPMCOUNTER14H = 12'hB8E,
448
- CSR_MHPMCOUNTER15H = 12'hB8F,
449
- CSR_MHPMCOUNTER16H = 12'hB90,
450
- CSR_MHPMCOUNTER17H = 12'hB91,
451
- CSR_MHPMCOUNTER18H = 12'hB92,
452
- CSR_MHPMCOUNTER19H = 12'hB93,
453
- CSR_MHPMCOUNTER20H = 12'hB94,
454
- CSR_MHPMCOUNTER21H = 12'hB95,
455
- CSR_MHPMCOUNTER22H = 12'hB96,
456
- CSR_MHPMCOUNTER23H = 12'hB97,
457
- CSR_MHPMCOUNTER24H = 12'hB98,
458
- CSR_MHPMCOUNTER25H = 12'hB99,
459
- CSR_MHPMCOUNTER26H = 12'hB9A,
460
- CSR_MHPMCOUNTER27H = 12'hB9B,
461
- CSR_MHPMCOUNTER28H = 12'hB9C,
462
- CSR_MHPMCOUNTER29H = 12'hB9D,
463
- CSR_MHPMCOUNTER30H = 12'hB9E,
464
- CSR_MHPMCOUNTER31H = 12'hB9F,
465
- CSR_CPUCTRL = 12'h7C0,
466
- CSR_SECURESEED = 12'h7C1
467
- } csr_num_e;
468
- // CSR pmp-related offsets
469
- parameter logic [11:0] CSR_OFF_PMP_CFG = 12'h3A0; // pmp_cfg @ 12'h3a0 - 12'h3a3
470
- parameter logic [11:0] CSR_OFF_PMP_ADDR = 12'h3B0; // pmp_addr @ 12'h3b0 - 12'h3bf
471
- // CSR status bits
472
- parameter int unsigned CSR_MSTATUS_MIE_BIT = 3;
473
- parameter int unsigned CSR_MSTATUS_MPIE_BIT = 7;
474
- parameter int unsigned CSR_MSTATUS_MPP_BIT_LOW = 11;
475
- parameter int unsigned CSR_MSTATUS_MPP_BIT_HIGH = 12;
476
- parameter int unsigned CSR_MSTATUS_MPRV_BIT = 17;
477
- parameter int unsigned CSR_MSTATUS_TW_BIT = 21;
478
- // CSR machine ISA
479
- parameter logic [1:0] CSR_MISA_MXL = 2'd1; // M-XLEN: XLEN in M-Mode for RV32
480
- // CSR interrupt pending/enable bits
481
- parameter int unsigned CSR_MSIX_BIT = 3;
482
- parameter int unsigned CSR_MTIX_BIT = 7;
483
- parameter int unsigned CSR_MEIX_BIT = 11;
484
- parameter int unsigned CSR_MFIX_BIT_LOW = 16;
485
- parameter int unsigned CSR_MFIX_BIT_HIGH = 31;
486
- // CSR Machine Security Configuration bits
487
- parameter int unsigned CSR_MSECCFG_MML_BIT = 0;
488
- parameter int unsigned CSR_MSECCFG_MMWP_BIT = 1;
489
- parameter int unsigned CSR_MSECCFG_RLB_BIT = 2;
490
- // Machine Vendor ID - OpenHW JEDEC ID is '2 decimal (bank 13)'
491
- parameter MVENDORID_OFFSET = 7'h2; // Final byte without parity bit
492
- parameter MVENDORID_BANK = 25'hC; // Number of continuation codes
493
- // Machine Architecture ID (https://github.com/riscv/riscv-isa-manual/blob/master/marchid.md)
494
- parameter MARCHID = 32'd35;
495
- localparam logic [31:0] CSR_MVENDORID_VALUE = {MVENDORID_BANK, MVENDORID_OFFSET};
496
- localparam logic [31:0] CSR_MARCHID_VALUE = MARCHID;
497
- // Implementation ID
498
- // 0 indicates this field is not implemeted. cve2 implementors may wish to indicate an RTL/netlist
499
- // version here using their own unique encoding (e.g. 32 bits of the git hash of the implemented
500
- // commit).
501
- localparam logic [31:0] CSR_MIMPID_VALUE = 32'b0;
502
- // Machine Configuration Pointer
503
- // 0 indicates the configuration data structure does not eixst. cve2 implementors may wish to
504
- // alter this to point to their system specific configuration data structure.
505
- localparam logic [31:0] CSR_MCONFIGPTR_VALUE = 32'b0;
506
- // RVFI CSR element
507
- typedef struct packed {
508
- bit [63:0] rdata;
509
- bit [63:0] rmask;
510
- bit [63:0] wdata;
511
- bit [63:0] wmask;
512
- } rvfi_csr_elmt_t;
513
- // RVFI CSR structure
514
- typedef struct packed {
515
- rvfi_csr_elmt_t fflags;
516
- rvfi_csr_elmt_t frm;
517
- rvfi_csr_elmt_t fcsr;
518
- rvfi_csr_elmt_t ftran;
519
- rvfi_csr_elmt_t dcsr;
520
- rvfi_csr_elmt_t dpc;
521
- rvfi_csr_elmt_t dscratch0;
522
- rvfi_csr_elmt_t dscratch1;
523
- rvfi_csr_elmt_t sstatus;
524
- rvfi_csr_elmt_t sie;
525
- rvfi_csr_elmt_t sip;
526
- rvfi_csr_elmt_t stvec;
527
- rvfi_csr_elmt_t scounteren;
528
- rvfi_csr_elmt_t sscratch;
529
- rvfi_csr_elmt_t sepc;
530
- rvfi_csr_elmt_t scause;
531
- rvfi_csr_elmt_t stval;
532
- rvfi_csr_elmt_t satp;
533
- rvfi_csr_elmt_t mstatus;
534
- rvfi_csr_elmt_t mstatush;
535
- rvfi_csr_elmt_t misa;
536
- rvfi_csr_elmt_t medeleg;
537
- rvfi_csr_elmt_t mideleg;
538
- rvfi_csr_elmt_t mie;
539
- rvfi_csr_elmt_t mtvec;
540
- rvfi_csr_elmt_t mcounteren;
541
- rvfi_csr_elmt_t mscratch;
542
- rvfi_csr_elmt_t mepc;
543
- rvfi_csr_elmt_t mcause;
544
- rvfi_csr_elmt_t mtval;
545
- rvfi_csr_elmt_t mip;
546
- rvfi_csr_elmt_t menvcfg;
547
- rvfi_csr_elmt_t menvcfgh;
548
- rvfi_csr_elmt_t mvendorid;
549
- rvfi_csr_elmt_t marchid;
550
- rvfi_csr_elmt_t mhartid;
551
- rvfi_csr_elmt_t mcountinhibit;
552
- rvfi_csr_elmt_t mcycle;
553
- rvfi_csr_elmt_t mcycleh;
554
- rvfi_csr_elmt_t minstret;
555
- rvfi_csr_elmt_t minstreth;
556
- rvfi_csr_elmt_t cycle;
557
- rvfi_csr_elmt_t cycleh;
558
- rvfi_csr_elmt_t instret;
559
- rvfi_csr_elmt_t instreth;
560
- rvfi_csr_elmt_t dcache;
561
- rvfi_csr_elmt_t icache;
562
- rvfi_csr_elmt_t acc_cons;
563
- rvfi_csr_elmt_t pmpcfg0;
564
- rvfi_csr_elmt_t pmpcfg1;
565
- rvfi_csr_elmt_t pmpcfg2;
566
- rvfi_csr_elmt_t pmpcfg3;
567
- rvfi_csr_elmt_t pmpaddr0;
568
- rvfi_csr_elmt_t pmpaddr1;
569
- rvfi_csr_elmt_t pmpaddr2;
570
- rvfi_csr_elmt_t pmpaddr3;
571
- rvfi_csr_elmt_t pmpaddr4;
572
- rvfi_csr_elmt_t pmpaddr5;
573
- rvfi_csr_elmt_t pmpaddr6;
574
- rvfi_csr_elmt_t pmpaddr7;
575
- rvfi_csr_elmt_t pmpaddr8;
576
- rvfi_csr_elmt_t pmpaddr9;
577
- rvfi_csr_elmt_t pmpaddr10;
578
- rvfi_csr_elmt_t pmpaddr11;
579
- rvfi_csr_elmt_t pmpaddr12;
580
- rvfi_csr_elmt_t pmpaddr13;
581
- rvfi_csr_elmt_t pmpaddr14;
582
- rvfi_csr_elmt_t pmpaddr15;
583
- } rvfi_csr_t;
584
- // CV-X-IF
585
- parameter int unsigned X_NUM_RS = 3;
586
- parameter int unsigned X_ID_WIDTH = 4;
587
- parameter int unsigned X_RFR_WIDTH = 32;
588
- parameter int unsigned X_RFW_WIDTH = 32;
589
- parameter int unsigned X_HARTID_WIDTH = 32;
590
- parameter int unsigned X_DUAL_READ = 0;
591
- parameter int unsigned X_DUAL_WRITE = 0;
592
- parameter int unsigned X_INSTR_INFLIGHT = 2**X_ID_WIDTH;
593
- typedef logic [X_NUM_RS+X_DUAL_READ-1:0] readregflags_t;
594
- typedef logic [X_DUAL_WRITE:0] writeregflags_t;
595
- typedef logic [X_ID_WIDTH-1:0] id_t;
596
- typedef logic [X_HARTID_WIDTH-1:0] hartid_t;
597
- // Issue Interface
598
- typedef struct packed {
599
- logic [31:0] instr;
600
- hartid_t hartid;
601
- id_t id;
602
- } x_issue_req_t;
603
- typedef struct packed {
604
- logic accept;
605
- writeregflags_t writeback;
606
- readregflags_t register_read;
607
- } x_issue_resp_t;
608
- // Register Interface
609
- typedef struct packed {
610
- hartid_t hartid;
611
- id_t id;
612
- logic [X_NUM_RS-1:0][X_RFR_WIDTH-1:0] rs;
613
- readregflags_t rs_valid;
614
- } x_register_t;
615
- // Commit Interface
616
- typedef struct packed {
617
- hartid_t hartid;
618
- id_t id;
619
- logic commit_kill;
620
- } x_commit_t;
621
- // Result Interface
622
- typedef struct packed {
623
- hartid_t hartid;
624
- id_t id;
625
- logic [X_RFW_WIDTH-1:0] data;
626
- logic [4:0] rd;
627
- writeregflags_t we;
628
- } x_result_t;
629
- endpackage
630
- // Copyright (c) 2025 Eclipse Foundation
631
- // Copyright lowRISC contributors.
632
- // Copyright 2018 ETH Zurich and University of Bologna, see also CREDITS.md.
633
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
634
- // SPDX-License-Identifier: Apache-2.0
635
- /**
636
- * Compressed instruction decoder
637
- *
638
- * Decodes RISC-V compressed instructions into their RV32 equivalent.
639
- * This module is fully combinatorial, clock and reset are used for
640
- * assertions only.
641
- */
642
- // Copyright lowRISC contributors.
643
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
644
- // SPDX-License-Identifier: Apache-2.0
645
- // Macros and helper code for using assertions.
646
- // - Provides default clk and rst options to simplify code
647
- // - Provides boiler plate template for common assertions
648
- ///////////////////
649
- // Helper macros //
650
- ///////////////////
651
- // Default clk and reset signals used by assertion macros below.
652
- // Converts an arbitrary block of code into a Verilog string
653
- // ASSERT_ERROR logs an error message with either `uvm_error or with $error.
654
- //
655
- // This somewhat duplicates `DV_ERROR macro defined in hw/dv/sv/dv_utils/dv_macros.svh. The reason
656
- // for redefining it here is to avoid creating a dependency.
657
- // This macro is suitable for conditionally triggering lint errors, e.g., if a Sec parameter takes
658
- // on a non-default value. This may be required for pre-silicon/FPGA evaluation but we don't want
659
- // to allow this for tapeout.
660
- // The basic helper macros are actually defined in "implementation headers". The macros should do
661
- // the same thing in each case (except for the dummy flavour), but in a way that the respective
662
- // tools support.
663
- //
664
- // If the tool supports assertions in some form, we also define INC_ASSERT (which can be used to
665
- // hide signal definitions that are only used for assertions).
666
- //
667
- // The list of basic macros supported is:
668
- //
669
- // ASSERT_I: Immediate assertion. Note that immediate assertions are sensitive to simulation
670
- // glitches.
671
- //
672
- // ASSERT_INIT: Assertion in initial block. Can be used for things like parameter checking.
673
- //
674
- // ASSERT_INIT_NET: Assertion in initial block. Can be used for initial value of a net.
675
- //
676
- // ASSERT_FINAL: Assertion in final block. Can be used for things like queues being empty at end of
677
- // sim, all credits returned at end of sim, state machines in idle at end of sim.
678
- //
679
- // ASSERT: Assert a concurrent property directly. It can be called as a module (or
680
- // interface) body item.
681
- //
682
- // Note: We use (__rst !== '0) in the disable iff statements instead of (__rst ==
683
- // '1). This properly disables the assertion in cases when reset is X at the
684
- // beginning of a simulation. For that case, (reset == '1) does not disable the
685
- // assertion.
686
- //
687
- // ASSERT_NEVER: Assert a concurrent property NEVER happens
688
- //
689
- // ASSERT_KNOWN: Assert that signal has a known value (each bit is either '0' or '1') after reset.
690
- // It can be called as a module (or interface) body item.
691
- //
692
- // COVER: Cover a concurrent property
693
- //
694
- // ASSUME: Assume a concurrent property
695
- //
696
- // ASSUME_I: Assume an immediate property
697
- // Copyright lowRISC contributors.
698
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
699
- // SPDX-License-Identifier: Apache-2.0
700
- // Macro bodies included by prim_assert.sv for tools that don't support assertions. See
701
- // prim_assert.sv for documentation for each of the macros.
702
- //////////////////////////////
703
- // Complex assertion macros //
704
- //////////////////////////////
705
- // Assert that signal is an active-high pulse with pulse length of 1 clock cycle
706
- // Assert that a property is true only when an enable signal is set. It can be called as a module
707
- // (or interface) body item.
708
- // Assert that signal has a known value (each bit is either '0' or '1') after reset if enable is
709
- // set. It can be called as a module (or interface) body item.
710
- //////////////////////////////////
711
- // For formal verification only //
712
- //////////////////////////////////
713
- // Note that the existing set of ASSERT macros specified above shall be used for FPV,
714
- // thereby ensuring that the assertions are evaluated during DV simulations as well.
715
- // ASSUME_FPV
716
- // Assume a concurrent property during formal verification only.
717
- // ASSUME_I_FPV
718
- // Assume a concurrent property during formal verification only.
719
- // COVER_FPV
720
- // Cover a concurrent property during formal verification
721
- // Copyright lowRISC contributors.
722
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
723
- // SPDX-License-Identifier: Apache-2.0
724
- // // Macros and helper code for security countermeasures.
725
- // Helper macros
726
- // macros for security countermeasures
727
- // PRIM_ASSERT_SEC_CM_SVH
728
- // PRIM_ASSERT_SV
729
- module cve2_compressed_decoder (
730
- input logic clk_i,
731
- input logic rst_ni,
732
- input logic valid_i,
733
- input logic [31:0] instr_i,
734
- output logic [31:0] instr_o,
735
- output logic is_compressed_o,
736
- output logic illegal_instr_o
737
- );
738
- import cve2_pkg::*;
739
- // valid_i indicates if instr_i is valid and is used for assertions only.
740
- // The following signal is used to avoid possible lint errors.
741
- logic unused_valid;
742
- assign unused_valid = valid_i;
743
- ////////////////////////
744
- // Compressed decoder //
745
- ////////////////////////
746
- always_comb begin
747
- // By default, forward incoming instruction, mark it as legal.
748
- instr_o = instr_i;
749
- illegal_instr_o = 1'b0;
750
- // Check if incoming instruction is compressed.
751
- unique case (instr_i[1:0])
752
- // C0
753
- 2'b00: begin
754
- unique case (instr_i[15:13])
755
- 3'b000: begin
756
- // c.addi4spn -> addi rd', x2, imm
757
- instr_o = {2'b0, instr_i[10:7], instr_i[12:11], instr_i[5],
758
- instr_i[6], 2'b00, 5'h02, 3'b000, 2'b01, instr_i[4:2], {OPCODE_OP_IMM}};
759
- if (instr_i[12:5] == 8'b0) illegal_instr_o = 1'b1;
760
- end
761
- 3'b010: begin
762
- // c.lw -> lw rd', imm(rs1')
763
- instr_o = {5'b0, instr_i[5], instr_i[12:10], instr_i[6],
764
- 2'b00, 2'b01, instr_i[9:7], 3'b010, 2'b01, instr_i[4:2], {OPCODE_LOAD}};
765
- end
766
- 3'b110: begin
767
- // c.sw -> sw rs2', imm(rs1')
768
- instr_o = {5'b0, instr_i[5], instr_i[12], 2'b01, instr_i[4:2],
769
- 2'b01, instr_i[9:7], 3'b010, instr_i[11:10], instr_i[6],
770
- 2'b00, {OPCODE_STORE}};
771
- end
772
- 3'b001,
773
- 3'b011,
774
- 3'b100,
775
- 3'b101,
776
- 3'b111: begin
777
- illegal_instr_o = 1'b1;
778
- end
779
- default: begin
780
- illegal_instr_o = 1'b1;
781
- end
782
- endcase
783
- end
784
- // C1
785
- //
786
- // Register address checks for RV32E are performed in the regular instruction decoder.
787
- // If this check fails, an illegal instruction exception is triggered and the controller
788
- // writes the actual faulting instruction to mtval.
789
- 2'b01: begin
790
- unique case (instr_i[15:13])
791
- 3'b000: begin
792
- // c.addi -> addi rd, rd, nzimm
793
- // c.nop
794
- instr_o = {{6 {instr_i[12]}}, instr_i[12], instr_i[6:2],
795
- instr_i[11:7], 3'b0, instr_i[11:7], {OPCODE_OP_IMM}};
796
- end
797
- 3'b001, 3'b101: begin
798
- // 001: c.jal -> jal x1, imm
799
- // 101: c.j -> jal x0, imm
800
- instr_o = {instr_i[12], instr_i[8], instr_i[10:9], instr_i[6],
801
- instr_i[7], instr_i[2], instr_i[11], instr_i[5:3],
802
- {9 {instr_i[12]}}, 4'b0, ~instr_i[15], {OPCODE_JAL}};
803
- end
804
- 3'b010: begin
805
- // c.li -> addi rd, x0, nzimm
806
- // (c.li hints are translated into an addi hint)
807
- instr_o = {{6 {instr_i[12]}}, instr_i[12], instr_i[6:2], 5'b0,
808
- 3'b0, instr_i[11:7], {OPCODE_OP_IMM}};
809
- end
810
- 3'b011: begin
811
- // c.lui -> lui rd, imm
812
- // (c.lui hints are translated into a lui hint)
813
- instr_o = {{15 {instr_i[12]}}, instr_i[6:2], instr_i[11:7], {OPCODE_LUI}};
814
- if (instr_i[11:7] == 5'h02) begin
815
- // c.addi16sp -> addi x2, x2, nzimm
816
- instr_o = {{3 {instr_i[12]}}, instr_i[4:3], instr_i[5], instr_i[2],
817
- instr_i[6], 4'b0, 5'h02, 3'b000, 5'h02, {OPCODE_OP_IMM}};
818
- end
819
- if ({instr_i[12], instr_i[6:2]} == 6'b0) illegal_instr_o = 1'b1;
820
- end
821
- 3'b100: begin
822
- unique case (instr_i[11:10])
823
- 2'b00,
824
- 2'b01: begin
825
- // 00: c.srli -> srli rd, rd, shamt
826
- // 01: c.srai -> srai rd, rd, shamt
827
- // (c.srli/c.srai hints are translated into a srli/srai hint)
828
- instr_o = {1'b0, instr_i[10], 5'b0, instr_i[6:2], 2'b01, instr_i[9:7],
829
- 3'b101, 2'b01, instr_i[9:7], {OPCODE_OP_IMM}};
830
- if (instr_i[12] == 1'b1) illegal_instr_o = 1'b1;
831
- end
832
- 2'b10: begin
833
- // c.andi -> andi rd, rd, imm
834
- instr_o = {{6 {instr_i[12]}}, instr_i[12], instr_i[6:2], 2'b01, instr_i[9:7],
835
- 3'b111, 2'b01, instr_i[9:7], {OPCODE_OP_IMM}};
836
- end
837
- 2'b11: begin
838
- unique case ({instr_i[12], instr_i[6:5]})
839
- 3'b000: begin
840
- // c.sub -> sub rd', rd', rs2'
841
- instr_o = {2'b01, 5'b0, 2'b01, instr_i[4:2], 2'b01, instr_i[9:7],
842
- 3'b000, 2'b01, instr_i[9:7], {OPCODE_OP}};
843
- end
844
- 3'b001: begin
845
- // c.xor -> xor rd', rd', rs2'
846
- instr_o = {7'b0, 2'b01, instr_i[4:2], 2'b01, instr_i[9:7], 3'b100,
847
- 2'b01, instr_i[9:7], {OPCODE_OP}};
848
- end
849
- 3'b010: begin
850
- // c.or -> or rd', rd', rs2'
851
- instr_o = {7'b0, 2'b01, instr_i[4:2], 2'b01, instr_i[9:7], 3'b110,
852
- 2'b01, instr_i[9:7], {OPCODE_OP}};
853
- end
854
- 3'b011: begin
855
- // c.and -> and rd', rd', rs2'
856
- instr_o = {7'b0, 2'b01, instr_i[4:2], 2'b01, instr_i[9:7], 3'b111,
857
- 2'b01, instr_i[9:7], {OPCODE_OP}};
858
- end
859
- 3'b100,
860
- 3'b101,
861
- 3'b110,
862
- 3'b111: begin
863
- // 100: c.subw
864
- // 101: c.addw
865
- illegal_instr_o = 1'b1;
866
- end
867
- default: begin
868
- illegal_instr_o = 1'b1;
869
- end
870
- endcase
871
- end
872
- default: begin
873
- illegal_instr_o = 1'b1;
874
- end
875
- endcase
876
- end
877
- 3'b110, 3'b111: begin
878
- // 0: c.beqz -> beq rs1', x0, imm
879
- // 1: c.bnez -> bne rs1', x0, imm
880
- instr_o = {{4 {instr_i[12]}}, instr_i[6:5], instr_i[2], 5'b0, 2'b01,
881
- instr_i[9:7], 2'b00, instr_i[13], instr_i[11:10], instr_i[4:3],
882
- instr_i[12], {OPCODE_BRANCH}};
883
- end
884
- default: begin
885
- illegal_instr_o = 1'b1;
886
- end
887
- endcase
888
- end
889
- // C2
890
- //
891
- // Register address checks for RV32E are performed in the regular instruction decoder.
892
- // If this check fails, an illegal instruction exception is triggered and the controller
893
- // writes the actual faulting instruction to mtval.
894
- 2'b10: begin
895
- unique case (instr_i[15:13])
896
- 3'b000: begin
897
- // c.slli -> slli rd, rd, shamt
898
- // (c.ssli hints are translated into a slli hint)
899
- instr_o = {7'b0, instr_i[6:2], instr_i[11:7], 3'b001, instr_i[11:7], {OPCODE_OP_IMM}};
900
- if (instr_i[12] == 1'b1) illegal_instr_o = 1'b1; // reserved for custom extensions
901
- end
902
- 3'b010: begin
903
- // c.lwsp -> lw rd, imm(x2)
904
- instr_o = {4'b0, instr_i[3:2], instr_i[12], instr_i[6:4], 2'b00, 5'h02,
905
- 3'b010, instr_i[11:7], OPCODE_LOAD};
906
- if (instr_i[11:7] == 5'b0) illegal_instr_o = 1'b1;
907
- end
908
- 3'b100: begin
909
- if (instr_i[12] == 1'b0) begin
910
- if (instr_i[6:2] != 5'b0) begin
911
- // c.mv -> add rd/rs1, x0, rs2
912
- // (c.mv hints are translated into an add hint)
913
- instr_o = {7'b0, instr_i[6:2], 5'b0, 3'b0, instr_i[11:7], {OPCODE_OP}};
914
- end else begin
915
- // c.jr -> jalr x0, rd/rs1, 0
916
- instr_o = {12'b0, instr_i[11:7], 3'b0, 5'b0, {OPCODE_JALR}};
917
- if (instr_i[11:7] == 5'b0) illegal_instr_o = 1'b1;
918
- end
919
- end else begin
920
- if (instr_i[6:2] != 5'b0) begin
921
- // c.add -> add rd, rd, rs2
922
- // (c.add hints are translated into an add hint)
923
- instr_o = {7'b0, instr_i[6:2], instr_i[11:7], 3'b0, instr_i[11:7], {OPCODE_OP}};
924
- end else begin
925
- if (instr_i[11:7] == 5'b0) begin
926
- // c.ebreak -> ebreak
927
- instr_o = {32'h00_10_00_73};
928
- end else begin
929
- // c.jalr -> jalr x1, rs1, 0
930
- instr_o = {12'b0, instr_i[11:7], 3'b000, 5'b00001, {OPCODE_JALR}};
931
- end
932
- end
933
- end
934
- end
935
- 3'b110: begin
936
- // c.swsp -> sw rs2, imm(x2)
937
- instr_o = {4'b0, instr_i[8:7], instr_i[12], instr_i[6:2], 5'h02, 3'b010,
938
- instr_i[11:9], 2'b00, {OPCODE_STORE}};
939
- end
940
- 3'b001,
941
- 3'b011,
942
- 3'b101,
943
- 3'b111: begin
944
- illegal_instr_o = 1'b1;
945
- end
946
- default: begin
947
- illegal_instr_o = 1'b1;
948
- end
949
- endcase
950
- end
951
- // Incoming instruction is not compressed.
952
- 2'b11:;
953
- default: begin
954
- illegal_instr_o = 1'b1;
955
- end
956
- endcase
957
- end
958
- assign is_compressed_o = (instr_i[1:0] != 2'b11);
959
- ////////////////
960
- // Assertions //
961
- ////////////////
962
- // The valid_i signal used to gate below assertions must be known.
963
- // Selectors must be known/valid.
964
- endmodule
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p3/mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"conditional_statement": [[31186, 31789], [26677, 26741], [30530, 30581], [24138, 24189], [30212, 30295], [27228, 27277], [30677, 31144], [31076, 31126], [31469, 31771]], "blocking_assignment": [[23681, 23707], [31685, 31751], [24526, 24715], [24281, 24433], [27067, 27211], [29323, 29532], [28266, 28398], [26042, 26166]], "always_construct": [[23592, 32418]], "case_statement": [[25271, 29637], [29942, 32264], [23792, 32412], [26792, 29172], [23858, 24966], [27598, 29047]], "ansi_port_declaration": [[23120, 23148], [23090, 23117], [23061, 23087], [23213, 23249], [23151, 23179], [23252, 23287], [23182, 23210]], "continuous_assign": [[32421, 32470]], "parameter_declaration": [[16993, 17037], [13787, 13814], [13551, 13619], [16802, 16847], [16708, 16752], [13622, 13688], [16850, 16895], [16755, 16799]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p4/all_mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"module_program_interface_instantiation": [], "continuous_assign": [[31028, 31060], [31063, 31096], [31170, 31229], [31232, 31291], [31294, 31353], [31356, 31415], [31418, 31477], [31480, 31539], [31542, 31601], [31721, 31769], [31826, 32029], [32372, 32469], [32769, 32894], [32925, 32971], [33367, 33425], [33477, 33556], [33624, 33692], [35233, 35330], [35898, 35980], [35983, 36069], [36163, 36373], [36643, 36748], [36998, 37041], [51357, 51386], [51427, 51462], [51539, 51570], [51764, 51790], [51855, 51909], [52230, 52291]], "blocking_assignment": [[33807, 33832], [33839, 33864], [33871, 33896], [33903, 33928], [33935, 33960], [33967, 33992], [34034, 34062], [34112, 34137], [34183, 34206], [34251, 34273], [34320, 34342], [34388, 34410], [36854, 36869], [36954, 36971], [37160, 37189], [37194, 37223], [37228, 37257], [37262, 37291], [37296, 37325], [37330, 37359], [37364, 37391], [37712, 37745], [37750, 37780], [37785, 37821], [37826, 37887], [37892, 37929], [37934, 37964], [37969, 37999], [38004, 38034], [38039, 38069], [38074, 38104], [38109, 38151], [38156, 38194], [38199, 38235], [38240, 38270], [38275, 38305], [38310, 38340], [38398, 38419], [38428, 38452], [38461, 38482], [38543, 38566], [38671, 38692], [38701, 38725], [38734, 38755], [38764, 38790], [38833, 38854], [38863, 38884], [38893, 38914], [38923, 38944], [38953, 38975], [39125, 39146], [39155, 39176], [39185, 39206], [39425, 39451], [39532, 39551], [39678, 39699], [40077, 40101], [40112, 40131], [40218, 40245], [40394, 40413], [40777, 40801], [41040, 41059], [41349, 41366], [41547, 41599], [41668, 41690], [41701, 41731], [41742, 41770], [42039, 42054], [42209, 42269], [42424, 42443], [42549, 42606], [42958, 42977], [43055, 43077], [43086, 43112], [43153, 43177], [43188, 43212], [43223, 43247], [43379, 43410], [43423, 43460], [44060, 44106], [44169, 44208], [44271, 44310], [44368, 44404], [44439, 44460], [44505, 44527], [44536, 44562], [44683, 44707], [44716, 44740], [44749, 44773], [44782, 44806], [44815, 44839], [44885, 44939], [44990, 45044], [45078, 45140], [45189, 45209], [45218, 45240], [45684, 45705], [45714, 45737], [45746, 45767], [45776, 45803], [46007, 46031], [46042, 46066], [46095, 46119], [46130, 46166], [46215, 46235], [46244, 46266], [46334, 46353], [46362, 46381], [46390, 46411], [46730, 46754], [46765, 46791], [46802, 46864], [46920, 46942], [46967, 46991], [47163, 47206], [47221, 47289], [47357, 47394], [47409, 47485], [47551, 47699], [48346, 48370], [48387, 48411], [48428, 48452], [48469, 48501], [48518, 48542], [49160, 49200], [49283, 49326], [49341, 49371], [49435, 49477], [49492, 49522], [49701, 49733], [49746, 49775], [49788, 49817], [49866, 49910], [49979, 50011], [50024, 50053], [50066, 50095], [50108, 50137], [50189, 50224], [51190, 51217], [51278, 51297], [51306, 51326]], "nonblocking_assignment": [[52410, 52443], [52450, 52482], [52489, 52521], [52528, 52560], [52567, 52599], [52606, 52638], [52645, 52677], [52684, 52716], [52723, 52755], [52781, 52820], [52827, 52865], [52872, 52916], [52923, 52963], [52970, 53021], [53028, 53066], [53073, 53112], [53119, 53156], [53163, 53205]], "case_statement": [[38345, 51348], [47090, 49579]], "conditional_statement": [[33999, 34420], [34078, 34420], [34153, 34420], [34222, 34420], [34289, 34420], [34358, 34420], [36916, 36981], [38491, 38578], [39324, 39563], [39643, 39711], [39749, 40143], [40180, 40425], [41144, 41611], [41620, 41782], [41957, 42066], [42075, 43003], [42137, 42991], [42463, 42991], [43121, 44430], [43332, 44418], [43480, 44418], [44126, 44418], [44228, 44418], [44848, 45152], [44957, 45152], [45843, 46178], [46670, 50263], [47764, 49218], [49668, 50238], [49830, 49926], [49946, 50238], [50157, 50238], [51103, 51229], [52385, 53213]], "always_construct": [[33783, 34428], [36818, 36995], [37116, 51354], [52316, 53219]], "parameter_declaration": [[6471, 6520], [6523, 6571], [6594, 6628], [6631, 6665], [6668, 6702], [12379, 12461], [12464, 12546], [12570, 12622], [12625, 12677], [12680, 12733], [12736, 12789], [12792, 12845], [12848, 12901], [12925, 13002], [13044, 13089], [13092, 13137], [13140, 13186], [13189, 13235], [13238, 13284], [13332, 13380], [13383, 13431], [13434, 13482], [13551, 13619], [13622, 13688], [13787, 13814], [16708, 16752], [16755, 16799], [16802, 16847], [16850, 16895], [16898, 16943], [16946, 16990], [16993, 17037], [17040, 17096]], "ansi_port_declaration": [[24823, 24859], [24862, 24899], [24902, 25005], [25008, 25096], [25128, 25214], [25217, 25298], [25301, 25381], [25384, 25464], [25467, 25546], [25549, 25631], [25634, 25721], [25724, 25822], [25862, 25934], [25937, 26028], [26031, 26120], [26123, 26200], [26203, 26276], [26279, 26355], [26358, 26429], [26461, 26542], [26545, 26634], [26637, 26732], [26823, 26908], [26911, 26998], [27001, 27090], [27182, 27274], [27277, 27353], [27365, 27432], [27435, 27476], [27479, 27521], [27549, 27643], [27713, 27792], [27818, 27903], [27906, 27989], [27992, 28083], [28154, 28235], [28238, 28322], [28344, 28386], [28389, 28433], [28436, 28483], [28486, 28529], [28532, 28582], [28585, 28631], [28634, 28680], [28683, 28729], [28732, 28776], [28779, 28823], [28826, 28878], [28881, 28933], [28936, 28983], [28986, 29028], [29031, 29073], [29076, 29123], [29153, 29194], [29197, 29238], [29267, 29348], [29442, 29531]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p4/cve2_controller.sv DELETED
@@ -1,1373 +0,0 @@
1
- // Copyright (c) 2025 Eclipse Foundation
2
- // Copyright lowRISC contributors.
3
- // Copyright 2017 ETH Zurich and University of Bologna, see also CREDITS.md.
4
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
5
- // SPDX-License-Identifier: Apache-2.0
6
- /**
7
- * Package with constants used by CVE2
8
- */
9
- package cve2_pkg;
10
- ////////////////
11
- // IO Structs //
12
- ////////////////
13
- typedef struct packed {
14
- logic [31:0] current_pc;
15
- logic [31:0] next_pc;
16
- logic [31:0] last_data_addr;
17
- logic [31:0] exception_addr;
18
- } crash_dump_t;
19
- typedef struct packed {
20
- logic dummy_instr_id;
21
- logic [4:0] raddr_a;
22
- logic [4:0] waddr_a;
23
- logic we_a;
24
- logic [4:0] raddr_b;
25
- } core2rf_t;
26
- /////////////////////
27
- // Parameter Enums //
28
- /////////////////////
29
- typedef enum integer {
30
- RV32MNone = 0,
31
- RV32MSlow = 1,
32
- RV32MFast = 2,
33
- RV32MSingleCycle = 3
34
- } rv32m_e;
35
- typedef enum integer {
36
- RV32BNone = 0,
37
- RV32BBalanced = 1,
38
- RV32BOTEarlGrey = 2,
39
- RV32BFull = 3
40
- } rv32b_e;
41
- /////////////
42
- // Opcodes //
43
- /////////////
44
- typedef enum logic [6:0] {
45
- OPCODE_LOAD = 7'h03,
46
- OPCODE_MISC_MEM = 7'h0f,
47
- OPCODE_OP_IMM = 7'h13,
48
- OPCODE_AUIPC = 7'h17,
49
- OPCODE_STORE = 7'h23,
50
- OPCODE_OP = 7'h33,
51
- OPCODE_LUI = 7'h37,
52
- OPCODE_BRANCH = 7'h63,
53
- OPCODE_JALR = 7'h67,
54
- OPCODE_JAL = 7'h6f,
55
- OPCODE_SYSTEM = 7'h73
56
- } opcode_e;
57
- ////////////////////
58
- // ALU operations //
59
- ////////////////////
60
- typedef enum logic [6:0] {
61
- // Arithmetics
62
- ALU_ADD,
63
- ALU_SUB,
64
- // Logics
65
- ALU_XOR,
66
- ALU_OR,
67
- ALU_AND,
68
- // RV32B
69
- ALU_XNOR,
70
- ALU_ORN,
71
- ALU_ANDN,
72
- // Shifts
73
- ALU_SRA,
74
- ALU_SRL,
75
- ALU_SLL,
76
- // RV32B
77
- ALU_SRO,
78
- ALU_SLO,
79
- ALU_ROR,
80
- ALU_ROL,
81
- ALU_GREV,
82
- ALU_GORC,
83
- ALU_SHFL,
84
- ALU_UNSHFL,
85
- ALU_XPERM_N,
86
- ALU_XPERM_B,
87
- ALU_XPERM_H,
88
- // Address Calculations
89
- // RV32B
90
- ALU_SH1ADD,
91
- ALU_SH2ADD,
92
- ALU_SH3ADD,
93
- // Comparisons
94
- ALU_LT,
95
- ALU_LTU,
96
- ALU_GE,
97
- ALU_GEU,
98
- ALU_EQ,
99
- ALU_NE,
100
- // RV32B
101
- ALU_MIN,
102
- ALU_MINU,
103
- ALU_MAX,
104
- ALU_MAXU,
105
- // Pack
106
- // RV32B
107
- ALU_PACK,
108
- ALU_PACKU,
109
- ALU_PACKH,
110
- // Sign-Extend
111
- // RV32B
112
- ALU_SEXTB,
113
- ALU_SEXTH,
114
- // Bitcounting
115
- // RV32B
116
- ALU_CLZ,
117
- ALU_CTZ,
118
- ALU_CPOP,
119
- // Set lower than
120
- ALU_SLT,
121
- ALU_SLTU,
122
- // Ternary Bitmanip Operations
123
- // RV32B
124
- ALU_CMOV,
125
- ALU_CMIX,
126
- ALU_FSL,
127
- ALU_FSR,
128
- // Single-Bit Operations
129
- // RV32B
130
- ALU_BSET,
131
- ALU_BCLR,
132
- ALU_BINV,
133
- ALU_BEXT,
134
- // Bit Compress / Decompress
135
- // RV32B
136
- ALU_BCOMPRESS,
137
- ALU_BDECOMPRESS,
138
- // Bit Field Place
139
- // RV32B
140
- ALU_BFP,
141
- // Carry-less Multiply
142
- // RV32B
143
- ALU_CLMUL,
144
- ALU_CLMULR,
145
- ALU_CLMULH,
146
- // Cyclic Redundancy Check
147
- ALU_CRC32_B,
148
- ALU_CRC32C_B,
149
- ALU_CRC32_H,
150
- ALU_CRC32C_H,
151
- ALU_CRC32_W,
152
- ALU_CRC32C_W
153
- } alu_op_e;
154
- typedef enum logic [1:0] {
155
- // Multiplier/divider
156
- MD_OP_MULL,
157
- MD_OP_MULH,
158
- MD_OP_DIV,
159
- MD_OP_REM
160
- } md_op_e;
161
- //////////////////////////////////
162
- // Control and status registers //
163
- //////////////////////////////////
164
- // CSR operations
165
- typedef enum logic [1:0] {
166
- CSR_OP_READ,
167
- CSR_OP_WRITE,
168
- CSR_OP_SET,
169
- CSR_OP_CLEAR
170
- } csr_op_e;
171
- // Privileged mode
172
- typedef enum logic[1:0] {
173
- PRIV_LVL_M = 2'b11,
174
- PRIV_LVL_H = 2'b10,
175
- PRIV_LVL_S = 2'b01,
176
- PRIV_LVL_U = 2'b00
177
- } priv_lvl_e;
178
- // Constants for the dcsr.xdebugver fields
179
- typedef enum logic[3:0] {
180
- XDEBUGVER_NO = 4'd0, // no external debug support
181
- XDEBUGVER_STD = 4'd4, // external debug according to RISC-V debug spec
182
- XDEBUGVER_NONSTD = 4'd15 // debug not conforming to RISC-V debug spec
183
- } x_debug_ver_e;
184
- //////////////
185
- // WB stage //
186
- //////////////
187
- // Type of instruction present in writeback stage
188
- typedef enum logic[1:0] {
189
- WB_INSTR_LOAD, // Instruction is awaiting load data
190
- WB_INSTR_STORE, // Instruction is awaiting store response
191
- WB_INSTR_OTHER // Instruction doesn't fit into above categories
192
- } wb_instr_type_e;
193
- //////////////
194
- // ID stage //
195
- //////////////
196
- // Operand a selection
197
- typedef enum logic[1:0] {
198
- OP_A_REG_A,
199
- OP_A_FWD,
200
- OP_A_CURRPC,
201
- OP_A_IMM
202
- } op_a_sel_e;
203
- // Immediate a selection
204
- typedef enum logic {
205
- IMM_A_Z,
206
- IMM_A_ZERO
207
- } imm_a_sel_e;
208
- // Operand b selection
209
- typedef enum logic {
210
- OP_B_REG_B,
211
- OP_B_IMM
212
- } op_b_sel_e;
213
- // Immediate b selection
214
- typedef enum logic [2:0] {
215
- IMM_B_I,
216
- IMM_B_S,
217
- IMM_B_B,
218
- IMM_B_U,
219
- IMM_B_J,
220
- IMM_B_INCR_PC,
221
- IMM_B_INCR_ADDR
222
- } imm_b_sel_e;
223
- // Regfile write data selection
224
- typedef enum {
225
- RF_WD_EX,
226
- RF_WD_CSR,
227
- RF_WD_COPROC // Only used when XInterface = 1
228
- } rf_wd_sel_e;
229
- //////////////
230
- // IF stage //
231
- //////////////
232
- // PC mux selection
233
- typedef enum logic [2:0] {
234
- PC_BOOT,
235
- PC_JUMP,
236
- PC_EXC,
237
- PC_ERET,
238
- PC_DRET,
239
- PC_BP
240
- } pc_sel_e;
241
- // Exception PC mux selection
242
- typedef enum logic [1:0] {
243
- EXC_PC_EXC,
244
- EXC_PC_IRQ,
245
- EXC_PC_DBD,
246
- EXC_PC_DBG_EXC // Exception while in debug mode
247
- } exc_pc_sel_e;
248
- // Interrupt requests
249
- typedef struct packed {
250
- logic irq_software;
251
- logic irq_timer;
252
- logic irq_external;
253
- logic [15:0] irq_fast; // 16 fast interrupts
254
- } irqs_t;
255
- // Exception cause
256
- typedef enum logic [6:0] {
257
- EXC_CAUSE_IRQ_SOFTWARE_M = {1'b1, 6'd03},
258
- EXC_CAUSE_IRQ_TIMER_M = {1'b1, 6'd07},
259
- EXC_CAUSE_IRQ_EXTERNAL_M = {1'b1, 6'd11},
260
- // EXC_CAUSE_IRQ_FAST_0 = {1'b1, 6'd16},
261
- // EXC_CAUSE_IRQ_FAST_15 = {1'b1, 6'd31},
262
- EXC_CAUSE_IRQ_NM = {1'b1, 6'd32},
263
- EXC_CAUSE_INSN_ADDR_MISA = {1'b0, 6'd00},
264
- EXC_CAUSE_INSTR_ACCESS_FAULT = {1'b0, 6'd01},
265
- EXC_CAUSE_ILLEGAL_INSN = {1'b0, 6'd02},
266
- EXC_CAUSE_BREAKPOINT = {1'b0, 6'd03},
267
- EXC_CAUSE_LOAD_ACCESS_FAULT = {1'b0, 6'd05},
268
- EXC_CAUSE_STORE_ACCESS_FAULT = {1'b0, 6'd07},
269
- EXC_CAUSE_ECALL_UMODE = {1'b0, 6'd08},
270
- EXC_CAUSE_ECALL_MMODE = {1'b0, 6'd11}
271
- } exc_cause_e;
272
- // Debug cause
273
- typedef enum logic [2:0] {
274
- DBG_CAUSE_NONE = 3'h0,
275
- DBG_CAUSE_EBREAK = 3'h1,
276
- DBG_CAUSE_TRIGGER = 3'h2,
277
- DBG_CAUSE_HALTREQ = 3'h3,
278
- DBG_CAUSE_STEP = 3'h4
279
- } dbg_cause_e;
280
- // PMP constants
281
- parameter int unsigned PMP_MAX_REGIONS = 16;
282
- parameter int unsigned PMP_CFG_W = 8;
283
- // PMP acces type
284
- parameter int unsigned PMP_I = 0;
285
- parameter int unsigned PMP_I2 = 1;
286
- parameter int unsigned PMP_D = 2;
287
- typedef enum logic [1:0] {
288
- PMP_ACC_EXEC = 2'b00,
289
- PMP_ACC_WRITE = 2'b01,
290
- PMP_ACC_READ = 2'b10
291
- } pmp_req_e;
292
- // PMP cfg structures
293
- typedef enum logic [1:0] {
294
- PMP_MODE_OFF = 2'b00,
295
- PMP_MODE_TOR = 2'b01,
296
- PMP_MODE_NA4 = 2'b10,
297
- PMP_MODE_NAPOT = 2'b11
298
- } pmp_cfg_mode_e;
299
- typedef struct packed {
300
- logic lock;
301
- pmp_cfg_mode_e mode;
302
- logic exec;
303
- logic write;
304
- logic read;
305
- } pmp_cfg_t;
306
- // Machine Security Configuration (ePMP)
307
- typedef struct packed {
308
- logic rlb; // Rule Locking Bypass
309
- logic mmwp; // Machine Mode Whitelist Policy
310
- logic mml; // Machine Mode Lockdown
311
- } pmp_mseccfg_t;
312
- // CSRs
313
- typedef enum logic[11:0] {
314
- // Machine information
315
- CSR_MVENDORID = 12'hF11,
316
- CSR_MARCHID = 12'hF12,
317
- CSR_MIMPID = 12'hF13,
318
- CSR_MHARTID = 12'hF14,
319
- CSR_MCONFIGPTR = 12'hF15,
320
- // Machine trap setup
321
- CSR_MSTATUS = 12'h300,
322
- CSR_MISA = 12'h301,
323
- CSR_MIE = 12'h304,
324
- CSR_MTVEC = 12'h305,
325
- CSR_MCOUNTEREN= 12'h306,
326
- CSR_MSTATUSH = 12'h310,
327
- CSR_MENVCFG = 12'h30A,
328
- CSR_MENVCFGH = 12'h31A,
329
- // Machine trap handling
330
- CSR_MSCRATCH = 12'h340,
331
- CSR_MEPC = 12'h341,
332
- CSR_MCAUSE = 12'h342,
333
- CSR_MTVAL = 12'h343,
334
- CSR_MIP = 12'h344,
335
- // Physical memory protection
336
- CSR_PMPCFG0 = 12'h3A0,
337
- CSR_PMPCFG1 = 12'h3A1,
338
- CSR_PMPCFG2 = 12'h3A2,
339
- CSR_PMPCFG3 = 12'h3A3,
340
- CSR_PMPADDR0 = 12'h3B0,
341
- CSR_PMPADDR1 = 12'h3B1,
342
- CSR_PMPADDR2 = 12'h3B2,
343
- CSR_PMPADDR3 = 12'h3B3,
344
- CSR_PMPADDR4 = 12'h3B4,
345
- CSR_PMPADDR5 = 12'h3B5,
346
- CSR_PMPADDR6 = 12'h3B6,
347
- CSR_PMPADDR7 = 12'h3B7,
348
- CSR_PMPADDR8 = 12'h3B8,
349
- CSR_PMPADDR9 = 12'h3B9,
350
- CSR_PMPADDR10 = 12'h3BA,
351
- CSR_PMPADDR11 = 12'h3BB,
352
- CSR_PMPADDR12 = 12'h3BC,
353
- CSR_PMPADDR13 = 12'h3BD,
354
- CSR_PMPADDR14 = 12'h3BE,
355
- CSR_PMPADDR15 = 12'h3BF,
356
- // ePMP control
357
- CSR_MSECCFG = 12'h747,
358
- CSR_MSECCFGH = 12'h757,
359
- // Debug trigger
360
- CSR_TSELECT = 12'h7A0,
361
- CSR_TDATA1 = 12'h7A1,
362
- CSR_TDATA2 = 12'h7A2,
363
- CSR_TDATA3 = 12'h7A3,
364
- CSR_MCONTEXT = 12'h7A8,
365
- CSR_SCONTEXT = 12'h7AA,
366
- // Debug/trace
367
- CSR_DCSR = 12'h7b0,
368
- CSR_DPC = 12'h7b1,
369
- // Debug
370
- CSR_DSCRATCH0 = 12'h7b2, // optional
371
- CSR_DSCRATCH1 = 12'h7b3, // optional
372
- // Machine Counter/Timers
373
- CSR_MCOUNTINHIBIT = 12'h320,
374
- CSR_MHPMEVENT3 = 12'h323,
375
- CSR_MHPMEVENT4 = 12'h324,
376
- CSR_MHPMEVENT5 = 12'h325,
377
- CSR_MHPMEVENT6 = 12'h326,
378
- CSR_MHPMEVENT7 = 12'h327,
379
- CSR_MHPMEVENT8 = 12'h328,
380
- CSR_MHPMEVENT9 = 12'h329,
381
- CSR_MHPMEVENT10 = 12'h32A,
382
- CSR_MHPMEVENT11 = 12'h32B,
383
- CSR_MHPMEVENT12 = 12'h32C,
384
- CSR_MHPMEVENT13 = 12'h32D,
385
- CSR_MHPMEVENT14 = 12'h32E,
386
- CSR_MHPMEVENT15 = 12'h32F,
387
- CSR_MHPMEVENT16 = 12'h330,
388
- CSR_MHPMEVENT17 = 12'h331,
389
- CSR_MHPMEVENT18 = 12'h332,
390
- CSR_MHPMEVENT19 = 12'h333,
391
- CSR_MHPMEVENT20 = 12'h334,
392
- CSR_MHPMEVENT21 = 12'h335,
393
- CSR_MHPMEVENT22 = 12'h336,
394
- CSR_MHPMEVENT23 = 12'h337,
395
- CSR_MHPMEVENT24 = 12'h338,
396
- CSR_MHPMEVENT25 = 12'h339,
397
- CSR_MHPMEVENT26 = 12'h33A,
398
- CSR_MHPMEVENT27 = 12'h33B,
399
- CSR_MHPMEVENT28 = 12'h33C,
400
- CSR_MHPMEVENT29 = 12'h33D,
401
- CSR_MHPMEVENT30 = 12'h33E,
402
- CSR_MHPMEVENT31 = 12'h33F,
403
- CSR_MCYCLE = 12'hB00,
404
- CSR_MINSTRET = 12'hB02,
405
- CSR_MHPMCOUNTER3 = 12'hB03,
406
- CSR_MHPMCOUNTER4 = 12'hB04,
407
- CSR_MHPMCOUNTER5 = 12'hB05,
408
- CSR_MHPMCOUNTER6 = 12'hB06,
409
- CSR_MHPMCOUNTER7 = 12'hB07,
410
- CSR_MHPMCOUNTER8 = 12'hB08,
411
- CSR_MHPMCOUNTER9 = 12'hB09,
412
- CSR_MHPMCOUNTER10 = 12'hB0A,
413
- CSR_MHPMCOUNTER11 = 12'hB0B,
414
- CSR_MHPMCOUNTER12 = 12'hB0C,
415
- CSR_MHPMCOUNTER13 = 12'hB0D,
416
- CSR_MHPMCOUNTER14 = 12'hB0E,
417
- CSR_MHPMCOUNTER15 = 12'hB0F,
418
- CSR_MHPMCOUNTER16 = 12'hB10,
419
- CSR_MHPMCOUNTER17 = 12'hB11,
420
- CSR_MHPMCOUNTER18 = 12'hB12,
421
- CSR_MHPMCOUNTER19 = 12'hB13,
422
- CSR_MHPMCOUNTER20 = 12'hB14,
423
- CSR_MHPMCOUNTER21 = 12'hB15,
424
- CSR_MHPMCOUNTER22 = 12'hB16,
425
- CSR_MHPMCOUNTER23 = 12'hB17,
426
- CSR_MHPMCOUNTER24 = 12'hB18,
427
- CSR_MHPMCOUNTER25 = 12'hB19,
428
- CSR_MHPMCOUNTER26 = 12'hB1A,
429
- CSR_MHPMCOUNTER27 = 12'hB1B,
430
- CSR_MHPMCOUNTER28 = 12'hB1C,
431
- CSR_MHPMCOUNTER29 = 12'hB1D,
432
- CSR_MHPMCOUNTER30 = 12'hB1E,
433
- CSR_MHPMCOUNTER31 = 12'hB1F,
434
- CSR_MCYCLEH = 12'hB80,
435
- CSR_MINSTRETH = 12'hB82,
436
- CSR_MHPMCOUNTER3H = 12'hB83,
437
- CSR_MHPMCOUNTER4H = 12'hB84,
438
- CSR_MHPMCOUNTER5H = 12'hB85,
439
- CSR_MHPMCOUNTER6H = 12'hB86,
440
- CSR_MHPMCOUNTER7H = 12'hB87,
441
- CSR_MHPMCOUNTER8H = 12'hB88,
442
- CSR_MHPMCOUNTER9H = 12'hB89,
443
- CSR_MHPMCOUNTER10H = 12'hB8A,
444
- CSR_MHPMCOUNTER11H = 12'hB8B,
445
- CSR_MHPMCOUNTER12H = 12'hB8C,
446
- CSR_MHPMCOUNTER13H = 12'hB8D,
447
- CSR_MHPMCOUNTER14H = 12'hB8E,
448
- CSR_MHPMCOUNTER15H = 12'hB8F,
449
- CSR_MHPMCOUNTER16H = 12'hB90,
450
- CSR_MHPMCOUNTER17H = 12'hB91,
451
- CSR_MHPMCOUNTER18H = 12'hB92,
452
- CSR_MHPMCOUNTER19H = 12'hB93,
453
- CSR_MHPMCOUNTER20H = 12'hB94,
454
- CSR_MHPMCOUNTER21H = 12'hB95,
455
- CSR_MHPMCOUNTER22H = 12'hB96,
456
- CSR_MHPMCOUNTER23H = 12'hB97,
457
- CSR_MHPMCOUNTER24H = 12'hB98,
458
- CSR_MHPMCOUNTER25H = 12'hB99,
459
- CSR_MHPMCOUNTER26H = 12'hB9A,
460
- CSR_MHPMCOUNTER27H = 12'hB9B,
461
- CSR_MHPMCOUNTER28H = 12'hB9C,
462
- CSR_MHPMCOUNTER29H = 12'hB9D,
463
- CSR_MHPMCOUNTER30H = 12'hB9E,
464
- CSR_MHPMCOUNTER31H = 12'hB9F,
465
- CSR_CPUCTRL = 12'h7C0,
466
- CSR_SECURESEED = 12'h7C1
467
- } csr_num_e;
468
- // CSR pmp-related offsets
469
- parameter logic [11:0] CSR_OFF_PMP_CFG = 12'h3A0; // pmp_cfg @ 12'h3a0 - 12'h3a3
470
- parameter logic [11:0] CSR_OFF_PMP_ADDR = 12'h3B0; // pmp_addr @ 12'h3b0 - 12'h3bf
471
- // CSR status bits
472
- parameter int unsigned CSR_MSTATUS_MIE_BIT = 3;
473
- parameter int unsigned CSR_MSTATUS_MPIE_BIT = 7;
474
- parameter int unsigned CSR_MSTATUS_MPP_BIT_LOW = 11;
475
- parameter int unsigned CSR_MSTATUS_MPP_BIT_HIGH = 12;
476
- parameter int unsigned CSR_MSTATUS_MPRV_BIT = 17;
477
- parameter int unsigned CSR_MSTATUS_TW_BIT = 21;
478
- // CSR machine ISA
479
- parameter logic [1:0] CSR_MISA_MXL = 2'd1; // M-XLEN: XLEN in M-Mode for RV32
480
- // CSR interrupt pending/enable bits
481
- parameter int unsigned CSR_MSIX_BIT = 3;
482
- parameter int unsigned CSR_MTIX_BIT = 7;
483
- parameter int unsigned CSR_MEIX_BIT = 11;
484
- parameter int unsigned CSR_MFIX_BIT_LOW = 16;
485
- parameter int unsigned CSR_MFIX_BIT_HIGH = 31;
486
- // CSR Machine Security Configuration bits
487
- parameter int unsigned CSR_MSECCFG_MML_BIT = 0;
488
- parameter int unsigned CSR_MSECCFG_MMWP_BIT = 1;
489
- parameter int unsigned CSR_MSECCFG_RLB_BIT = 2;
490
- // Machine Vendor ID - OpenHW JEDEC ID is '2 decimal (bank 13)'
491
- parameter MVENDORID_OFFSET = 7'h2; // Final byte without parity bit
492
- parameter MVENDORID_BANK = 25'hC; // Number of continuation codes
493
- // Machine Architecture ID (https://github.com/riscv/riscv-isa-manual/blob/master/marchid.md)
494
- parameter MARCHID = 32'd35;
495
- localparam logic [31:0] CSR_MVENDORID_VALUE = {MVENDORID_BANK, MVENDORID_OFFSET};
496
- localparam logic [31:0] CSR_MARCHID_VALUE = MARCHID;
497
- // Implementation ID
498
- // 0 indicates this field is not implemeted. cve2 implementors may wish to indicate an RTL/netlist
499
- // version here using their own unique encoding (e.g. 32 bits of the git hash of the implemented
500
- // commit).
501
- localparam logic [31:0] CSR_MIMPID_VALUE = 32'b0;
502
- // Machine Configuration Pointer
503
- // 0 indicates the configuration data structure does not eixst. cve2 implementors may wish to
504
- // alter this to point to their system specific configuration data structure.
505
- localparam logic [31:0] CSR_MCONFIGPTR_VALUE = 32'b0;
506
- // RVFI CSR element
507
- typedef struct packed {
508
- bit [63:0] rdata;
509
- bit [63:0] rmask;
510
- bit [63:0] wdata;
511
- bit [63:0] wmask;
512
- } rvfi_csr_elmt_t;
513
- // RVFI CSR structure
514
- typedef struct packed {
515
- rvfi_csr_elmt_t fflags;
516
- rvfi_csr_elmt_t frm;
517
- rvfi_csr_elmt_t fcsr;
518
- rvfi_csr_elmt_t ftran;
519
- rvfi_csr_elmt_t dcsr;
520
- rvfi_csr_elmt_t dpc;
521
- rvfi_csr_elmt_t dscratch0;
522
- rvfi_csr_elmt_t dscratch1;
523
- rvfi_csr_elmt_t sstatus;
524
- rvfi_csr_elmt_t sie;
525
- rvfi_csr_elmt_t sip;
526
- rvfi_csr_elmt_t stvec;
527
- rvfi_csr_elmt_t scounteren;
528
- rvfi_csr_elmt_t sscratch;
529
- rvfi_csr_elmt_t sepc;
530
- rvfi_csr_elmt_t scause;
531
- rvfi_csr_elmt_t stval;
532
- rvfi_csr_elmt_t satp;
533
- rvfi_csr_elmt_t mstatus;
534
- rvfi_csr_elmt_t mstatush;
535
- rvfi_csr_elmt_t misa;
536
- rvfi_csr_elmt_t medeleg;
537
- rvfi_csr_elmt_t mideleg;
538
- rvfi_csr_elmt_t mie;
539
- rvfi_csr_elmt_t mtvec;
540
- rvfi_csr_elmt_t mcounteren;
541
- rvfi_csr_elmt_t mscratch;
542
- rvfi_csr_elmt_t mepc;
543
- rvfi_csr_elmt_t mcause;
544
- rvfi_csr_elmt_t mtval;
545
- rvfi_csr_elmt_t mip;
546
- rvfi_csr_elmt_t menvcfg;
547
- rvfi_csr_elmt_t menvcfgh;
548
- rvfi_csr_elmt_t mvendorid;
549
- rvfi_csr_elmt_t marchid;
550
- rvfi_csr_elmt_t mhartid;
551
- rvfi_csr_elmt_t mcountinhibit;
552
- rvfi_csr_elmt_t mcycle;
553
- rvfi_csr_elmt_t mcycleh;
554
- rvfi_csr_elmt_t minstret;
555
- rvfi_csr_elmt_t minstreth;
556
- rvfi_csr_elmt_t cycle;
557
- rvfi_csr_elmt_t cycleh;
558
- rvfi_csr_elmt_t instret;
559
- rvfi_csr_elmt_t instreth;
560
- rvfi_csr_elmt_t dcache;
561
- rvfi_csr_elmt_t icache;
562
- rvfi_csr_elmt_t acc_cons;
563
- rvfi_csr_elmt_t pmpcfg0;
564
- rvfi_csr_elmt_t pmpcfg1;
565
- rvfi_csr_elmt_t pmpcfg2;
566
- rvfi_csr_elmt_t pmpcfg3;
567
- rvfi_csr_elmt_t pmpaddr0;
568
- rvfi_csr_elmt_t pmpaddr1;
569
- rvfi_csr_elmt_t pmpaddr2;
570
- rvfi_csr_elmt_t pmpaddr3;
571
- rvfi_csr_elmt_t pmpaddr4;
572
- rvfi_csr_elmt_t pmpaddr5;
573
- rvfi_csr_elmt_t pmpaddr6;
574
- rvfi_csr_elmt_t pmpaddr7;
575
- rvfi_csr_elmt_t pmpaddr8;
576
- rvfi_csr_elmt_t pmpaddr9;
577
- rvfi_csr_elmt_t pmpaddr10;
578
- rvfi_csr_elmt_t pmpaddr11;
579
- rvfi_csr_elmt_t pmpaddr12;
580
- rvfi_csr_elmt_t pmpaddr13;
581
- rvfi_csr_elmt_t pmpaddr14;
582
- rvfi_csr_elmt_t pmpaddr15;
583
- } rvfi_csr_t;
584
- // CV-X-IF
585
- parameter int unsigned X_NUM_RS = 3;
586
- parameter int unsigned X_ID_WIDTH = 4;
587
- parameter int unsigned X_RFR_WIDTH = 32;
588
- parameter int unsigned X_RFW_WIDTH = 32;
589
- parameter int unsigned X_HARTID_WIDTH = 32;
590
- parameter int unsigned X_DUAL_READ = 0;
591
- parameter int unsigned X_DUAL_WRITE = 0;
592
- parameter int unsigned X_INSTR_INFLIGHT = 2**X_ID_WIDTH;
593
- typedef logic [X_NUM_RS+X_DUAL_READ-1:0] readregflags_t;
594
- typedef logic [X_DUAL_WRITE:0] writeregflags_t;
595
- typedef logic [X_ID_WIDTH-1:0] id_t;
596
- typedef logic [X_HARTID_WIDTH-1:0] hartid_t;
597
- // Issue Interface
598
- typedef struct packed {
599
- logic [31:0] instr;
600
- hartid_t hartid;
601
- id_t id;
602
- } x_issue_req_t;
603
- typedef struct packed {
604
- logic accept;
605
- writeregflags_t writeback;
606
- readregflags_t register_read;
607
- } x_issue_resp_t;
608
- // Register Interface
609
- typedef struct packed {
610
- hartid_t hartid;
611
- id_t id;
612
- logic [X_NUM_RS-1:0][X_RFR_WIDTH-1:0] rs;
613
- readregflags_t rs_valid;
614
- } x_register_t;
615
- // Commit Interface
616
- typedef struct packed {
617
- hartid_t hartid;
618
- id_t id;
619
- logic commit_kill;
620
- } x_commit_t;
621
- // Result Interface
622
- typedef struct packed {
623
- hartid_t hartid;
624
- id_t id;
625
- logic [X_RFW_WIDTH-1:0] data;
626
- logic [4:0] rd;
627
- writeregflags_t we;
628
- } x_result_t;
629
- endpackage
630
- // Copyright (c) 2025 Eclipse Foundation
631
- // Copyright lowRISC contributors.
632
- // Copyright 2018 ETH Zurich and University of Bologna, see also CREDITS.md.
633
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
634
- // SPDX-License-Identifier: Apache-2.0
635
- /**
636
- * Main controller of the processor
637
- */
638
- // Copyright lowRISC contributors.
639
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
640
- // SPDX-License-Identifier: Apache-2.0
641
- // Macros and helper code for using assertions.
642
- // - Provides default clk and rst options to simplify code
643
- // - Provides boiler plate template for common assertions
644
- ///////////////////
645
- // Helper macros //
646
- ///////////////////
647
- // Default clk and reset signals used by assertion macros below.
648
- // Converts an arbitrary block of code into a Verilog string
649
- // ASSERT_ERROR logs an error message with either `uvm_error or with $error.
650
- //
651
- // This somewhat duplicates `DV_ERROR macro defined in hw/dv/sv/dv_utils/dv_macros.svh. The reason
652
- // for redefining it here is to avoid creating a dependency.
653
- // This macro is suitable for conditionally triggering lint errors, e.g., if a Sec parameter takes
654
- // on a non-default value. This may be required for pre-silicon/FPGA evaluation but we don't want
655
- // to allow this for tapeout.
656
- // The basic helper macros are actually defined in "implementation headers". The macros should do
657
- // the same thing in each case (except for the dummy flavour), but in a way that the respective
658
- // tools support.
659
- //
660
- // If the tool supports assertions in some form, we also define INC_ASSERT (which can be used to
661
- // hide signal definitions that are only used for assertions).
662
- //
663
- // The list of basic macros supported is:
664
- //
665
- // ASSERT_I: Immediate assertion. Note that immediate assertions are sensitive to simulation
666
- // glitches.
667
- //
668
- // ASSERT_INIT: Assertion in initial block. Can be used for things like parameter checking.
669
- //
670
- // ASSERT_INIT_NET: Assertion in initial block. Can be used for initial value of a net.
671
- //
672
- // ASSERT_FINAL: Assertion in final block. Can be used for things like queues being empty at end of
673
- // sim, all credits returned at end of sim, state machines in idle at end of sim.
674
- //
675
- // ASSERT: Assert a concurrent property directly. It can be called as a module (or
676
- // interface) body item.
677
- //
678
- // Note: We use (__rst !== '0) in the disable iff statements instead of (__rst ==
679
- // '1). This properly disables the assertion in cases when reset is X at the
680
- // beginning of a simulation. For that case, (reset == '1) does not disable the
681
- // assertion.
682
- //
683
- // ASSERT_NEVER: Assert a concurrent property NEVER happens
684
- //
685
- // ASSERT_KNOWN: Assert that signal has a known value (each bit is either '0' or '1') after reset.
686
- // It can be called as a module (or interface) body item.
687
- //
688
- // COVER: Cover a concurrent property
689
- //
690
- // ASSUME: Assume a concurrent property
691
- //
692
- // ASSUME_I: Assume an immediate property
693
- // Copyright lowRISC contributors.
694
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
695
- // SPDX-License-Identifier: Apache-2.0
696
- // Macro bodies included by prim_assert.sv for tools that don't support assertions. See
697
- // prim_assert.sv for documentation for each of the macros.
698
- //////////////////////////////
699
- // Complex assertion macros //
700
- //////////////////////////////
701
- // Assert that signal is an active-high pulse with pulse length of 1 clock cycle
702
- // Assert that a property is true only when an enable signal is set. It can be called as a module
703
- // (or interface) body item.
704
- // Assert that signal has a known value (each bit is either '0' or '1') after reset if enable is
705
- // set. It can be called as a module (or interface) body item.
706
- //////////////////////////////////
707
- // For formal verification only //
708
- //////////////////////////////////
709
- // Note that the existing set of ASSERT macros specified above shall be used for FPV,
710
- // thereby ensuring that the assertions are evaluated during DV simulations as well.
711
- // ASSUME_FPV
712
- // Assume a concurrent property during formal verification only.
713
- // ASSUME_I_FPV
714
- // Assume a concurrent property during formal verification only.
715
- // COVER_FPV
716
- // Cover a concurrent property during formal verification
717
- // Copyright lowRISC contributors.
718
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
719
- // SPDX-License-Identifier: Apache-2.0
720
- // // Macros and helper code for security countermeasures.
721
- // Helper macros
722
- // macros for security countermeasures
723
- // PRIM_ASSERT_SEC_CM_SVH
724
- // PRIM_ASSERT_SV
725
- // Copyright lowRISC contributors.
726
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
727
- // SPDX-License-Identifier: Apache-2.0
728
- // Include FCOV RTL by default. Disable it for synthesis and where explicitly requested (by defining
729
- // DV_FCOV_DISABLE).
730
- // Disable instantiations of FCOV coverpoints or covergroups.
731
- // Instantiates a covergroup in an interface or module.
732
- //
733
- // This macro assumes that a covergroup of the same name as the NAME_ arg is defined in the
734
- // interface or module. It just adds some extra signals and logic to control the creation of the
735
- // covergroup instance with ~bit en_<cg_name>~. This defaults to 0. It is ORed with the external
736
- // COND_ signal. The testbench can modify it at t = 0 based on the test being run.
737
- // NOTE: This is not meant to be invoked inside a class.
738
- //
739
- // NAME_ : Name of the covergroup.
740
- // COND_ : External condition / expr that controls the creation of the covergroup.
741
- // ARGS_ : Arguments to covergroup instance, if any. Args MUST BE wrapped in (..).
742
- // Creates a coverpoint for an expression where only the expression true case is of interest for
743
- // coverage (e.g. where the expression indicates an event has occured).
744
- // Creates a SVA cover that can be used in a covergroup.
745
- //
746
- // This macro creates an unnamed SVA cover from the property (or an expression) `PROP_` and an event
747
- // with the name `EV_NAME_`. When the SVA cover is hit, the event is triggered. A coverpoint can
748
- // cover the `triggered` property of the event.
749
- // Coverage support is not always available but it's useful to include extra fcov signals for
750
- // linting purposes. They need to be marked as unused to avoid warnings.
751
- // Define a signal and expression in the design for capture in functional coverage
752
- // Define a signal and expression in the design for capture in functional coverage depending on
753
- // design configuration. The input GEN_COND_ must be a constant or parameter.
754
- module cve2_controller #(
755
- ) (
756
- input logic clk_i,
757
- input logic rst_ni,
758
- input logic fetch_enable_i, // core can fetch instructions leave RESET state
759
- output logic ctrl_busy_o, // core is busy processing instrs
760
- // decoder related signals
761
- input logic illegal_insn_i, // decoder has an invalid instr
762
- input logic ecall_insn_i, // decoder has ECALL instr
763
- input logic mret_insn_i, // decoder has MRET instr
764
- input logic dret_insn_i, // decoder has DRET instr
765
- input logic wfi_insn_i, // decoder has WFI instr
766
- input logic ebrk_insn_i, // decoder has EBREAK instr
767
- input logic csr_pipe_flush_i, // do CSR-related pipeline flush
768
- input logic xif_scoreboard_busy_i, // tells if the the core is waiting for XIF
769
- // instr from IF-ID pipeline stage
770
- input logic instr_valid_i, // instr is valid
771
- input logic [31:0] instr_i, // uncompressed instr data for mtval
772
- input logic [15:0] instr_compressed_i, // instr compressed data for mtval
773
- input logic instr_is_compressed_i, // instr is compressed
774
- input logic instr_fetch_err_i, // instr has error
775
- input logic instr_fetch_err_plus2_i, // instr error is x32
776
- input logic [31:0] pc_id_i, // instr address
777
- // to IF-ID pipeline stage
778
- output logic instr_valid_clear_o, // kill instr in IF-ID reg
779
- output logic id_in_ready_o, // ID stage is ready for new instr
780
- output logic controller_run_o, // Controller is in standard instruction
781
- // run mode
782
- // to prefetcher
783
- output logic instr_req_o, // start fetching instructions
784
- output logic pc_set_o, // jump to address set by pc_mux
785
- output cve2_pkg::pc_sel_e pc_mux_o, // IF stage fetch address selector
786
- // (boot, normal, exception...)
787
- output cve2_pkg::exc_pc_sel_e exc_pc_mux_o, // IF stage selector for exception PC
788
- output cve2_pkg::exc_cause_e exc_cause_o, // for IF stage, CSRs
789
- // LSU
790
- input logic [31:0] lsu_addr_last_i, // for mtval
791
- input logic load_err_i,
792
- input logic store_err_i,
793
- // jump/branch signals
794
- input logic branch_set_i, // branch set signal (branch definitely
795
- // taken)
796
- input logic jump_set_i, // jump taken set signal
797
- // interrupt signals
798
- input logic csr_mstatus_mie_i, // M-mode interrupt enable bit
799
- input logic irq_pending_i, // interrupt request pending
800
- input cve2_pkg::irqs_t irqs_i, // interrupt requests qualified with
801
- // mie CSR
802
- input logic irq_nm_i, // non-maskeable interrupt
803
- output logic nmi_mode_o, // core executing NMI handler
804
- // debug signals
805
- input logic debug_req_i,
806
- output cve2_pkg::dbg_cause_e debug_cause_o,
807
- output logic debug_csr_save_o,
808
- output logic debug_mode_o,
809
- input logic debug_single_step_i,
810
- input logic debug_ebreakm_i,
811
- input logic debug_ebreaku_i,
812
- input logic trigger_match_i,
813
- output logic csr_save_if_o,
814
- output logic csr_save_id_o,
815
- output logic csr_restore_mret_id_o,
816
- output logic csr_restore_dret_id_o,
817
- output logic csr_save_cause_o,
818
- output logic [31:0] csr_mtval_o,
819
- input cve2_pkg::priv_lvl_e priv_mode_i,
820
- input logic csr_mstatus_tw_i,
821
- // stall & flush signals
822
- input logic stall_id_i,
823
- output logic flush_id_o,
824
- // performance monitors
825
- output logic perf_jump_o, // we are executing a jump
826
- // instruction (j, jr, jal, jalr)
827
- output logic perf_tbranch_o // we are executing a taken branch
828
- // instruction
829
- );
830
- import cve2_pkg::*;
831
- // FSM state encoding
832
- typedef enum logic [3:0] {
833
- RESET, BOOT_SET, WAIT_SLEEP, SLEEP, FIRST_FETCH, DECODE, FLUSH,
834
- IRQ_TAKEN, DBG_TAKEN_IF, DBG_TAKEN_ID
835
- } ctrl_fsm_e;
836
- ctrl_fsm_e ctrl_fsm_cs, ctrl_fsm_ns;
837
- logic nmi_mode_q, nmi_mode_d;
838
- logic debug_mode_q, debug_mode_d;
839
- logic load_err_q, load_err_d;
840
- logic store_err_q, store_err_d;
841
- logic exc_req_q, exc_req_d;
842
- logic illegal_insn_q, illegal_insn_d;
843
- // Of the various exception/fault signals, which one takes priority in FLUSH and hence controls
844
- // what happens next (setting exc_cause, csr_mtval etc)
845
- logic instr_fetch_err_prio;
846
- logic illegal_insn_prio;
847
- logic ecall_insn_prio;
848
- logic ebrk_insn_prio;
849
- logic store_err_prio;
850
- logic load_err_prio;
851
- logic stall;
852
- logic halt_if;
853
- logic retain_id;
854
- logic flush_id;
855
- logic illegal_dret;
856
- logic illegal_umode;
857
- logic exc_req_lsu;
858
- logic special_req;
859
- logic special_req_pc_change;
860
- logic special_req_flush_only;
861
- logic do_single_step_d;
862
- logic do_single_step_q;
863
- logic enter_debug_mode_prio_d;
864
- logic enter_debug_mode_prio_q;
865
- logic enter_debug_mode;
866
- logic ebreak_into_debug;
867
- logic handle_irq;
868
- logic [3:0] mfip_id;
869
- logic unused_irq_timer;
870
- logic ecall_insn;
871
- logic mret_insn;
872
- logic dret_insn;
873
- logic wfi_insn;
874
- logic ebrk_insn;
875
- logic csr_pipe_flush;
876
- logic instr_fetch_err;
877
- ////////////////
878
- // Exceptions //
879
- ////////////////
880
- assign load_err_d = load_err_i;
881
- assign store_err_d = store_err_i;
882
- // Decoder doesn't take instr_valid into account, factor it in here.
883
- assign ecall_insn = ecall_insn_i & instr_valid_i;
884
- assign mret_insn = mret_insn_i & instr_valid_i;
885
- assign dret_insn = dret_insn_i & instr_valid_i;
886
- assign wfi_insn = wfi_insn_i & instr_valid_i;
887
- assign ebrk_insn = ebrk_insn_i & instr_valid_i;
888
- assign csr_pipe_flush = csr_pipe_flush_i & instr_valid_i;
889
- assign instr_fetch_err = instr_fetch_err_i & instr_valid_i;
890
- // "Executing DRET outside of Debug Mode causes an illegal instruction exception."
891
- // [Debug Spec v0.13.2, p.41]
892
- assign illegal_dret = dret_insn & ~debug_mode_q;
893
- // Some instructions can only be executed in M-Mode
894
- assign illegal_umode = (priv_mode_i != PRIV_LVL_M) &
895
- // MRET must be in M-Mode. TW means trap WFI to M-Mode.
896
- (mret_insn | (csr_mstatus_tw_i & wfi_insn));
897
- // This is recorded in the illegal_insn_q flop to help timing. Specifically
898
- // it is needed to break the path from cve2_cs_registers/illegal_csr_insn_o
899
- // to pc_set_o. Clear when controller is in FLUSH so it won't remain set
900
- // once illegal instruction is handled.
901
- // All terms in this expression are qualified by instr_valid_i
902
- assign illegal_insn_d = (illegal_insn_i | illegal_dret | illegal_umode) & (ctrl_fsm_cs != FLUSH);
903
- // exception requests
904
- // requests are flopped in exc_req_q. This is cleared when controller is in
905
- // the FLUSH state so the cycle following exc_req_q won't remain set for an
906
- // exception request that has just been handled.
907
- // All terms in this expression are qualified by instr_valid_i
908
- assign exc_req_d = (ecall_insn | ebrk_insn | illegal_insn_d | instr_fetch_err) &
909
- (ctrl_fsm_cs != FLUSH);
910
- // LSU exception requests
911
- assign exc_req_lsu = store_err_i | load_err_i;
912
- // special requests: special instructions, pipeline flushes, exceptions...
913
- // All terms in these expressions are qualified by instr_valid_i except exc_req_lsu which can come
914
- // from the Writeback stage with no instr_valid_i from the ID stage
915
- // These special requests only cause a pipeline flush and in particular don't cause a PC change
916
- // that is outside the normal execution flow
917
- assign special_req_flush_only = wfi_insn | csr_pipe_flush;
918
- // These special requests cause a change in PC
919
- assign special_req_pc_change = mret_insn | dret_insn | exc_req_d | exc_req_lsu;
920
- // generic special request signal, applies to all instructions
921
- assign special_req = special_req_pc_change | special_req_flush_only;
922
- // Exception/fault prioritisation is taken from Table 3.7 of Priviledged Spec v1.11
923
- always_comb begin
924
- instr_fetch_err_prio = 0;
925
- illegal_insn_prio = 0;
926
- ecall_insn_prio = 0;
927
- ebrk_insn_prio = 0;
928
- store_err_prio = 0;
929
- load_err_prio = 0;
930
- if (instr_fetch_err) begin
931
- instr_fetch_err_prio = 1'b1;
932
- end else if (illegal_insn_q) begin
933
- illegal_insn_prio = 1'b1;
934
- end else if (ecall_insn) begin
935
- ecall_insn_prio = 1'b1;
936
- end else if (ebrk_insn) begin
937
- ebrk_insn_prio = 1'b1;
938
- end else if (store_err_q) begin
939
- store_err_prio = 1'b1;
940
- end else if (load_err_q) begin
941
- load_err_prio = 1'b1;
942
- end
943
- end
944
- ////////////////
945
- // Interrupts //
946
- ////////////////
947
- // Enter debug mode due to an external debug_req_i or because the core is in
948
- // single step mode (dcsr.step == 1). Single step must be qualified with
949
- // instruction valid otherwise the core will immediately enter debug mode
950
- // due to a recently flushed IF (or a delay in an instruction returning from
951
- // memory) before it has had anything to single step.
952
- // Also enter debug mode on a trigger match (hardware breakpoint)
953
- // Set `do_single_step_q` when a valid instruction is seen outside of debug mode and core is in
954
- // single step mode. The first valid instruction on debug mode entry will clear it. Hold its value
955
- // when there is no valid instruction so `do_single_step_d` remains asserted until debug mode is
956
- // entered.
957
- assign do_single_step_d = instr_valid_i ? ~debug_mode_q & debug_single_step_i : do_single_step_q;
958
- // Enter debug mode due to:
959
- // * external `debug_req_i`
960
- // * core in single step mode (dcsr.step == 1).
961
- // * trigger match (hardware breakpoint)
962
- //
963
- // `debug_req_i` and `do_single_step_d` request debug mode with priority. This results in a debug
964
- // mode entry even if the controller goes to `FLUSH` in preparation for handling an exception or
965
- // interrupt. `trigger_match_i` is not a priority entry into debug mode as it must be ignored
966
- // where control flow changes such that the instruction causing the trigger is no longer being
967
- // executed.
968
- assign enter_debug_mode_prio_d = (debug_req_i | do_single_step_d) & ~debug_mode_q;
969
- assign enter_debug_mode = enter_debug_mode_prio_d | (trigger_match_i & ~debug_mode_q);
970
- // Set when an ebreak should enter debug mode rather than jump to exception
971
- // handler
972
- assign ebreak_into_debug = priv_mode_i == PRIV_LVL_M ? debug_ebreakm_i :
973
- priv_mode_i == PRIV_LVL_U ? debug_ebreaku_i :
974
- 1'b0;
975
- // Interrupts including NMI are ignored,
976
- // - while in debug mode [Debug Spec v0.13.2, p.39],
977
- // - while in NMI mode (nested NMIs are not supported, NMI has highest priority and
978
- // cannot be interrupted by regular interrupts).
979
- // - while single stepping.
980
- assign handle_irq = ~debug_mode_q & ~nmi_mode_q &
981
- (irq_nm_i | (irq_pending_i & csr_mstatus_mie_i));
982
- // generate ID of fast interrupts, highest priority to lowest ID
983
- always_comb begin : gen_mfip_id
984
- mfip_id = 4'd0;
985
- for (int i = 15; i >= 0; i--) begin
986
- if (irqs_i.irq_fast[i]) begin
987
- mfip_id = i[3:0];
988
- end
989
- end
990
- end
991
- assign unused_irq_timer = irqs_i.irq_timer;
992
- /////////////////////
993
- // Core controller //
994
- /////////////////////
995
- always_comb begin
996
- // Default values
997
- instr_req_o = 1'b1;
998
- csr_save_if_o = 1'b0;
999
- csr_save_id_o = 1'b0;
1000
- csr_restore_mret_id_o = 1'b0;
1001
- csr_restore_dret_id_o = 1'b0;
1002
- csr_save_cause_o = 1'b0;
1003
- csr_mtval_o = '0;
1004
- // The values of pc_mux and exc_pc_mux are only relevant if pc_set is set. Some of the states
1005
- // below always set pc_mux and exc_pc_mux but only set pc_set if certain conditions are met.
1006
- // This avoid having to factor those conditions into the pc_mux and exc_pc_mux select signals
1007
- // helping timing.
1008
- pc_mux_o = PC_BOOT;
1009
- pc_set_o = 1'b0;
1010
- exc_pc_mux_o = EXC_PC_IRQ;
1011
- exc_cause_o = EXC_CAUSE_INSN_ADDR_MISA; // = 6'h00
1012
- ctrl_fsm_ns = ctrl_fsm_cs;
1013
- ctrl_busy_o = 1'b1;
1014
- halt_if = 1'b0;
1015
- retain_id = 1'b0;
1016
- flush_id = 1'b0;
1017
- debug_csr_save_o = 1'b0;
1018
- debug_cause_o = DBG_CAUSE_EBREAK;
1019
- debug_mode_d = debug_mode_q;
1020
- nmi_mode_d = nmi_mode_q;
1021
- perf_tbranch_o = 1'b0;
1022
- perf_jump_o = 1'b0;
1023
- controller_run_o = 1'b0;
1024
- unique case (ctrl_fsm_cs)
1025
- RESET: begin
1026
- instr_req_o = 1'b0;
1027
- pc_mux_o = PC_BOOT;
1028
- pc_set_o = 1'b1;
1029
- if (fetch_enable_i == 1'b1)
1030
- begin
1031
- ctrl_fsm_ns = BOOT_SET;
1032
- end
1033
- end
1034
- BOOT_SET: begin
1035
- // copy boot address to instr fetch address
1036
- instr_req_o = 1'b1;
1037
- pc_mux_o = PC_BOOT;
1038
- pc_set_o = 1'b1;
1039
- ctrl_fsm_ns = FIRST_FETCH;
1040
- end
1041
- WAIT_SLEEP: begin
1042
- ctrl_busy_o = 1'b0;
1043
- instr_req_o = 1'b0;
1044
- halt_if = 1'b1;
1045
- flush_id = 1'b1;
1046
- ctrl_fsm_ns = SLEEP;
1047
- end
1048
- SLEEP: begin
1049
- // instruction in IF stage is already valid
1050
- // we begin execution when an interrupt has arrived
1051
- instr_req_o = 1'b0;
1052
- halt_if = 1'b1;
1053
- flush_id = 1'b1;
1054
- // normal execution flow
1055
- // in debug mode or single step mode we leave immediately (wfi=nop)
1056
- if (irq_nm_i || irq_pending_i || debug_req_i || debug_mode_q || debug_single_step_i) begin
1057
- ctrl_fsm_ns = FIRST_FETCH;
1058
- end else begin
1059
- // Make sure clock remains disabled.
1060
- ctrl_busy_o = 1'b0;
1061
- end
1062
- end
1063
- FIRST_FETCH: begin
1064
- // Stall because of IF miss
1065
- if (id_in_ready_o) begin
1066
- ctrl_fsm_ns = DECODE;
1067
- end
1068
- // handle interrupts
1069
- if (handle_irq) begin
1070
- // We are handling an interrupt. Set halt_if to tell IF not to give
1071
- // us any more instructions before it redirects to the handler, but
1072
- // don't set flush_id: we must allow this instruction to complete
1073
- // (since it might have outstanding loads or stores).
1074
- ctrl_fsm_ns = IRQ_TAKEN;
1075
- halt_if = 1'b1;
1076
- end
1077
- // enter debug mode
1078
- if (enter_debug_mode) begin
1079
- ctrl_fsm_ns = DBG_TAKEN_IF;
1080
- // Halt IF only for now, ID will be flushed in DBG_TAKEN_IF as the
1081
- // ID state is needed for correct debug mode entry
1082
- halt_if = 1'b1;
1083
- end
1084
- end
1085
- DECODE: begin
1086
- // normal operating mode of the ID stage, in case of debug and interrupt requests,
1087
- // priorities are as follows (lower number == higher priority)
1088
- // 1. currently running (multicycle) instructions and exceptions caused by these
1089
- // 2. debug requests
1090
- // 3. interrupt requests
1091
- controller_run_o = 1'b1;
1092
- // Set PC mux for branch and jump here to ease timing. Value is only relevant if pc_set_o is
1093
- // also set. Setting the mux value here avoids factoring in special_req and instr_valid_i
1094
- // which helps timing.
1095
- pc_mux_o = PC_JUMP;
1096
- // Get ready for special instructions, exceptions, pipeline flushes
1097
- if (special_req) begin
1098
- // Halt IF but don't flush ID. This leaves a valid instruction in
1099
- // ID so controller can determine appropriate action in the
1100
- // FLUSH state.
1101
- retain_id = 1'b1;
1102
- // The FSM will always go directly to FLUSH.
1103
- // when X-IF is active and xif_scoreboard_busy_i, wait the scoreboard to be empty before switching state
1104
- ctrl_fsm_ns = xif_scoreboard_busy_i ? DECODE: FLUSH;
1105
- end
1106
- if (branch_set_i || jump_set_i) begin
1107
- pc_set_o = 1'b1;
1108
- perf_tbranch_o = branch_set_i;
1109
- perf_jump_o = jump_set_i;
1110
- end
1111
- // If entering debug mode or handling an IRQ the core needs to wait until any instruction in
1112
- // ID has finished executing. Stall IF during that time.
1113
- if ((enter_debug_mode || handle_irq) && (stall || instr_valid_i)) begin
1114
- halt_if = 1'b1;
1115
- end
1116
- if (!stall && !special_req && !instr_valid_i) begin
1117
- if (enter_debug_mode) begin
1118
- // enter debug mode
1119
- ctrl_fsm_ns = xif_scoreboard_busy_i ? DECODE : DBG_TAKEN_IF;
1120
- // Halt IF only for now, ID will be flushed in DBG_TAKEN_IF as the
1121
- // ID state is needed for correct debug mode entry
1122
- halt_if = 1'b1;
1123
- end else if (handle_irq) begin
1124
- // handle interrupt (not in debug mode)
1125
- ctrl_fsm_ns = xif_scoreboard_busy_i ? DECODE : IRQ_TAKEN;
1126
- // We are handling an interrupt (not in debug mode). Set halt_if to
1127
- // tell IF not to give us any more instructions before it redirects
1128
- // to the handler, but don't set flush_id: we must allow this
1129
- // instruction to complete (since it might have outstanding loads
1130
- // or stores).
1131
- halt_if = 1'b1;
1132
- end
1133
- end
1134
- end // DECODE
1135
- IRQ_TAKEN: begin
1136
- pc_mux_o = PC_EXC;
1137
- exc_pc_mux_o = EXC_PC_IRQ;
1138
- if (handle_irq) begin
1139
- pc_set_o = 1'b1;
1140
- csr_save_if_o = 1'b1;
1141
- csr_save_cause_o = 1'b1;
1142
- // interrupt priorities according to Privileged Spec v1.11 p.31
1143
- if (irq_nm_i && !nmi_mode_q) begin
1144
- exc_cause_o = EXC_CAUSE_IRQ_NM;
1145
- nmi_mode_d = 1'b1; // enter NMI mode
1146
- end else if (irqs_i.irq_fast != 16'b0) begin
1147
- // generate exception cause ID from fast interrupt ID:
1148
- // - first bit distinguishes interrupts from exceptions,
1149
- // - third bit adds 16 to fast interrupt ID so that the interrup 0 becomes 16 and the interrupt 15 becomes 31 (hence 5bits)
1150
- // - second bit is always 0 as the FAST interrupts are represented in the first 5bits, the 6th is always 0 cause is used by the NMI (in that case is 1 as represented by the number 32)
1151
- // for example EXC_CAUSE_IRQ_FAST_0 = {1'b1, 6'd16}
1152
- exc_cause_o = exc_cause_e'({3'b101, mfip_id});
1153
- end else if (irqs_i.irq_external) begin
1154
- exc_cause_o = EXC_CAUSE_IRQ_EXTERNAL_M;
1155
- end else if (irqs_i.irq_software) begin
1156
- exc_cause_o = EXC_CAUSE_IRQ_SOFTWARE_M;
1157
- end else begin // irqs_i.irq_timer
1158
- exc_cause_o = EXC_CAUSE_IRQ_TIMER_M;
1159
- end
1160
- end
1161
- ctrl_fsm_ns = DECODE;
1162
- end
1163
- DBG_TAKEN_IF: begin
1164
- pc_mux_o = PC_EXC;
1165
- exc_pc_mux_o = EXC_PC_DBD;
1166
- // enter debug mode and save PC in IF to dpc
1167
- // jump to debug exception handler in debug memory
1168
- flush_id = 1'b1;
1169
- pc_set_o = 1'b1;
1170
- csr_save_if_o = 1'b1;
1171
- debug_csr_save_o = 1'b1;
1172
- csr_save_cause_o = 1'b1;
1173
- if (trigger_match_i) begin
1174
- debug_cause_o = DBG_CAUSE_TRIGGER; // (priority 4)
1175
- end else if (debug_req_i) begin
1176
- debug_cause_o = DBG_CAUSE_HALTREQ; // (priority 1)
1177
- end else begin
1178
- debug_cause_o = DBG_CAUSE_STEP; // (priority 0, lowest)
1179
- end
1180
- // enter debug mode
1181
- debug_mode_d = 1'b1;
1182
- ctrl_fsm_ns = DECODE;
1183
- end
1184
- DBG_TAKEN_ID: begin
1185
- // enter debug mode and save PC in ID to dpc, used when encountering
1186
- // 1. EBREAK during debug mode
1187
- // 2. EBREAK with forced entry into debug mode (ebreakm or ebreaku set).
1188
- // regular ebreak's go through FLUSH.
1189
- //
1190
- // for 1. do not update dcsr and dpc, for 2. do so [Debug Spec v0.13.2, p.39]
1191
- // jump to debug exception handler in debug memory
1192
- flush_id = 1'b1;
1193
- pc_mux_o = PC_EXC;
1194
- pc_set_o = 1'b1;
1195
- exc_pc_mux_o = EXC_PC_DBD;
1196
- // update dcsr and dpc
1197
- if (ebreak_into_debug && !debug_mode_q) begin // ebreak with forced entry
1198
- // dpc (set to the address of the EBREAK, i.e. set to PC in ID stage)
1199
- csr_save_cause_o = 1'b1;
1200
- csr_save_id_o = 1'b1;
1201
- // dcsr
1202
- debug_csr_save_o = 1'b1;
1203
- debug_cause_o = DBG_CAUSE_EBREAK;
1204
- end
1205
- // enter debug mode
1206
- debug_mode_d = 1'b1;
1207
- ctrl_fsm_ns = DECODE;
1208
- end
1209
- FLUSH: begin
1210
- // flush the pipeline
1211
- halt_if = 1'b1;
1212
- flush_id = 1'b1;
1213
- ctrl_fsm_ns = DECODE;
1214
- // As pc_mux and exc_pc_mux can take various values in this state they aren't set early
1215
- // here.
1216
- // exceptions: set exception PC, save PC and exception cause
1217
- // exc_req_lsu is high for one clock cycle only (in DECODE)
1218
- if (exc_req_q || store_err_q || load_err_q) begin
1219
- pc_set_o = 1'b1;
1220
- pc_mux_o = PC_EXC;
1221
- exc_pc_mux_o = debug_mode_q ? EXC_PC_DBG_EXC : EXC_PC_EXC;
1222
- begin : g_no_writeback_mepc_save
1223
- csr_save_id_o = 1'b0;
1224
- end
1225
- csr_save_cause_o = 1'b1;
1226
- // Exception/fault prioritisation logic will have set exactly 1 X_prio signal
1227
- unique case (1'b1)
1228
- instr_fetch_err_prio: begin
1229
- exc_cause_o = EXC_CAUSE_INSTR_ACCESS_FAULT;
1230
- csr_mtval_o = instr_fetch_err_plus2_i ? (pc_id_i + 32'd2) : pc_id_i;
1231
- end
1232
- illegal_insn_prio: begin
1233
- exc_cause_o = EXC_CAUSE_ILLEGAL_INSN;
1234
- csr_mtval_o = instr_is_compressed_i ? {16'b0, instr_compressed_i} : instr_i;
1235
- end
1236
- ecall_insn_prio: begin
1237
- exc_cause_o = (priv_mode_i == PRIV_LVL_M) ? EXC_CAUSE_ECALL_MMODE :
1238
- EXC_CAUSE_ECALL_UMODE;
1239
- end
1240
- ebrk_insn_prio: begin
1241
- if (debug_mode_q | ebreak_into_debug) begin
1242
- /*
1243
- * EBREAK in debug mode re-enters debug mode
1244
- *
1245
- * "The only exception is EBREAK. When that is executed in Debug
1246
- * Mode, it halts the hart again but without updating dpc or
1247
- * dcsr." [Debug Spec v0.13.2, p.39]
1248
- */
1249
- /*
1250
- * dcsr.ebreakm == 1:
1251
- * "EBREAK instructions in M-mode enter Debug Mode."
1252
- * [Debug Spec v0.13.2, p.42]
1253
- */
1254
- pc_set_o = 1'b0;
1255
- csr_save_id_o = 1'b0;
1256
- csr_save_cause_o = 1'b0;
1257
- ctrl_fsm_ns = DBG_TAKEN_ID;
1258
- flush_id = 1'b0;
1259
- end else begin
1260
- /*
1261
- * "The EBREAK instruction is used by debuggers to cause control
1262
- * to be transferred back to a debugging environment. It
1263
- * generates a breakpoint exception and performs no other
1264
- * operation. [...] ECALL and EBREAK cause the receiving
1265
- * privilege mode's epc register to be set to the address of the
1266
- * ECALL or EBREAK instruction itself, not the address of the
1267
- * following instruction." [Privileged Spec v1.11, p.40]
1268
- */
1269
- exc_cause_o = EXC_CAUSE_BREAKPOINT;
1270
- end
1271
- end
1272
- store_err_prio: begin
1273
- exc_cause_o = EXC_CAUSE_STORE_ACCESS_FAULT;
1274
- csr_mtval_o = lsu_addr_last_i;
1275
- end
1276
- load_err_prio: begin
1277
- exc_cause_o = EXC_CAUSE_LOAD_ACCESS_FAULT;
1278
- csr_mtval_o = lsu_addr_last_i;
1279
- end
1280
- default: ;
1281
- endcase
1282
- end else begin
1283
- // special instructions and pipeline flushes
1284
- if (mret_insn) begin
1285
- pc_mux_o = PC_ERET;
1286
- pc_set_o = 1'b1;
1287
- csr_restore_mret_id_o = 1'b1;
1288
- if (nmi_mode_q) begin
1289
- nmi_mode_d = 1'b0; // exit NMI mode
1290
- end
1291
- end else if (dret_insn) begin
1292
- pc_mux_o = PC_DRET;
1293
- pc_set_o = 1'b1;
1294
- debug_mode_d = 1'b0;
1295
- csr_restore_dret_id_o = 1'b1;
1296
- end else if (wfi_insn) begin
1297
- ctrl_fsm_ns = WAIT_SLEEP;
1298
- end
1299
- end // exc_req_q
1300
- // Entering debug mode due to either single step or debug_req. Ensure
1301
- // registers are set for exception but then enter debug handler rather
1302
- // than exception handler [Debug Spec v0.13.2, p.44]
1303
- // Leave all other signals as is to ensure CSRs and PC get set as if
1304
- // core was entering exception handler, entry to debug mode will then
1305
- // see the appropriate state and setup dpc correctly.
1306
- // If an EBREAK instruction is causing us to enter debug mode on the
1307
- // same cycle as a debug_req or single step, honor the EBREAK and
1308
- // proceed to DBG_TAKEN_ID, as it has the highest priority.
1309
- // [Debug Spec v1.0.0-STABLE, p.53]
1310
- // cause==EBREAK -> prio 3 (highest)
1311
- // cause==debug_req -> prio 2
1312
- // cause==step -> prio 1 (lowest)
1313
- if (enter_debug_mode_prio_q && !(ebrk_insn_prio && ebreak_into_debug)) begin
1314
- ctrl_fsm_ns = DBG_TAKEN_IF;
1315
- end
1316
- end // FLUSH
1317
- default: begin
1318
- instr_req_o = 1'b0;
1319
- ctrl_fsm_ns = RESET;
1320
- end
1321
- endcase
1322
- end
1323
- assign flush_id_o = flush_id;
1324
- // signal to CSR when in debug mode
1325
- assign debug_mode_o = debug_mode_q;
1326
- // signal to CSR when in an NMI handler (for nested exception handling)
1327
- assign nmi_mode_o = nmi_mode_q;
1328
- ///////////////////
1329
- // Stall control //
1330
- ///////////////////
1331
- // If high current instruction cannot complete this cycle. Either because it needs more cycles to
1332
- // finish (stall_id_i)
1333
- assign stall = stall_id_i;
1334
- // signal to IF stage that ID stage is ready for next instr
1335
- assign id_in_ready_o = ~stall & ~halt_if & ~retain_id;
1336
- // kill instr in IF-ID pipeline reg that are done, or if a
1337
- // multicycle instr causes an exception for example
1338
- // retain_id is another kind of stall, where the instr_valid bit must remain
1339
- // set (unless flush_id is set also). It cannot be factored directly into
1340
- // stall as this causes a combinational loop.
1341
- assign instr_valid_clear_o = ~(stall | retain_id) | flush_id;
1342
- // update registers
1343
- always_ff @(posedge clk_i or negedge rst_ni) begin : update_regs
1344
- if (!rst_ni) begin
1345
- ctrl_fsm_cs <= RESET;
1346
- nmi_mode_q <= 1'b0;
1347
- do_single_step_q <= 1'b0;
1348
- debug_mode_q <= 1'b0;
1349
- enter_debug_mode_prio_q <= 1'b0;
1350
- load_err_q <= 1'b0;
1351
- store_err_q <= 1'b0;
1352
- exc_req_q <= 1'b0;
1353
- illegal_insn_q <= 1'b0;
1354
- end else begin
1355
- ctrl_fsm_cs <= ctrl_fsm_ns;
1356
- nmi_mode_q <= nmi_mode_d;
1357
- do_single_step_q <= do_single_step_d;
1358
- debug_mode_q <= debug_mode_d;
1359
- enter_debug_mode_prio_q <= enter_debug_mode_prio_d;
1360
- load_err_q <= load_err_d;
1361
- store_err_q <= store_err_d;
1362
- exc_req_q <= exc_req_d;
1363
- illegal_insn_q <= illegal_insn_d;
1364
- end
1365
- end
1366
- //////////
1367
- // FCOV //
1368
- //////////
1369
- ////////////////
1370
- // Assertions //
1371
- ////////////////
1372
- // Selectors must be known/valid.
1373
- endmodule
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p4/mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"conditional_statement": [[44228, 44418], [41957, 42066], [49830, 49926], [44848, 45152], [33999, 34420], [34358, 34420], [39324, 39563], [34153, 34420], [45843, 46178], [51103, 51229], [34078, 34420], [41144, 41611]], "blocking_assignment": [[43423, 43460], [45776, 45803], [47409, 47485], [43188, 43212], [39155, 39176], [49788, 49817], [38461, 38482], [41040, 41059], [38109, 38151]], "always_construct": [[52316, 53219], [37116, 51354], [36818, 36995], [33783, 34428]], "case_statement": [[47090, 49579], [38345, 51348]], "ansi_port_declaration": [[26203, 26276], [29197, 29238], [26279, 26355], [25862, 25934], [28881, 28933], [25008, 25096], [27277, 27353], [26911, 26998], [28486, 28529]], "continuous_assign": [[35983, 36069], [31721, 31769], [31542, 31601], [36163, 36373], [33624, 33692], [51764, 51790], [52230, 52291]], "parameter_declaration": [[16946, 16990], [16850, 16895], [16993, 17037], [13622, 13688], [13551, 13619], [16898, 16943], [16755, 16799], [16708, 16752]], "nonblocking_assignment": [[52970, 53021], [53119, 53156], [53073, 53112], [52827, 52865], [53028, 53066], [52872, 52916], [52781, 52820], [53163, 53205], [52923, 52963]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p5/all_mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"module_program_interface_instantiation": [[55085, 55344], [55357, 55597], [55867, 56116], [56133, 56392], [56407, 56654], [56668, 56912], [56926, 57150], [57319, 57586], [57599, 57839], [57857, 58119], [58137, 58399], [58491, 58774], [58793, 59053], [59074, 59339], [66071, 66393], [67160, 67514], [68349, 68656], [71469, 71809], [71826, 72189], [73359, 73821], [77311, 77594], [77673, 78002], [78009, 78331]], "continuous_assign": [[23385, 23412], [23683, 23724], [23762, 23787], [24835, 24917], [25786, 25841], [25846, 25894], [25952, 26009], [26060, 26108], [26121, 26169], [26174, 26249], [26288, 26325], [26383, 26422], [26473, 26503], [26520, 26551], [35926, 35969], [36061, 36102], [36105, 36147], [36150, 36192], [36263, 36322], [36325, 36390], [36393, 36489], [36576, 36617], [36620, 36658], [36661, 36702], [36705, 36742], [53365, 53400], [53469, 53538], [53907, 53982], [54029, 54093], [54096, 54131], [54170, 54198], [54201, 54229], [54232, 54261], [54264, 54307], [54310, 54352], [54355, 54396], [54399, 54443], [54446, 54490], [54642, 54677], [54680, 54711], [55609, 55665], [55668, 55724], [55727, 55783], [55786, 55864], [62917, 63072], [63351, 63390], [64404, 64434], [64443, 64473], [64699, 64834], [64930, 64995], [65579, 65644], [65814, 65994], [66001, 66064], [66512, 66576], [66742, 66970], [67010, 67143], [67521, 67559], [67566, 67620], [67633, 67696], [67758, 67849], [67854, 67946], [68068, 68114], [68252, 68344], [68661, 68696], [68855, 68885], [68892, 68922], [69002, 69046], [69053, 69083], [69096, 69120], [69129, 69168], [72808, 72845], [72863, 72901], [72904, 72957], [72960, 73014], [73017, 73072], [74039, 74143], [74307, 74349], [74358, 74408], [74456, 74485], [74737, 74807], [74848, 74917], [74922, 74992], [74997, 75068], [75113, 75152], [76276, 76352], [76430, 76587], [76594, 76751], [76958, 77129], [77195, 77238], [77243, 77289], [78542, 78605], [78676, 78737], [78744, 78803], [78858, 78911], [78918, 78969], [79035, 80553], [80599, 80649], [80849, 80934], [80947, 80987], [81031, 81065], [81070, 81104], [81109, 81143], [81148, 81182]], "blocking_assignment": [[24967, 25001], [25006, 25043], [25048, 25084], [25120, 25156], [25163, 25199], [25256, 25299], [25344, 25386], [25412, 25450], [36783, 36802], [36807, 36828], [36933, 36969], [37042, 37076], [37157, 37190], [37254, 37280], [37363, 37400], [37483, 37552], [37561, 37641], [37650, 37731], [37740, 37820], [37829, 37910], [37919, 37998], [38117, 38136], [38299, 38318], [38349, 38376], [38432, 38487], [38496, 38567], [38576, 38644], [38653, 38724], [38733, 38800], [38891, 38910], [38941, 38968], [39027, 39051], [39109, 39132], [39184, 39236], [39281, 39305], [39367, 39422], [39431, 39500], [39509, 39575], [39584, 39653], [39662, 39727], [39802, 39843], [39854, 39908], [39919, 39974], [39985, 40039], [40073, 40092], [40180, 40199], [40233, 40252], [40319, 40448], [40470, 40599], [40621, 40751], [40773, 40904], [40926, 40960], [40982, 41016], [41038, 41072], [41094, 41128], [41150, 41184], [41206, 41240], [41262, 41296], [41318, 41352], [41374, 41408], [41430, 41464], [41486, 41521], [41543, 41578], [41600, 41635], [41657, 41692], [41714, 41749], [41771, 41806], [41837, 41860], [41869, 41897], [41937, 41960], [41969, 41997], [42043, 42071], [42080, 42108], [42154, 42182], [42191, 42219], [42287, 42317], [42871, 42914], [43574, 43625], [44316, 44368], [44436, 44466], [44475, 44505], [44548, 44585], [44594, 44624], [44667, 44702], [44711, 44741], [44784, 44803], [44812, 44842], [44887, 44906], [44915, 44945], [44990, 45009], [45018, 45048], [45152, 45171], [45211, 45230], [45725, 45744], [45810, 45833], [45838, 45864], [45869, 45889], [45894, 45919], [45924, 45944], [45949, 45969], [45974, 45994], [45999, 46042], [46047, 46067], [46072, 46127], [46132, 46152], [46157, 46186], [46191, 46223], [46305, 46447], [46452, 46472], [46477, 46499], [46504, 46547], [46552, 46572], [46577, 46597], [46602, 46622], [46627, 46649], [46654, 46686], [46691, 46722], [46727, 46751], [46756, 46782], [46787, 46811], [46816, 46838], [46843, 46865], [46987, 47005], [47016, 47368], [47511, 47538], [47610, 47624], [47647, 47666], [47728, 47743], [47782, 47799], [47848, 47864], [47901, 47917], [47952, 47975], [47986, 48019], [48184, 48208], [48263, 48291], [48365, 48386], [48435, 48454], [48465, 48486], [48497, 48521], [48532, 48555], [48597, 48617], [48628, 48648], [48659, 48680], [48691, 48711], [48779, 48794], [48818, 48838], [48862, 48882], [48944, 48968], [49640, 49679], [50394, 50434], [50670, 50693], [50751, 50774], [50907, 50931], [51077, 51103], [51114, 51143], [51154, 51174], [51185, 51213], [51224, 51244], [51456, 51478], [51489, 51518], [51529, 51551], [51562, 51606], [51650, 51681], [51692, 51720], [51731, 51753], [51764, 51794], [51805, 51827], [51838, 51870], [51935, 51957], [52048, 52072], [52153, 52184], [52193, 52215], [52224, 52280], [52338, 52360], [52582, 52613], [52624, 52654], [52665, 52687], [52698, 52728], [52739, 52761], [52772, 52804], [52967, 52989], [53000, 53028], [53631, 53660], [53681, 53724], [53745, 53788], [53809, 53837], [53858, 53886], [63557, 63589], [63698, 63741], [63984, 64046], [64223, 64266], [65169, 65206], [65227, 65264], [65285, 65428], [65449, 65488], [65509, 65546], [69404, 69482], [69508, 69542], [69796, 69823], [70030, 70086], [70091, 70149], [70154, 70212], [70217, 70297], [70302, 70384], [70389, 70451], [70456, 70519], [70524, 70602], [70607, 70686], [70691, 70776], [70781, 70854], [70859, 70936], [70941, 71016], [71197, 71220], [71227, 71250], [71281, 71325], [71422, 71440]], "nonblocking_assignment": [[23286, 23308], [23347, 23368], [23570, 23594], [23637, 23660], [25603, 25619], [25645, 25668], [53220, 53249], [53275, 53304], [75241, 75263], [75289, 75324]], "case_statement": [[36833, 45252], [46898, 50478], [50551, 53100], [50608, 50824], [53588, 53898], [65099, 65562]], "conditional_statement": [[23261, 23376], [23322, 23376], [23543, 23670], [23610, 23670], [25089, 25207], [25236, 25458], [25313, 25458], [25578, 25676], [39771, 40104], [40149, 40264], [45257, 45762], [45285, 45754], [46870, 50486], [47425, 47552], [48104, 48222], [50940, 51969], [51262, 51969], [52289, 52372], [52480, 53040], [53195, 53312], [63602, 63757], [64059, 64282], [69330, 69550], [75216, 75332]], "always_construct": [[23206, 23382], [23486, 23678], [24932, 25464], [25523, 25682], [36761, 45768], [45788, 53106], [53140, 53318], [53566, 53904], [63527, 63771], [63894, 64296], [65073, 65572], [69285, 69556], [69602, 71022], [71075, 71454], [75161, 75338]], "parameter_declaration": [[6471, 6520], [6523, 6571], [6594, 6628], [6631, 6665], [6668, 6702], [12379, 12461], [12464, 12546], [12570, 12622], [12625, 12677], [12680, 12733], [12736, 12789], [12792, 12845], [12848, 12901], [12925, 13002], [13044, 13089], [13092, 13137], [13140, 13186], [13189, 13235], [13238, 13284], [13332, 13380], [13383, 13431], [13434, 13482], [13551, 13619], [13622, 13688], [13787, 13814], [16708, 16752], [16755, 16799], [16802, 16847], [16850, 16895], [16898, 16943], [16946, 16990], [16993, 17037], [17040, 17096], [22814, 22856], [22859, 22903], [22906, 22947], [24020, 24052], [24310, 24341], [27383, 27433], [27436, 27486], [27489, 27540], [27543, 27594], [27597, 27647], [27650, 27700], [27703, 27753], [27756, 27806], [27809, 27877], [27880, 27947]], "ansi_port_declaration": [[22955, 22986], [22989, 23021], [23024, 23059], [23062, 23095], [23098, 23133], [23136, 23171], [24348, 24374], [24377, 24404], [24407, 24441], [24444, 24478], [24481, 24514], [24517, 24551], [24554, 24588], [24591, 24628], [27975, 28010], [28013, 28049], [28065, 28104], [28127, 28171], [28174, 28219], [28222, 28268], [28282, 28323], [28326, 28372], [28375, 28416], [28459, 28501], [28504, 28544], [28547, 28588], [28591, 28629], [28632, 28673], [28676, 28717], [28736, 28780], [28783, 28824], [28827, 28871], [28874, 28914], [28917, 28957], [28960, 29041], [29044, 29137], [29140, 29187], [29190, 29230], [29242, 29304], [29307, 29369], [29372, 29421], [29435, 29477], [29480, 29523], [29526, 29572], [29575, 29615], [29618, 29667], [29670, 29715], [29718, 29763], [29766, 29811], [29814, 29851], [29854, 29891], [29922, 29965], [29968, 30011], [30014, 30062], [30065, 30113], [30116, 30162], [30165, 30207], [30210, 30251], [30254, 30337], [30542, 30631], [30634, 30719], [30722, 30809], [30812, 30907], [30910, 30998], [31001, 31078], [31081, 31172], [31175, 31265], [31268, 31355], [31358, 31445], [31448, 31532]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p5/cve2_cs_registers.sv DELETED
@@ -1,2157 +0,0 @@
1
- // Copyright (c) 2025 Eclipse Foundation
2
- // Copyright lowRISC contributors.
3
- // Copyright 2017 ETH Zurich and University of Bologna, see also CREDITS.md.
4
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
5
- // SPDX-License-Identifier: Apache-2.0
6
- /**
7
- * Package with constants used by CVE2
8
- */
9
- package cve2_pkg;
10
- ////////////////
11
- // IO Structs //
12
- ////////////////
13
- typedef struct packed {
14
- logic [31:0] current_pc;
15
- logic [31:0] next_pc;
16
- logic [31:0] last_data_addr;
17
- logic [31:0] exception_addr;
18
- } crash_dump_t;
19
- typedef struct packed {
20
- logic dummy_instr_id;
21
- logic [4:0] raddr_a;
22
- logic [4:0] waddr_a;
23
- logic we_a;
24
- logic [4:0] raddr_b;
25
- } core2rf_t;
26
- /////////////////////
27
- // Parameter Enums //
28
- /////////////////////
29
- typedef enum integer {
30
- RV32MNone = 0,
31
- RV32MSlow = 1,
32
- RV32MFast = 2,
33
- RV32MSingleCycle = 3
34
- } rv32m_e;
35
- typedef enum integer {
36
- RV32BNone = 0,
37
- RV32BBalanced = 1,
38
- RV32BOTEarlGrey = 2,
39
- RV32BFull = 3
40
- } rv32b_e;
41
- /////////////
42
- // Opcodes //
43
- /////////////
44
- typedef enum logic [6:0] {
45
- OPCODE_LOAD = 7'h03,
46
- OPCODE_MISC_MEM = 7'h0f,
47
- OPCODE_OP_IMM = 7'h13,
48
- OPCODE_AUIPC = 7'h17,
49
- OPCODE_STORE = 7'h23,
50
- OPCODE_OP = 7'h33,
51
- OPCODE_LUI = 7'h37,
52
- OPCODE_BRANCH = 7'h63,
53
- OPCODE_JALR = 7'h67,
54
- OPCODE_JAL = 7'h6f,
55
- OPCODE_SYSTEM = 7'h73
56
- } opcode_e;
57
- ////////////////////
58
- // ALU operations //
59
- ////////////////////
60
- typedef enum logic [6:0] {
61
- // Arithmetics
62
- ALU_ADD,
63
- ALU_SUB,
64
- // Logics
65
- ALU_XOR,
66
- ALU_OR,
67
- ALU_AND,
68
- // RV32B
69
- ALU_XNOR,
70
- ALU_ORN,
71
- ALU_ANDN,
72
- // Shifts
73
- ALU_SRA,
74
- ALU_SRL,
75
- ALU_SLL,
76
- // RV32B
77
- ALU_SRO,
78
- ALU_SLO,
79
- ALU_ROR,
80
- ALU_ROL,
81
- ALU_GREV,
82
- ALU_GORC,
83
- ALU_SHFL,
84
- ALU_UNSHFL,
85
- ALU_XPERM_N,
86
- ALU_XPERM_B,
87
- ALU_XPERM_H,
88
- // Address Calculations
89
- // RV32B
90
- ALU_SH1ADD,
91
- ALU_SH2ADD,
92
- ALU_SH3ADD,
93
- // Comparisons
94
- ALU_LT,
95
- ALU_LTU,
96
- ALU_GE,
97
- ALU_GEU,
98
- ALU_EQ,
99
- ALU_NE,
100
- // RV32B
101
- ALU_MIN,
102
- ALU_MINU,
103
- ALU_MAX,
104
- ALU_MAXU,
105
- // Pack
106
- // RV32B
107
- ALU_PACK,
108
- ALU_PACKU,
109
- ALU_PACKH,
110
- // Sign-Extend
111
- // RV32B
112
- ALU_SEXTB,
113
- ALU_SEXTH,
114
- // Bitcounting
115
- // RV32B
116
- ALU_CLZ,
117
- ALU_CTZ,
118
- ALU_CPOP,
119
- // Set lower than
120
- ALU_SLT,
121
- ALU_SLTU,
122
- // Ternary Bitmanip Operations
123
- // RV32B
124
- ALU_CMOV,
125
- ALU_CMIX,
126
- ALU_FSL,
127
- ALU_FSR,
128
- // Single-Bit Operations
129
- // RV32B
130
- ALU_BSET,
131
- ALU_BCLR,
132
- ALU_BINV,
133
- ALU_BEXT,
134
- // Bit Compress / Decompress
135
- // RV32B
136
- ALU_BCOMPRESS,
137
- ALU_BDECOMPRESS,
138
- // Bit Field Place
139
- // RV32B
140
- ALU_BFP,
141
- // Carry-less Multiply
142
- // RV32B
143
- ALU_CLMUL,
144
- ALU_CLMULR,
145
- ALU_CLMULH,
146
- // Cyclic Redundancy Check
147
- ALU_CRC32_B,
148
- ALU_CRC32C_B,
149
- ALU_CRC32_H,
150
- ALU_CRC32C_H,
151
- ALU_CRC32_W,
152
- ALU_CRC32C_W
153
- } alu_op_e;
154
- typedef enum logic [1:0] {
155
- // Multiplier/divider
156
- MD_OP_MULL,
157
- MD_OP_MULH,
158
- MD_OP_DIV,
159
- MD_OP_REM
160
- } md_op_e;
161
- //////////////////////////////////
162
- // Control and status registers //
163
- //////////////////////////////////
164
- // CSR operations
165
- typedef enum logic [1:0] {
166
- CSR_OP_READ,
167
- CSR_OP_WRITE,
168
- CSR_OP_SET,
169
- CSR_OP_CLEAR
170
- } csr_op_e;
171
- // Privileged mode
172
- typedef enum logic[1:0] {
173
- PRIV_LVL_M = 2'b11,
174
- PRIV_LVL_H = 2'b10,
175
- PRIV_LVL_S = 2'b01,
176
- PRIV_LVL_U = 2'b00
177
- } priv_lvl_e;
178
- // Constants for the dcsr.xdebugver fields
179
- typedef enum logic[3:0] {
180
- XDEBUGVER_NO = 4'd0, // no external debug support
181
- XDEBUGVER_STD = 4'd4, // external debug according to RISC-V debug spec
182
- XDEBUGVER_NONSTD = 4'd15 // debug not conforming to RISC-V debug spec
183
- } x_debug_ver_e;
184
- //////////////
185
- // WB stage //
186
- //////////////
187
- // Type of instruction present in writeback stage
188
- typedef enum logic[1:0] {
189
- WB_INSTR_LOAD, // Instruction is awaiting load data
190
- WB_INSTR_STORE, // Instruction is awaiting store response
191
- WB_INSTR_OTHER // Instruction doesn't fit into above categories
192
- } wb_instr_type_e;
193
- //////////////
194
- // ID stage //
195
- //////////////
196
- // Operand a selection
197
- typedef enum logic[1:0] {
198
- OP_A_REG_A,
199
- OP_A_FWD,
200
- OP_A_CURRPC,
201
- OP_A_IMM
202
- } op_a_sel_e;
203
- // Immediate a selection
204
- typedef enum logic {
205
- IMM_A_Z,
206
- IMM_A_ZERO
207
- } imm_a_sel_e;
208
- // Operand b selection
209
- typedef enum logic {
210
- OP_B_REG_B,
211
- OP_B_IMM
212
- } op_b_sel_e;
213
- // Immediate b selection
214
- typedef enum logic [2:0] {
215
- IMM_B_I,
216
- IMM_B_S,
217
- IMM_B_B,
218
- IMM_B_U,
219
- IMM_B_J,
220
- IMM_B_INCR_PC,
221
- IMM_B_INCR_ADDR
222
- } imm_b_sel_e;
223
- // Regfile write data selection
224
- typedef enum {
225
- RF_WD_EX,
226
- RF_WD_CSR,
227
- RF_WD_COPROC // Only used when XInterface = 1
228
- } rf_wd_sel_e;
229
- //////////////
230
- // IF stage //
231
- //////////////
232
- // PC mux selection
233
- typedef enum logic [2:0] {
234
- PC_BOOT,
235
- PC_JUMP,
236
- PC_EXC,
237
- PC_ERET,
238
- PC_DRET,
239
- PC_BP
240
- } pc_sel_e;
241
- // Exception PC mux selection
242
- typedef enum logic [1:0] {
243
- EXC_PC_EXC,
244
- EXC_PC_IRQ,
245
- EXC_PC_DBD,
246
- EXC_PC_DBG_EXC // Exception while in debug mode
247
- } exc_pc_sel_e;
248
- // Interrupt requests
249
- typedef struct packed {
250
- logic irq_software;
251
- logic irq_timer;
252
- logic irq_external;
253
- logic [15:0] irq_fast; // 16 fast interrupts
254
- } irqs_t;
255
- // Exception cause
256
- typedef enum logic [6:0] {
257
- EXC_CAUSE_IRQ_SOFTWARE_M = {1'b1, 6'd03},
258
- EXC_CAUSE_IRQ_TIMER_M = {1'b1, 6'd07},
259
- EXC_CAUSE_IRQ_EXTERNAL_M = {1'b1, 6'd11},
260
- // EXC_CAUSE_IRQ_FAST_0 = {1'b1, 6'd16},
261
- // EXC_CAUSE_IRQ_FAST_15 = {1'b1, 6'd31},
262
- EXC_CAUSE_IRQ_NM = {1'b1, 6'd32},
263
- EXC_CAUSE_INSN_ADDR_MISA = {1'b0, 6'd00},
264
- EXC_CAUSE_INSTR_ACCESS_FAULT = {1'b0, 6'd01},
265
- EXC_CAUSE_ILLEGAL_INSN = {1'b0, 6'd02},
266
- EXC_CAUSE_BREAKPOINT = {1'b0, 6'd03},
267
- EXC_CAUSE_LOAD_ACCESS_FAULT = {1'b0, 6'd05},
268
- EXC_CAUSE_STORE_ACCESS_FAULT = {1'b0, 6'd07},
269
- EXC_CAUSE_ECALL_UMODE = {1'b0, 6'd08},
270
- EXC_CAUSE_ECALL_MMODE = {1'b0, 6'd11}
271
- } exc_cause_e;
272
- // Debug cause
273
- typedef enum logic [2:0] {
274
- DBG_CAUSE_NONE = 3'h0,
275
- DBG_CAUSE_EBREAK = 3'h1,
276
- DBG_CAUSE_TRIGGER = 3'h2,
277
- DBG_CAUSE_HALTREQ = 3'h3,
278
- DBG_CAUSE_STEP = 3'h4
279
- } dbg_cause_e;
280
- // PMP constants
281
- parameter int unsigned PMP_MAX_REGIONS = 16;
282
- parameter int unsigned PMP_CFG_W = 8;
283
- // PMP acces type
284
- parameter int unsigned PMP_I = 0;
285
- parameter int unsigned PMP_I2 = 1;
286
- parameter int unsigned PMP_D = 2;
287
- typedef enum logic [1:0] {
288
- PMP_ACC_EXEC = 2'b00,
289
- PMP_ACC_WRITE = 2'b01,
290
- PMP_ACC_READ = 2'b10
291
- } pmp_req_e;
292
- // PMP cfg structures
293
- typedef enum logic [1:0] {
294
- PMP_MODE_OFF = 2'b00,
295
- PMP_MODE_TOR = 2'b01,
296
- PMP_MODE_NA4 = 2'b10,
297
- PMP_MODE_NAPOT = 2'b11
298
- } pmp_cfg_mode_e;
299
- typedef struct packed {
300
- logic lock;
301
- pmp_cfg_mode_e mode;
302
- logic exec;
303
- logic write;
304
- logic read;
305
- } pmp_cfg_t;
306
- // Machine Security Configuration (ePMP)
307
- typedef struct packed {
308
- logic rlb; // Rule Locking Bypass
309
- logic mmwp; // Machine Mode Whitelist Policy
310
- logic mml; // Machine Mode Lockdown
311
- } pmp_mseccfg_t;
312
- // CSRs
313
- typedef enum logic[11:0] {
314
- // Machine information
315
- CSR_MVENDORID = 12'hF11,
316
- CSR_MARCHID = 12'hF12,
317
- CSR_MIMPID = 12'hF13,
318
- CSR_MHARTID = 12'hF14,
319
- CSR_MCONFIGPTR = 12'hF15,
320
- // Machine trap setup
321
- CSR_MSTATUS = 12'h300,
322
- CSR_MISA = 12'h301,
323
- CSR_MIE = 12'h304,
324
- CSR_MTVEC = 12'h305,
325
- CSR_MCOUNTEREN= 12'h306,
326
- CSR_MSTATUSH = 12'h310,
327
- CSR_MENVCFG = 12'h30A,
328
- CSR_MENVCFGH = 12'h31A,
329
- // Machine trap handling
330
- CSR_MSCRATCH = 12'h340,
331
- CSR_MEPC = 12'h341,
332
- CSR_MCAUSE = 12'h342,
333
- CSR_MTVAL = 12'h343,
334
- CSR_MIP = 12'h344,
335
- // Physical memory protection
336
- CSR_PMPCFG0 = 12'h3A0,
337
- CSR_PMPCFG1 = 12'h3A1,
338
- CSR_PMPCFG2 = 12'h3A2,
339
- CSR_PMPCFG3 = 12'h3A3,
340
- CSR_PMPADDR0 = 12'h3B0,
341
- CSR_PMPADDR1 = 12'h3B1,
342
- CSR_PMPADDR2 = 12'h3B2,
343
- CSR_PMPADDR3 = 12'h3B3,
344
- CSR_PMPADDR4 = 12'h3B4,
345
- CSR_PMPADDR5 = 12'h3B5,
346
- CSR_PMPADDR6 = 12'h3B6,
347
- CSR_PMPADDR7 = 12'h3B7,
348
- CSR_PMPADDR8 = 12'h3B8,
349
- CSR_PMPADDR9 = 12'h3B9,
350
- CSR_PMPADDR10 = 12'h3BA,
351
- CSR_PMPADDR11 = 12'h3BB,
352
- CSR_PMPADDR12 = 12'h3BC,
353
- CSR_PMPADDR13 = 12'h3BD,
354
- CSR_PMPADDR14 = 12'h3BE,
355
- CSR_PMPADDR15 = 12'h3BF,
356
- // ePMP control
357
- CSR_MSECCFG = 12'h747,
358
- CSR_MSECCFGH = 12'h757,
359
- // Debug trigger
360
- CSR_TSELECT = 12'h7A0,
361
- CSR_TDATA1 = 12'h7A1,
362
- CSR_TDATA2 = 12'h7A2,
363
- CSR_TDATA3 = 12'h7A3,
364
- CSR_MCONTEXT = 12'h7A8,
365
- CSR_SCONTEXT = 12'h7AA,
366
- // Debug/trace
367
- CSR_DCSR = 12'h7b0,
368
- CSR_DPC = 12'h7b1,
369
- // Debug
370
- CSR_DSCRATCH0 = 12'h7b2, // optional
371
- CSR_DSCRATCH1 = 12'h7b3, // optional
372
- // Machine Counter/Timers
373
- CSR_MCOUNTINHIBIT = 12'h320,
374
- CSR_MHPMEVENT3 = 12'h323,
375
- CSR_MHPMEVENT4 = 12'h324,
376
- CSR_MHPMEVENT5 = 12'h325,
377
- CSR_MHPMEVENT6 = 12'h326,
378
- CSR_MHPMEVENT7 = 12'h327,
379
- CSR_MHPMEVENT8 = 12'h328,
380
- CSR_MHPMEVENT9 = 12'h329,
381
- CSR_MHPMEVENT10 = 12'h32A,
382
- CSR_MHPMEVENT11 = 12'h32B,
383
- CSR_MHPMEVENT12 = 12'h32C,
384
- CSR_MHPMEVENT13 = 12'h32D,
385
- CSR_MHPMEVENT14 = 12'h32E,
386
- CSR_MHPMEVENT15 = 12'h32F,
387
- CSR_MHPMEVENT16 = 12'h330,
388
- CSR_MHPMEVENT17 = 12'h331,
389
- CSR_MHPMEVENT18 = 12'h332,
390
- CSR_MHPMEVENT19 = 12'h333,
391
- CSR_MHPMEVENT20 = 12'h334,
392
- CSR_MHPMEVENT21 = 12'h335,
393
- CSR_MHPMEVENT22 = 12'h336,
394
- CSR_MHPMEVENT23 = 12'h337,
395
- CSR_MHPMEVENT24 = 12'h338,
396
- CSR_MHPMEVENT25 = 12'h339,
397
- CSR_MHPMEVENT26 = 12'h33A,
398
- CSR_MHPMEVENT27 = 12'h33B,
399
- CSR_MHPMEVENT28 = 12'h33C,
400
- CSR_MHPMEVENT29 = 12'h33D,
401
- CSR_MHPMEVENT30 = 12'h33E,
402
- CSR_MHPMEVENT31 = 12'h33F,
403
- CSR_MCYCLE = 12'hB00,
404
- CSR_MINSTRET = 12'hB02,
405
- CSR_MHPMCOUNTER3 = 12'hB03,
406
- CSR_MHPMCOUNTER4 = 12'hB04,
407
- CSR_MHPMCOUNTER5 = 12'hB05,
408
- CSR_MHPMCOUNTER6 = 12'hB06,
409
- CSR_MHPMCOUNTER7 = 12'hB07,
410
- CSR_MHPMCOUNTER8 = 12'hB08,
411
- CSR_MHPMCOUNTER9 = 12'hB09,
412
- CSR_MHPMCOUNTER10 = 12'hB0A,
413
- CSR_MHPMCOUNTER11 = 12'hB0B,
414
- CSR_MHPMCOUNTER12 = 12'hB0C,
415
- CSR_MHPMCOUNTER13 = 12'hB0D,
416
- CSR_MHPMCOUNTER14 = 12'hB0E,
417
- CSR_MHPMCOUNTER15 = 12'hB0F,
418
- CSR_MHPMCOUNTER16 = 12'hB10,
419
- CSR_MHPMCOUNTER17 = 12'hB11,
420
- CSR_MHPMCOUNTER18 = 12'hB12,
421
- CSR_MHPMCOUNTER19 = 12'hB13,
422
- CSR_MHPMCOUNTER20 = 12'hB14,
423
- CSR_MHPMCOUNTER21 = 12'hB15,
424
- CSR_MHPMCOUNTER22 = 12'hB16,
425
- CSR_MHPMCOUNTER23 = 12'hB17,
426
- CSR_MHPMCOUNTER24 = 12'hB18,
427
- CSR_MHPMCOUNTER25 = 12'hB19,
428
- CSR_MHPMCOUNTER26 = 12'hB1A,
429
- CSR_MHPMCOUNTER27 = 12'hB1B,
430
- CSR_MHPMCOUNTER28 = 12'hB1C,
431
- CSR_MHPMCOUNTER29 = 12'hB1D,
432
- CSR_MHPMCOUNTER30 = 12'hB1E,
433
- CSR_MHPMCOUNTER31 = 12'hB1F,
434
- CSR_MCYCLEH = 12'hB80,
435
- CSR_MINSTRETH = 12'hB82,
436
- CSR_MHPMCOUNTER3H = 12'hB83,
437
- CSR_MHPMCOUNTER4H = 12'hB84,
438
- CSR_MHPMCOUNTER5H = 12'hB85,
439
- CSR_MHPMCOUNTER6H = 12'hB86,
440
- CSR_MHPMCOUNTER7H = 12'hB87,
441
- CSR_MHPMCOUNTER8H = 12'hB88,
442
- CSR_MHPMCOUNTER9H = 12'hB89,
443
- CSR_MHPMCOUNTER10H = 12'hB8A,
444
- CSR_MHPMCOUNTER11H = 12'hB8B,
445
- CSR_MHPMCOUNTER12H = 12'hB8C,
446
- CSR_MHPMCOUNTER13H = 12'hB8D,
447
- CSR_MHPMCOUNTER14H = 12'hB8E,
448
- CSR_MHPMCOUNTER15H = 12'hB8F,
449
- CSR_MHPMCOUNTER16H = 12'hB90,
450
- CSR_MHPMCOUNTER17H = 12'hB91,
451
- CSR_MHPMCOUNTER18H = 12'hB92,
452
- CSR_MHPMCOUNTER19H = 12'hB93,
453
- CSR_MHPMCOUNTER20H = 12'hB94,
454
- CSR_MHPMCOUNTER21H = 12'hB95,
455
- CSR_MHPMCOUNTER22H = 12'hB96,
456
- CSR_MHPMCOUNTER23H = 12'hB97,
457
- CSR_MHPMCOUNTER24H = 12'hB98,
458
- CSR_MHPMCOUNTER25H = 12'hB99,
459
- CSR_MHPMCOUNTER26H = 12'hB9A,
460
- CSR_MHPMCOUNTER27H = 12'hB9B,
461
- CSR_MHPMCOUNTER28H = 12'hB9C,
462
- CSR_MHPMCOUNTER29H = 12'hB9D,
463
- CSR_MHPMCOUNTER30H = 12'hB9E,
464
- CSR_MHPMCOUNTER31H = 12'hB9F,
465
- CSR_CPUCTRL = 12'h7C0,
466
- CSR_SECURESEED = 12'h7C1
467
- } csr_num_e;
468
- // CSR pmp-related offsets
469
- parameter logic [11:0] CSR_OFF_PMP_CFG = 12'h3A0; // pmp_cfg @ 12'h3a0 - 12'h3a3
470
- parameter logic [11:0] CSR_OFF_PMP_ADDR = 12'h3B0; // pmp_addr @ 12'h3b0 - 12'h3bf
471
- // CSR status bits
472
- parameter int unsigned CSR_MSTATUS_MIE_BIT = 3;
473
- parameter int unsigned CSR_MSTATUS_MPIE_BIT = 7;
474
- parameter int unsigned CSR_MSTATUS_MPP_BIT_LOW = 11;
475
- parameter int unsigned CSR_MSTATUS_MPP_BIT_HIGH = 12;
476
- parameter int unsigned CSR_MSTATUS_MPRV_BIT = 17;
477
- parameter int unsigned CSR_MSTATUS_TW_BIT = 21;
478
- // CSR machine ISA
479
- parameter logic [1:0] CSR_MISA_MXL = 2'd1; // M-XLEN: XLEN in M-Mode for RV32
480
- // CSR interrupt pending/enable bits
481
- parameter int unsigned CSR_MSIX_BIT = 3;
482
- parameter int unsigned CSR_MTIX_BIT = 7;
483
- parameter int unsigned CSR_MEIX_BIT = 11;
484
- parameter int unsigned CSR_MFIX_BIT_LOW = 16;
485
- parameter int unsigned CSR_MFIX_BIT_HIGH = 31;
486
- // CSR Machine Security Configuration bits
487
- parameter int unsigned CSR_MSECCFG_MML_BIT = 0;
488
- parameter int unsigned CSR_MSECCFG_MMWP_BIT = 1;
489
- parameter int unsigned CSR_MSECCFG_RLB_BIT = 2;
490
- // Machine Vendor ID - OpenHW JEDEC ID is '2 decimal (bank 13)'
491
- parameter MVENDORID_OFFSET = 7'h2; // Final byte without parity bit
492
- parameter MVENDORID_BANK = 25'hC; // Number of continuation codes
493
- // Machine Architecture ID (https://github.com/riscv/riscv-isa-manual/blob/master/marchid.md)
494
- parameter MARCHID = 32'd35;
495
- localparam logic [31:0] CSR_MVENDORID_VALUE = {MVENDORID_BANK, MVENDORID_OFFSET};
496
- localparam logic [31:0] CSR_MARCHID_VALUE = MARCHID;
497
- // Implementation ID
498
- // 0 indicates this field is not implemeted. cve2 implementors may wish to indicate an RTL/netlist
499
- // version here using their own unique encoding (e.g. 32 bits of the git hash of the implemented
500
- // commit).
501
- localparam logic [31:0] CSR_MIMPID_VALUE = 32'b0;
502
- // Machine Configuration Pointer
503
- // 0 indicates the configuration data structure does not eixst. cve2 implementors may wish to
504
- // alter this to point to their system specific configuration data structure.
505
- localparam logic [31:0] CSR_MCONFIGPTR_VALUE = 32'b0;
506
- // RVFI CSR element
507
- typedef struct packed {
508
- bit [63:0] rdata;
509
- bit [63:0] rmask;
510
- bit [63:0] wdata;
511
- bit [63:0] wmask;
512
- } rvfi_csr_elmt_t;
513
- // RVFI CSR structure
514
- typedef struct packed {
515
- rvfi_csr_elmt_t fflags;
516
- rvfi_csr_elmt_t frm;
517
- rvfi_csr_elmt_t fcsr;
518
- rvfi_csr_elmt_t ftran;
519
- rvfi_csr_elmt_t dcsr;
520
- rvfi_csr_elmt_t dpc;
521
- rvfi_csr_elmt_t dscratch0;
522
- rvfi_csr_elmt_t dscratch1;
523
- rvfi_csr_elmt_t sstatus;
524
- rvfi_csr_elmt_t sie;
525
- rvfi_csr_elmt_t sip;
526
- rvfi_csr_elmt_t stvec;
527
- rvfi_csr_elmt_t scounteren;
528
- rvfi_csr_elmt_t sscratch;
529
- rvfi_csr_elmt_t sepc;
530
- rvfi_csr_elmt_t scause;
531
- rvfi_csr_elmt_t stval;
532
- rvfi_csr_elmt_t satp;
533
- rvfi_csr_elmt_t mstatus;
534
- rvfi_csr_elmt_t mstatush;
535
- rvfi_csr_elmt_t misa;
536
- rvfi_csr_elmt_t medeleg;
537
- rvfi_csr_elmt_t mideleg;
538
- rvfi_csr_elmt_t mie;
539
- rvfi_csr_elmt_t mtvec;
540
- rvfi_csr_elmt_t mcounteren;
541
- rvfi_csr_elmt_t mscratch;
542
- rvfi_csr_elmt_t mepc;
543
- rvfi_csr_elmt_t mcause;
544
- rvfi_csr_elmt_t mtval;
545
- rvfi_csr_elmt_t mip;
546
- rvfi_csr_elmt_t menvcfg;
547
- rvfi_csr_elmt_t menvcfgh;
548
- rvfi_csr_elmt_t mvendorid;
549
- rvfi_csr_elmt_t marchid;
550
- rvfi_csr_elmt_t mhartid;
551
- rvfi_csr_elmt_t mcountinhibit;
552
- rvfi_csr_elmt_t mcycle;
553
- rvfi_csr_elmt_t mcycleh;
554
- rvfi_csr_elmt_t minstret;
555
- rvfi_csr_elmt_t minstreth;
556
- rvfi_csr_elmt_t cycle;
557
- rvfi_csr_elmt_t cycleh;
558
- rvfi_csr_elmt_t instret;
559
- rvfi_csr_elmt_t instreth;
560
- rvfi_csr_elmt_t dcache;
561
- rvfi_csr_elmt_t icache;
562
- rvfi_csr_elmt_t acc_cons;
563
- rvfi_csr_elmt_t pmpcfg0;
564
- rvfi_csr_elmt_t pmpcfg1;
565
- rvfi_csr_elmt_t pmpcfg2;
566
- rvfi_csr_elmt_t pmpcfg3;
567
- rvfi_csr_elmt_t pmpaddr0;
568
- rvfi_csr_elmt_t pmpaddr1;
569
- rvfi_csr_elmt_t pmpaddr2;
570
- rvfi_csr_elmt_t pmpaddr3;
571
- rvfi_csr_elmt_t pmpaddr4;
572
- rvfi_csr_elmt_t pmpaddr5;
573
- rvfi_csr_elmt_t pmpaddr6;
574
- rvfi_csr_elmt_t pmpaddr7;
575
- rvfi_csr_elmt_t pmpaddr8;
576
- rvfi_csr_elmt_t pmpaddr9;
577
- rvfi_csr_elmt_t pmpaddr10;
578
- rvfi_csr_elmt_t pmpaddr11;
579
- rvfi_csr_elmt_t pmpaddr12;
580
- rvfi_csr_elmt_t pmpaddr13;
581
- rvfi_csr_elmt_t pmpaddr14;
582
- rvfi_csr_elmt_t pmpaddr15;
583
- } rvfi_csr_t;
584
- // CV-X-IF
585
- parameter int unsigned X_NUM_RS = 3;
586
- parameter int unsigned X_ID_WIDTH = 4;
587
- parameter int unsigned X_RFR_WIDTH = 32;
588
- parameter int unsigned X_RFW_WIDTH = 32;
589
- parameter int unsigned X_HARTID_WIDTH = 32;
590
- parameter int unsigned X_DUAL_READ = 0;
591
- parameter int unsigned X_DUAL_WRITE = 0;
592
- parameter int unsigned X_INSTR_INFLIGHT = 2**X_ID_WIDTH;
593
- typedef logic [X_NUM_RS+X_DUAL_READ-1:0] readregflags_t;
594
- typedef logic [X_DUAL_WRITE:0] writeregflags_t;
595
- typedef logic [X_ID_WIDTH-1:0] id_t;
596
- typedef logic [X_HARTID_WIDTH-1:0] hartid_t;
597
- // Issue Interface
598
- typedef struct packed {
599
- logic [31:0] instr;
600
- hartid_t hartid;
601
- id_t id;
602
- } x_issue_req_t;
603
- typedef struct packed {
604
- logic accept;
605
- writeregflags_t writeback;
606
- readregflags_t register_read;
607
- } x_issue_resp_t;
608
- // Register Interface
609
- typedef struct packed {
610
- hartid_t hartid;
611
- id_t id;
612
- logic [X_NUM_RS-1:0][X_RFR_WIDTH-1:0] rs;
613
- readregflags_t rs_valid;
614
- } x_register_t;
615
- // Commit Interface
616
- typedef struct packed {
617
- hartid_t hartid;
618
- id_t id;
619
- logic commit_kill;
620
- } x_commit_t;
621
- // Result Interface
622
- typedef struct packed {
623
- hartid_t hartid;
624
- id_t id;
625
- logic [X_RFW_WIDTH-1:0] data;
626
- logic [4:0] rd;
627
- writeregflags_t we;
628
- } x_result_t;
629
- endpackage
630
- // Copyright (c) 2025 Eclipse Foundation
631
- // Copyright lowRISC contributors.
632
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
633
- // SPDX-License-Identifier: Apache-2.0
634
- /**
635
- * Control / status register primitive
636
- */
637
- // Copyright lowRISC contributors.
638
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
639
- // SPDX-License-Identifier: Apache-2.0
640
- // Macros and helper code for using assertions.
641
- // - Provides default clk and rst options to simplify code
642
- // - Provides boiler plate template for common assertions
643
- ///////////////////
644
- // Helper macros //
645
- ///////////////////
646
- // Default clk and reset signals used by assertion macros below.
647
- // Converts an arbitrary block of code into a Verilog string
648
- // ASSERT_ERROR logs an error message with either `uvm_error or with $error.
649
- //
650
- // This somewhat duplicates `DV_ERROR macro defined in hw/dv/sv/dv_utils/dv_macros.svh. The reason
651
- // for redefining it here is to avoid creating a dependency.
652
- // This macro is suitable for conditionally triggering lint errors, e.g., if a Sec parameter takes
653
- // on a non-default value. This may be required for pre-silicon/FPGA evaluation but we don't want
654
- // to allow this for tapeout.
655
- // The basic helper macros are actually defined in "implementation headers". The macros should do
656
- // the same thing in each case (except for the dummy flavour), but in a way that the respective
657
- // tools support.
658
- //
659
- // If the tool supports assertions in some form, we also define INC_ASSERT (which can be used to
660
- // hide signal definitions that are only used for assertions).
661
- //
662
- // The list of basic macros supported is:
663
- //
664
- // ASSERT_I: Immediate assertion. Note that immediate assertions are sensitive to simulation
665
- // glitches.
666
- //
667
- // ASSERT_INIT: Assertion in initial block. Can be used for things like parameter checking.
668
- //
669
- // ASSERT_INIT_NET: Assertion in initial block. Can be used for initial value of a net.
670
- //
671
- // ASSERT_FINAL: Assertion in final block. Can be used for things like queues being empty at end of
672
- // sim, all credits returned at end of sim, state machines in idle at end of sim.
673
- //
674
- // ASSERT: Assert a concurrent property directly. It can be called as a module (or
675
- // interface) body item.
676
- //
677
- // Note: We use (__rst !== '0) in the disable iff statements instead of (__rst ==
678
- // '1). This properly disables the assertion in cases when reset is X at the
679
- // beginning of a simulation. For that case, (reset == '1) does not disable the
680
- // assertion.
681
- //
682
- // ASSERT_NEVER: Assert a concurrent property NEVER happens
683
- //
684
- // ASSERT_KNOWN: Assert that signal has a known value (each bit is either '0' or '1') after reset.
685
- // It can be called as a module (or interface) body item.
686
- //
687
- // COVER: Cover a concurrent property
688
- //
689
- // ASSUME: Assume a concurrent property
690
- //
691
- // ASSUME_I: Assume an immediate property
692
- // Copyright lowRISC contributors.
693
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
694
- // SPDX-License-Identifier: Apache-2.0
695
- // Macro bodies included by prim_assert.sv for tools that don't support assertions. See
696
- // prim_assert.sv for documentation for each of the macros.
697
- //////////////////////////////
698
- // Complex assertion macros //
699
- //////////////////////////////
700
- // Assert that signal is an active-high pulse with pulse length of 1 clock cycle
701
- // Assert that a property is true only when an enable signal is set. It can be called as a module
702
- // (or interface) body item.
703
- // Assert that signal has a known value (each bit is either '0' or '1') after reset if enable is
704
- // set. It can be called as a module (or interface) body item.
705
- //////////////////////////////////
706
- // For formal verification only //
707
- //////////////////////////////////
708
- // Note that the existing set of ASSERT macros specified above shall be used for FPV,
709
- // thereby ensuring that the assertions are evaluated during DV simulations as well.
710
- // ASSUME_FPV
711
- // Assume a concurrent property during formal verification only.
712
- // ASSUME_I_FPV
713
- // Assume a concurrent property during formal verification only.
714
- // COVER_FPV
715
- // Cover a concurrent property during formal verification
716
- // Copyright lowRISC contributors.
717
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
718
- // SPDX-License-Identifier: Apache-2.0
719
- // // Macros and helper code for security countermeasures.
720
- // Helper macros
721
- // macros for security countermeasures
722
- // PRIM_ASSERT_SEC_CM_SVH
723
- // PRIM_ASSERT_SV
724
- module cve2_csr #(
725
- parameter int unsigned Width = 32,
726
- parameter bit ShadowCopy = 1'b0,
727
- parameter bit [Width-1:0] ResetValue = '0
728
- ) (
729
- input logic clk_i,
730
- input logic rst_ni,
731
- input logic [Width-1:0] wr_data_i,
732
- input logic wr_en_i,
733
- output logic [Width-1:0] rd_data_o,
734
- output logic rd_error_o
735
- );
736
- logic [Width-1:0] rdata_q;
737
- always_ff @(posedge clk_i or negedge rst_ni) begin
738
- if (!rst_ni) begin
739
- rdata_q <= ResetValue;
740
- end else if (wr_en_i) begin
741
- rdata_q <= wr_data_i;
742
- end
743
- end
744
- assign rd_data_o = rdata_q;
745
- if (ShadowCopy) begin : gen_shadow
746
- logic [Width-1:0] shadow_q;
747
- always_ff @(posedge clk_i or negedge rst_ni) begin
748
- if (!rst_ni) begin
749
- shadow_q <= ~ResetValue;
750
- end else if (wr_en_i) begin
751
- shadow_q <= ~wr_data_i;
752
- end
753
- end
754
- assign rd_error_o = rdata_q != ~shadow_q;
755
- end else begin : gen_no_shadow
756
- assign rd_error_o = 1'b0;
757
- end
758
- endmodule
759
- // Copyright (c) 2025 Eclipse Foundation
760
- // Copyright lowRISC contributors.
761
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
762
- // SPDX-License-Identifier: Apache-2.0
763
- module cve2_counter #(
764
- parameter int CounterWidth = 32,
765
- // When set `counter_val_upd_o` provides an incremented version of the counter value, otherwise
766
- // the output is hard-wired to 0. This is required to allow Xilinx DSP inference to work
767
- // correctly. When `ProvideValUpd` is set no DSPs are inferred.
768
- parameter bit ProvideValUpd = 0
769
- ) (
770
- input logic clk_i,
771
- input logic rst_ni,
772
- input logic counter_inc_i,
773
- input logic counterh_we_i,
774
- input logic counter_we_i,
775
- input logic [31:0] counter_val_i,
776
- output logic [63:0] counter_val_o,
777
- output logic [63:0] counter_val_upd_o
778
- );
779
- logic [63:0] counter;
780
- logic [CounterWidth-1:0] counter_upd;
781
- logic [63:0] counter_load;
782
- logic we;
783
- logic [CounterWidth-1:0] counter_d;
784
- // Increment
785
- assign counter_upd = counter[CounterWidth-1:0] + {{CounterWidth - 1{1'b0}}, 1'b1};
786
- // Update
787
- always_comb begin
788
- // Write
789
- we = counter_we_i | counterh_we_i;
790
- counter_load[63:32] = counter[63:32];
791
- counter_load[31:0] = counter_val_i;
792
- if (counterh_we_i) begin
793
- counter_load[63:32] = counter_val_i;
794
- counter_load[31:0] = counter[31:0];
795
- end
796
- // Next value logic
797
- if (we) begin
798
- counter_d = counter_load[CounterWidth-1:0];
799
- end else if (counter_inc_i) begin
800
- counter_d = counter_upd[CounterWidth-1:0];
801
- end else begin
802
- counter_d = counter[CounterWidth-1:0];
803
- end
804
- end
805
- logic [CounterWidth-1:0] counter_q;
806
- // Counter flop
807
- always_ff @(posedge clk_i or negedge rst_ni) begin
808
- if (!rst_ni) begin
809
- counter_q <= '0;
810
- end else begin
811
- counter_q <= counter_d;
812
- end
813
- end
814
- if (CounterWidth < 64) begin : g_counter_narrow
815
- logic [63:CounterWidth] unused_counter_load;
816
- assign counter[CounterWidth-1:0] = counter_q;
817
- assign counter[63:CounterWidth] = '0;
818
- if (ProvideValUpd) begin : g_counter_val_upd_o
819
- assign counter_val_upd_o[CounterWidth-1:0] = counter_upd;
820
- end else begin : g_no_counter_val_upd_o
821
- assign counter_val_upd_o[CounterWidth-1:0] = '0;
822
- end
823
- assign counter_val_upd_o[63:CounterWidth] = '0;
824
- assign unused_counter_load = counter_load[63:CounterWidth];
825
- end else begin : g_counter_full
826
- assign counter = counter_q;
827
- if (ProvideValUpd) begin : g_counter_val_upd_o
828
- assign counter_val_upd_o = counter_upd;
829
- end else begin : g_no_counter_val_upd_o
830
- assign counter_val_upd_o = '0;
831
- end
832
- end
833
- assign counter_val_o = counter;
834
- endmodule
835
- // Keep helper defines file-local.
836
- // Copyright (c) 2025 Eclipse Foundation
837
- // Copyright lowRISC contributors.
838
- // Copyright 2018 ETH Zurich and University of Bologna, see also CREDITS.md.
839
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
840
- // SPDX-License-Identifier: Apache-2.0
841
- /**
842
- * Control and Status Registers
843
- *
844
- * Control and Status Registers (CSRs) following the RISC-V Privileged
845
- * Specification, draft version 1.11
846
- */
847
- // Copyright lowRISC contributors.
848
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
849
- // SPDX-License-Identifier: Apache-2.0
850
- // Macros and helper code for using assertions.
851
- // - Provides default clk and rst options to simplify code
852
- // - Provides boiler plate template for common assertions
853
- // PRIM_ASSERT_SV
854
- module cve2_cs_registers #(
855
- parameter bit DbgTriggerEn = 0,
856
- parameter int unsigned DbgHwBreakNum = 1,
857
- parameter int unsigned MHPMCounterNum = 10,
858
- parameter int unsigned MHPMCounterWidth = 40,
859
- parameter bit PMPEnable = 0,
860
- parameter int unsigned PMPGranularity = 0,
861
- parameter int unsigned PMPNumRegions = 4,
862
- parameter bit RV32E = 0,
863
- parameter cve2_pkg::rv32m_e RV32M = cve2_pkg::RV32MFast,
864
- parameter cve2_pkg::rv32b_e RV32B = cve2_pkg::RV32BNone
865
- ) (
866
- // Clock and Reset
867
- input logic clk_i,
868
- input logic rst_ni,
869
- // Hart ID
870
- input logic [31:0] hart_id_i,
871
- // Privilege mode
872
- output cve2_pkg::priv_lvl_e priv_mode_id_o,
873
- output cve2_pkg::priv_lvl_e priv_mode_lsu_o,
874
- output logic csr_mstatus_tw_o,
875
- // mtvec
876
- output logic [31:0] csr_mtvec_o,
877
- input logic csr_mtvec_init_i,
878
- input logic [31:0] boot_addr_i,
879
- // Interface to registers (SRAM like)
880
- input logic csr_access_i,
881
- input cve2_pkg::csr_num_e csr_addr_i,
882
- input logic [31:0] csr_wdata_i,
883
- input cve2_pkg::csr_op_e csr_op_i,
884
- input csr_op_en_i,
885
- output logic [31:0] csr_rdata_o,
886
- // interrupts
887
- input logic irq_software_i,
888
- input logic irq_timer_i,
889
- input logic irq_external_i,
890
- input logic [15:0] irq_fast_i,
891
- input logic nmi_mode_i,
892
- output logic irq_pending_o, // interrupt request pending
893
- output cve2_pkg::irqs_t irqs_o, // interrupt requests qualified with mie
894
- output logic csr_mstatus_mie_o,
895
- output logic [31:0] csr_mepc_o,
896
- // PMP
897
- output cve2_pkg::pmp_cfg_t csr_pmp_cfg_o [PMPNumRegions],
898
- output logic [33:0] csr_pmp_addr_o [PMPNumRegions],
899
- output cve2_pkg::pmp_mseccfg_t csr_pmp_mseccfg_o,
900
- // debug
901
- input logic debug_mode_i,
902
- input cve2_pkg::dbg_cause_e debug_cause_i,
903
- input logic debug_csr_save_i,
904
- output logic [31:0] csr_depc_o,
905
- output logic debug_single_step_o,
906
- output logic debug_ebreakm_o,
907
- output logic debug_ebreaku_o,
908
- output logic trigger_match_o,
909
- input logic [31:0] pc_if_i,
910
- input logic [31:0] pc_id_i,
911
- // Exception save/restore
912
- input logic csr_save_if_i,
913
- input logic csr_save_id_i,
914
- input logic csr_restore_mret_i,
915
- input logic csr_restore_dret_i,
916
- input logic csr_save_cause_i,
917
- input cve2_pkg::exc_cause_e csr_mcause_i,
918
- input logic [31:0] csr_mtval_i,
919
- output logic illegal_csr_insn_o, // access to non-existent CSR,
920
- // with wrong priviledge level, or
921
- // missing write permissions
922
- // Performance Counters
923
- input logic instr_ret_i, // instr retired in ID/EX stage
924
- input logic instr_ret_compressed_i, // compressed instr retired
925
- input logic iside_wait_i, // core waiting for the iside
926
- input logic jump_i, // jump instr seen (j, jr, jal, jalr)
927
- input logic branch_i, // branch instr seen (bf, bnf)
928
- input logic branch_taken_i, // branch was taken
929
- input logic mem_load_i, // load from memory in this cycle
930
- input logic mem_store_i, // store to memory in this cycle
931
- input logic dside_wait_i, // core waiting for the dside
932
- input logic wfi_wait_i, // core waiting for interrupt
933
- input logic div_wait_i // core waiting for divide
934
- );
935
- import cve2_pkg::*;
936
- localparam int unsigned RV32BEnabled = (RV32B == RV32BNone) ? 0 : 1;
937
- localparam int unsigned RV32MEnabled = (RV32M == RV32MNone) ? 0 : 1;
938
- localparam int unsigned PMPAddrWidth = (PMPGranularity > 0) ? 33 - PMPGranularity : 32;
939
- // misa
940
- localparam logic [31:0] MISA_VALUE =
941
- (0 << 0) // A - Atomic Instructions extension
942
- | (RV32BEnabled << 1) // B - Bit-Manipulation extension
943
- | (1 << 2) // C - Compressed extension
944
- | (0 << 3) // D - Double precision floating-point extension
945
- | (32'(RV32E) << 4) // E - RV32E base ISA
946
- | (0 << 5) // F - Single precision floating-point extension
947
- | (32'(!RV32E) << 8) // I - RV32I/64I/128I base ISA
948
- | (RV32MEnabled << 12) // M - Integer Multiply/Divide extension
949
- | (0 << 13) // N - User level interrupts supported
950
- | (0 << 18) // S - Supervisor mode implemented
951
- | (1 << 20) // U - User mode implemented
952
- | (0 << 23) // X - Non-standard extensions present
953
- | (32'(CSR_MISA_MXL) << 30); // M-XLEN
954
- typedef struct packed {
955
- logic mie;
956
- logic mpie;
957
- priv_lvl_e mpp;
958
- logic mprv;
959
- logic tw;
960
- } status_t;
961
- typedef struct packed {
962
- logic mpie;
963
- priv_lvl_e mpp;
964
- } status_stk_t;
965
- typedef struct packed {
966
- x_debug_ver_e xdebugver;
967
- logic [11:0] zero2;
968
- logic ebreakm;
969
- logic zero1;
970
- logic ebreaks;
971
- logic ebreaku;
972
- logic stepie;
973
- logic stopcount;
974
- logic stoptime;
975
- dbg_cause_e cause;
976
- logic zero0;
977
- logic mprven;
978
- logic nmip;
979
- logic step;
980
- priv_lvl_e prv;
981
- } dcsr_t;
982
- // Interrupt and exception control signals
983
- logic [31:0] exception_pc;
984
- // CSRs
985
- priv_lvl_e priv_lvl_q, priv_lvl_d;
986
- status_t mstatus_q, mstatus_d;
987
- logic mstatus_en;
988
- irqs_t mie_q, mie_d;
989
- logic mie_en;
990
- logic [31:0] mscratch_q;
991
- logic mscratch_en;
992
- logic [31:0] mepc_q, mepc_d;
993
- logic mepc_en;
994
- logic [6:0] mcause_q, mcause_d;
995
- logic mcause_en;
996
- logic [31:0] mtval_q, mtval_d;
997
- logic mtval_en;
998
- logic [31:0] mtvec_q, mtvec_d;
999
- logic mtvec_en;
1000
- irqs_t mip;
1001
- dcsr_t dcsr_q, dcsr_d;
1002
- logic dcsr_en;
1003
- logic [31:0] depc_q, depc_d;
1004
- logic depc_en;
1005
- logic [31:0] dscratch0_q;
1006
- logic [31:0] dscratch1_q;
1007
- logic dscratch0_en, dscratch1_en;
1008
- // CSRs for recoverable NMIs
1009
- // NOTE: these CSRS are nonstandard, see https://github.com/riscv/riscv-isa-manual/issues/261
1010
- status_stk_t mstack_q, mstack_d;
1011
- logic mstack_en;
1012
- logic [31:0] mstack_epc_q, mstack_epc_d;
1013
- logic [6:0] mstack_cause_q, mstack_cause_d;
1014
- // PMP Signals
1015
- logic [31:0] pmp_addr_rdata [PMP_MAX_REGIONS];
1016
- logic [PMP_CFG_W-1:0] pmp_cfg_rdata [PMP_MAX_REGIONS];
1017
- pmp_mseccfg_t pmp_mseccfg;
1018
- // Hardware performance monitor signals
1019
- logic [31:0] mcountinhibit;
1020
- // Only have mcountinhibit flops for counters that actually exist
1021
- logic [MHPMCounterNum+3-1:0] mcountinhibit_d, mcountinhibit_q;
1022
- logic mcountinhibit_we;
1023
- // mhpmcounter flops are elaborated below providing only the precise number that is required based
1024
- // on MHPMCounterNum/MHPMCounterWidth. This signal connects to the Q output of these flops
1025
- // where they exist and is otherwise 0.
1026
- logic [63:0] mhpmcounter [32];
1027
- logic [31:0] mhpmcounter_we;
1028
- logic [31:0] mhpmcounterh_we;
1029
- logic [31:0] mhpmcounter_incr;
1030
- logic [31:0] mhpmevent [32];
1031
- logic [4:0] mhpmcounter_idx;
1032
- logic unused_mhpmcounter_we_1;
1033
- logic unused_mhpmcounterh_we_1;
1034
- logic unused_mhpmcounter_incr_1;
1035
- logic [63:0] minstret_raw;
1036
- // Debug / trigger registers
1037
- logic [31:0] tselect_rdata;
1038
- logic [31:0] tmatch_control_rdata;
1039
- logic [31:0] tmatch_value_rdata;
1040
- // CSR update logic
1041
- logic [31:0] csr_wdata_int;
1042
- logic [31:0] csr_rdata_int;
1043
- logic csr_we_int;
1044
- logic csr_wr;
1045
- // Access violation signals
1046
- logic illegal_csr;
1047
- logic illegal_csr_priv;
1048
- logic illegal_csr_write;
1049
- logic [7:0] unused_boot_addr;
1050
- logic [2:0] unused_csr_addr;
1051
- assign unused_boot_addr = boot_addr_i[7:0];
1052
- /////////////
1053
- // CSR reg //
1054
- /////////////
1055
- logic [$bits(csr_num_e)-1:0] csr_addr;
1056
- assign csr_addr = {csr_addr_i};
1057
- assign unused_csr_addr = csr_addr[7:5];
1058
- assign mhpmcounter_idx = csr_addr[4:0];
1059
- // See RISC-V Privileged Specification, version 1.11, Section 2.1
1060
- assign illegal_csr_priv = (csr_addr[9:8] > {priv_lvl_q});
1061
- assign illegal_csr_write = (csr_addr[11:10] == 2'b11) && csr_wr;
1062
- assign illegal_csr_insn_o = csr_access_i & (illegal_csr | illegal_csr_write | illegal_csr_priv);
1063
- // mip CSR is purely combinational - must be able to re-enable the clock upon WFI
1064
- assign mip.irq_software = irq_software_i;
1065
- assign mip.irq_timer = irq_timer_i;
1066
- assign mip.irq_external = irq_external_i;
1067
- assign mip.irq_fast = irq_fast_i;
1068
- // read logic
1069
- always_comb begin
1070
- csr_rdata_int = '0;
1071
- illegal_csr = 1'b0;
1072
- unique case (csr_addr_i)
1073
- // mvendorid: encoding of manufacturer/provider
1074
- CSR_MVENDORID: csr_rdata_int = CSR_MVENDORID_VALUE;
1075
- // marchid: encoding of base microarchitecture
1076
- CSR_MARCHID: csr_rdata_int = CSR_MARCHID_VALUE;
1077
- // mimpid: encoding of processor implementation version
1078
- CSR_MIMPID: csr_rdata_int = CSR_MIMPID_VALUE;
1079
- // mhartid: unique hardware thread id
1080
- CSR_MHARTID: csr_rdata_int = hart_id_i;
1081
- // mconfigptr: pointer to configuration data structre
1082
- CSR_MCONFIGPTR: csr_rdata_int = CSR_MCONFIGPTR_VALUE;
1083
- // mstatus: always M-mode, contains IE bit
1084
- CSR_MSTATUS: begin
1085
- csr_rdata_int = '0;
1086
- csr_rdata_int[CSR_MSTATUS_MIE_BIT] = mstatus_q.mie;
1087
- csr_rdata_int[CSR_MSTATUS_MPIE_BIT] = mstatus_q.mpie;
1088
- csr_rdata_int[CSR_MSTATUS_MPP_BIT_HIGH:CSR_MSTATUS_MPP_BIT_LOW] = mstatus_q.mpp;
1089
- csr_rdata_int[CSR_MSTATUS_MPRV_BIT] = mstatus_q.mprv;
1090
- csr_rdata_int[CSR_MSTATUS_TW_BIT] = mstatus_q.tw;
1091
- end
1092
- // mstatush: All zeros for CVE2 (fixed little endian and all other bits reserved)
1093
- CSR_MSTATUSH: csr_rdata_int = '0;
1094
- // menvcfg: machine environment configuration, all zeros for CVE2 (none of the relevant
1095
- // features are implemented)
1096
- CSR_MENVCFG, CSR_MENVCFGH: csr_rdata_int = '0;
1097
- // misa
1098
- CSR_MISA: csr_rdata_int = MISA_VALUE;
1099
- // interrupt enable
1100
- CSR_MIE: begin
1101
- csr_rdata_int = '0;
1102
- csr_rdata_int[CSR_MSIX_BIT] = mie_q.irq_software;
1103
- csr_rdata_int[CSR_MTIX_BIT] = mie_q.irq_timer;
1104
- csr_rdata_int[CSR_MEIX_BIT] = mie_q.irq_external;
1105
- csr_rdata_int[CSR_MFIX_BIT_HIGH:CSR_MFIX_BIT_LOW] = mie_q.irq_fast;
1106
- end
1107
- // mcounteren: machine counter enable
1108
- CSR_MCOUNTEREN: begin
1109
- csr_rdata_int = '0;
1110
- end
1111
- CSR_MSCRATCH: csr_rdata_int = mscratch_q;
1112
- // mtvec: trap-vector base address
1113
- CSR_MTVEC: csr_rdata_int = mtvec_q;
1114
- // mepc: exception program counter
1115
- CSR_MEPC: csr_rdata_int = mepc_q;
1116
- // mcause: exception cause
1117
- CSR_MCAUSE: csr_rdata_int = {mcause_q[6], 25'b0, mcause_q[5:0]};
1118
- // mtval: trap value
1119
- CSR_MTVAL: csr_rdata_int = mtval_q;
1120
- // mip: interrupt pending
1121
- CSR_MIP: begin
1122
- csr_rdata_int = '0;
1123
- csr_rdata_int[CSR_MSIX_BIT] = mip.irq_software;
1124
- csr_rdata_int[CSR_MTIX_BIT] = mip.irq_timer;
1125
- csr_rdata_int[CSR_MEIX_BIT] = mip.irq_external;
1126
- csr_rdata_int[CSR_MFIX_BIT_HIGH:CSR_MFIX_BIT_LOW] = mip.irq_fast;
1127
- end
1128
- CSR_MSECCFG: begin
1129
- if (PMPEnable) begin
1130
- csr_rdata_int = '0;
1131
- csr_rdata_int[CSR_MSECCFG_MML_BIT] = pmp_mseccfg.mml;
1132
- csr_rdata_int[CSR_MSECCFG_MMWP_BIT] = pmp_mseccfg.mmwp;
1133
- csr_rdata_int[CSR_MSECCFG_RLB_BIT] = pmp_mseccfg.rlb;
1134
- end else begin
1135
- illegal_csr = 1'b1;
1136
- end
1137
- end
1138
- CSR_MSECCFGH: begin
1139
- if (PMPEnable) begin
1140
- csr_rdata_int = '0;
1141
- end else begin
1142
- illegal_csr = 1'b1;
1143
- end
1144
- end
1145
- // PMP registers
1146
- CSR_PMPCFG0: csr_rdata_int = {pmp_cfg_rdata[3], pmp_cfg_rdata[2],
1147
- pmp_cfg_rdata[1], pmp_cfg_rdata[0]};
1148
- CSR_PMPCFG1: csr_rdata_int = {pmp_cfg_rdata[7], pmp_cfg_rdata[6],
1149
- pmp_cfg_rdata[5], pmp_cfg_rdata[4]};
1150
- CSR_PMPCFG2: csr_rdata_int = {pmp_cfg_rdata[11], pmp_cfg_rdata[10],
1151
- pmp_cfg_rdata[9], pmp_cfg_rdata[8]};
1152
- CSR_PMPCFG3: csr_rdata_int = {pmp_cfg_rdata[15], pmp_cfg_rdata[14],
1153
- pmp_cfg_rdata[13], pmp_cfg_rdata[12]};
1154
- CSR_PMPADDR0: csr_rdata_int = pmp_addr_rdata[0];
1155
- CSR_PMPADDR1: csr_rdata_int = pmp_addr_rdata[1];
1156
- CSR_PMPADDR2: csr_rdata_int = pmp_addr_rdata[2];
1157
- CSR_PMPADDR3: csr_rdata_int = pmp_addr_rdata[3];
1158
- CSR_PMPADDR4: csr_rdata_int = pmp_addr_rdata[4];
1159
- CSR_PMPADDR5: csr_rdata_int = pmp_addr_rdata[5];
1160
- CSR_PMPADDR6: csr_rdata_int = pmp_addr_rdata[6];
1161
- CSR_PMPADDR7: csr_rdata_int = pmp_addr_rdata[7];
1162
- CSR_PMPADDR8: csr_rdata_int = pmp_addr_rdata[8];
1163
- CSR_PMPADDR9: csr_rdata_int = pmp_addr_rdata[9];
1164
- CSR_PMPADDR10: csr_rdata_int = pmp_addr_rdata[10];
1165
- CSR_PMPADDR11: csr_rdata_int = pmp_addr_rdata[11];
1166
- CSR_PMPADDR12: csr_rdata_int = pmp_addr_rdata[12];
1167
- CSR_PMPADDR13: csr_rdata_int = pmp_addr_rdata[13];
1168
- CSR_PMPADDR14: csr_rdata_int = pmp_addr_rdata[14];
1169
- CSR_PMPADDR15: csr_rdata_int = pmp_addr_rdata[15];
1170
- CSR_DCSR: begin
1171
- csr_rdata_int = dcsr_q;
1172
- illegal_csr = ~debug_mode_i;
1173
- end
1174
- CSR_DPC: begin
1175
- csr_rdata_int = depc_q;
1176
- illegal_csr = ~debug_mode_i;
1177
- end
1178
- CSR_DSCRATCH0: begin
1179
- csr_rdata_int = dscratch0_q;
1180
- illegal_csr = ~debug_mode_i;
1181
- end
1182
- CSR_DSCRATCH1: begin
1183
- csr_rdata_int = dscratch1_q;
1184
- illegal_csr = ~debug_mode_i;
1185
- end
1186
- // machine counter/timers
1187
- CSR_MCOUNTINHIBIT: csr_rdata_int = mcountinhibit;
1188
- CSR_MHPMEVENT3,
1189
- CSR_MHPMEVENT4, CSR_MHPMEVENT5, CSR_MHPMEVENT6, CSR_MHPMEVENT7,
1190
- CSR_MHPMEVENT8, CSR_MHPMEVENT9, CSR_MHPMEVENT10, CSR_MHPMEVENT11,
1191
- CSR_MHPMEVENT12, CSR_MHPMEVENT13, CSR_MHPMEVENT14, CSR_MHPMEVENT15,
1192
- CSR_MHPMEVENT16, CSR_MHPMEVENT17, CSR_MHPMEVENT18, CSR_MHPMEVENT19,
1193
- CSR_MHPMEVENT20, CSR_MHPMEVENT21, CSR_MHPMEVENT22, CSR_MHPMEVENT23,
1194
- CSR_MHPMEVENT24, CSR_MHPMEVENT25, CSR_MHPMEVENT26, CSR_MHPMEVENT27,
1195
- CSR_MHPMEVENT28, CSR_MHPMEVENT29, CSR_MHPMEVENT30, CSR_MHPMEVENT31: begin
1196
- csr_rdata_int = mhpmevent[mhpmcounter_idx];
1197
- end
1198
- CSR_MCYCLE,
1199
- CSR_MINSTRET,
1200
- CSR_MHPMCOUNTER3,
1201
- CSR_MHPMCOUNTER4, CSR_MHPMCOUNTER5, CSR_MHPMCOUNTER6, CSR_MHPMCOUNTER7,
1202
- CSR_MHPMCOUNTER8, CSR_MHPMCOUNTER9, CSR_MHPMCOUNTER10, CSR_MHPMCOUNTER11,
1203
- CSR_MHPMCOUNTER12, CSR_MHPMCOUNTER13, CSR_MHPMCOUNTER14, CSR_MHPMCOUNTER15,
1204
- CSR_MHPMCOUNTER16, CSR_MHPMCOUNTER17, CSR_MHPMCOUNTER18, CSR_MHPMCOUNTER19,
1205
- CSR_MHPMCOUNTER20, CSR_MHPMCOUNTER21, CSR_MHPMCOUNTER22, CSR_MHPMCOUNTER23,
1206
- CSR_MHPMCOUNTER24, CSR_MHPMCOUNTER25, CSR_MHPMCOUNTER26, CSR_MHPMCOUNTER27,
1207
- CSR_MHPMCOUNTER28, CSR_MHPMCOUNTER29, CSR_MHPMCOUNTER30, CSR_MHPMCOUNTER31: begin
1208
- csr_rdata_int = mhpmcounter[mhpmcounter_idx][31:0];
1209
- end
1210
- CSR_MCYCLEH,
1211
- CSR_MINSTRETH,
1212
- CSR_MHPMCOUNTER3H,
1213
- CSR_MHPMCOUNTER4H, CSR_MHPMCOUNTER5H, CSR_MHPMCOUNTER6H, CSR_MHPMCOUNTER7H,
1214
- CSR_MHPMCOUNTER8H, CSR_MHPMCOUNTER9H, CSR_MHPMCOUNTER10H, CSR_MHPMCOUNTER11H,
1215
- CSR_MHPMCOUNTER12H, CSR_MHPMCOUNTER13H, CSR_MHPMCOUNTER14H, CSR_MHPMCOUNTER15H,
1216
- CSR_MHPMCOUNTER16H, CSR_MHPMCOUNTER17H, CSR_MHPMCOUNTER18H, CSR_MHPMCOUNTER19H,
1217
- CSR_MHPMCOUNTER20H, CSR_MHPMCOUNTER21H, CSR_MHPMCOUNTER22H, CSR_MHPMCOUNTER23H,
1218
- CSR_MHPMCOUNTER24H, CSR_MHPMCOUNTER25H, CSR_MHPMCOUNTER26H, CSR_MHPMCOUNTER27H,
1219
- CSR_MHPMCOUNTER28H, CSR_MHPMCOUNTER29H, CSR_MHPMCOUNTER30H, CSR_MHPMCOUNTER31H: begin
1220
- csr_rdata_int = mhpmcounter[mhpmcounter_idx][63:32];
1221
- end
1222
- // Debug triggers
1223
- CSR_TSELECT: begin
1224
- csr_rdata_int = tselect_rdata;
1225
- illegal_csr = ~DbgTriggerEn;
1226
- end
1227
- CSR_TDATA1: begin
1228
- csr_rdata_int = tmatch_control_rdata;
1229
- illegal_csr = ~DbgTriggerEn;
1230
- end
1231
- CSR_TDATA2: begin
1232
- csr_rdata_int = tmatch_value_rdata;
1233
- illegal_csr = ~DbgTriggerEn;
1234
- end
1235
- CSR_TDATA3: begin
1236
- csr_rdata_int = '0;
1237
- illegal_csr = ~DbgTriggerEn;
1238
- end
1239
- CSR_MCONTEXT: begin
1240
- csr_rdata_int = '0;
1241
- illegal_csr = ~DbgTriggerEn;
1242
- end
1243
- CSR_SCONTEXT: begin
1244
- csr_rdata_int = '0;
1245
- illegal_csr = ~DbgTriggerEn;
1246
- end
1247
- // Custom CSR for LFSR re-seeding (cannot be read)
1248
- CSR_SECURESEED: begin
1249
- csr_rdata_int = '0;
1250
- end
1251
- default: begin
1252
- illegal_csr = 1'b1;
1253
- end
1254
- endcase
1255
- if (!PMPEnable) begin
1256
- if (csr_addr inside {CSR_PMPCFG0, CSR_PMPCFG1, CSR_PMPCFG2, CSR_PMPCFG3,
1257
- CSR_PMPADDR0, CSR_PMPADDR1, CSR_PMPADDR2, CSR_PMPADDR3,
1258
- CSR_PMPADDR4, CSR_PMPADDR5, CSR_PMPADDR6, CSR_PMPADDR7,
1259
- CSR_PMPADDR8, CSR_PMPADDR9, CSR_PMPADDR10, CSR_PMPADDR11,
1260
- CSR_PMPADDR12, CSR_PMPADDR13, CSR_PMPADDR14, CSR_PMPADDR15}) begin
1261
- illegal_csr = 1'b1;
1262
- end
1263
- end
1264
- end
1265
- // write logic
1266
- always_comb begin
1267
- exception_pc = pc_id_i;
1268
- priv_lvl_d = priv_lvl_q;
1269
- mstatus_en = 1'b0;
1270
- mstatus_d = mstatus_q;
1271
- mie_en = 1'b0;
1272
- mscratch_en = 1'b0;
1273
- mepc_en = 1'b0;
1274
- mepc_d = {csr_wdata_int[31:1], 1'b0};
1275
- mcause_en = 1'b0;
1276
- mcause_d = {csr_wdata_int[31], csr_wdata_int[5:0]};
1277
- mtval_en = 1'b0;
1278
- mtval_d = csr_wdata_int;
1279
- mtvec_en = csr_mtvec_init_i;
1280
- // mtvec.MODE set to vectored
1281
- // mtvec.BASE must be 256-byte aligned
1282
- mtvec_d = csr_mtvec_init_i ? {boot_addr_i[31:8], 6'b0, 2'b01} :
1283
- {csr_wdata_int[31:8], 6'b0, 2'b01};
1284
- dcsr_en = 1'b0;
1285
- dcsr_d = dcsr_q;
1286
- depc_d = {csr_wdata_int[31:1], 1'b0};
1287
- depc_en = 1'b0;
1288
- dscratch0_en = 1'b0;
1289
- dscratch1_en = 1'b0;
1290
- mstack_en = 1'b0;
1291
- mstack_d.mpie = mstatus_q.mpie;
1292
- mstack_d.mpp = mstatus_q.mpp;
1293
- mstack_epc_d = mepc_q;
1294
- mstack_cause_d = mcause_q;
1295
- mcountinhibit_we = 1'b0;
1296
- mhpmcounter_we = '0;
1297
- mhpmcounterh_we = '0;
1298
- if (csr_we_int) begin
1299
- unique case (csr_addr_i)
1300
- // mstatus: IE bit
1301
- CSR_MSTATUS: begin
1302
- mstatus_en = 1'b1;
1303
- mstatus_d = '{
1304
- mie: csr_wdata_int[CSR_MSTATUS_MIE_BIT],
1305
- mpie: csr_wdata_int[CSR_MSTATUS_MPIE_BIT],
1306
- mpp: priv_lvl_e'(csr_wdata_int[CSR_MSTATUS_MPP_BIT_HIGH:CSR_MSTATUS_MPP_BIT_LOW]),
1307
- mprv: csr_wdata_int[CSR_MSTATUS_MPRV_BIT],
1308
- tw: csr_wdata_int[CSR_MSTATUS_TW_BIT]
1309
- };
1310
- // Convert illegal values to M-mode
1311
- if ((mstatus_d.mpp != PRIV_LVL_M) && (mstatus_d.mpp != PRIV_LVL_U)) begin
1312
- mstatus_d.mpp = PRIV_LVL_M;
1313
- end
1314
- end
1315
- // interrupt enable
1316
- CSR_MIE: mie_en = 1'b1;
1317
- CSR_MSCRATCH: mscratch_en = 1'b1;
1318
- // mepc: exception program counter
1319
- CSR_MEPC: mepc_en = 1'b1;
1320
- // mcause
1321
- CSR_MCAUSE: mcause_en = 1'b1;
1322
- // mtval: trap value
1323
- CSR_MTVAL: mtval_en = 1'b1;
1324
- // mtvec
1325
- CSR_MTVEC: mtvec_en = 1'b1;
1326
- CSR_DCSR: begin
1327
- dcsr_d = csr_wdata_int;
1328
- dcsr_d.xdebugver = XDEBUGVER_STD;
1329
- // Change to PRIV_LVL_M if software writes an unsupported value
1330
- if ((dcsr_d.prv != PRIV_LVL_M) && (dcsr_d.prv != PRIV_LVL_U)) begin
1331
- dcsr_d.prv = PRIV_LVL_M;
1332
- end
1333
- // Read-only for SW
1334
- dcsr_d.cause = dcsr_q.cause;
1335
- // Interrupts always disabled during single stepping
1336
- dcsr_d.stepie = 1'b0;
1337
- // currently not supported:
1338
- dcsr_d.nmip = 1'b0;
1339
- dcsr_d.mprven = 1'b0;
1340
- dcsr_d.stopcount = 1'b0;
1341
- dcsr_d.stoptime = 1'b0;
1342
- // forced to be zero
1343
- dcsr_d.zero0 = 1'b0;
1344
- dcsr_d.zero1 = 1'b0;
1345
- dcsr_d.zero2 = 12'h0;
1346
- dcsr_en = 1'b1;
1347
- end
1348
- // dpc: debug program counter
1349
- CSR_DPC: depc_en = 1'b1;
1350
- CSR_DSCRATCH0: dscratch0_en = 1'b1;
1351
- CSR_DSCRATCH1: dscratch1_en = 1'b1;
1352
- // machine counter/timers
1353
- CSR_MCOUNTINHIBIT: mcountinhibit_we = 1'b1;
1354
- CSR_MCYCLE,
1355
- CSR_MINSTRET,
1356
- CSR_MHPMCOUNTER3,
1357
- CSR_MHPMCOUNTER4, CSR_MHPMCOUNTER5, CSR_MHPMCOUNTER6, CSR_MHPMCOUNTER7,
1358
- CSR_MHPMCOUNTER8, CSR_MHPMCOUNTER9, CSR_MHPMCOUNTER10, CSR_MHPMCOUNTER11,
1359
- CSR_MHPMCOUNTER12, CSR_MHPMCOUNTER13, CSR_MHPMCOUNTER14, CSR_MHPMCOUNTER15,
1360
- CSR_MHPMCOUNTER16, CSR_MHPMCOUNTER17, CSR_MHPMCOUNTER18, CSR_MHPMCOUNTER19,
1361
- CSR_MHPMCOUNTER20, CSR_MHPMCOUNTER21, CSR_MHPMCOUNTER22, CSR_MHPMCOUNTER23,
1362
- CSR_MHPMCOUNTER24, CSR_MHPMCOUNTER25, CSR_MHPMCOUNTER26, CSR_MHPMCOUNTER27,
1363
- CSR_MHPMCOUNTER28, CSR_MHPMCOUNTER29, CSR_MHPMCOUNTER30, CSR_MHPMCOUNTER31: begin
1364
- mhpmcounter_we[mhpmcounter_idx] = 1'b1;
1365
- end
1366
- CSR_MCYCLEH,
1367
- CSR_MINSTRETH,
1368
- CSR_MHPMCOUNTER3H,
1369
- CSR_MHPMCOUNTER4H, CSR_MHPMCOUNTER5H, CSR_MHPMCOUNTER6H, CSR_MHPMCOUNTER7H,
1370
- CSR_MHPMCOUNTER8H, CSR_MHPMCOUNTER9H, CSR_MHPMCOUNTER10H, CSR_MHPMCOUNTER11H,
1371
- CSR_MHPMCOUNTER12H, CSR_MHPMCOUNTER13H, CSR_MHPMCOUNTER14H, CSR_MHPMCOUNTER15H,
1372
- CSR_MHPMCOUNTER16H, CSR_MHPMCOUNTER17H, CSR_MHPMCOUNTER18H, CSR_MHPMCOUNTER19H,
1373
- CSR_MHPMCOUNTER20H, CSR_MHPMCOUNTER21H, CSR_MHPMCOUNTER22H, CSR_MHPMCOUNTER23H,
1374
- CSR_MHPMCOUNTER24H, CSR_MHPMCOUNTER25H, CSR_MHPMCOUNTER26H, CSR_MHPMCOUNTER27H,
1375
- CSR_MHPMCOUNTER28H, CSR_MHPMCOUNTER29H, CSR_MHPMCOUNTER30H, CSR_MHPMCOUNTER31H: begin
1376
- mhpmcounterh_we[mhpmcounter_idx] = 1'b1;
1377
- end
1378
- default:;
1379
- endcase
1380
- end
1381
- // exception controller gets priority over other writes
1382
- unique case (1'b1)
1383
- csr_save_cause_i: begin
1384
- unique case (1'b1)
1385
- csr_save_if_i: begin
1386
- exception_pc = pc_if_i;
1387
- end
1388
- csr_save_id_i: begin
1389
- exception_pc = pc_id_i;
1390
- end
1391
- default:;
1392
- endcase
1393
- // Any exception, including debug mode, causes a switch to M-mode
1394
- priv_lvl_d = PRIV_LVL_M;
1395
- if (debug_csr_save_i) begin
1396
- // all interrupts are masked
1397
- // do not update cause, epc, tval, epc and status
1398
- dcsr_d.prv = priv_lvl_q;
1399
- dcsr_d.cause = debug_cause_i;
1400
- dcsr_en = 1'b1;
1401
- depc_d = exception_pc;
1402
- depc_en = 1'b1;
1403
- end else if (!debug_mode_i) begin
1404
- // In debug mode, "exceptions do not update any registers. That
1405
- // includes cause, epc, tval, dpc and mstatus." [Debug Spec v0.13.2, p.39]
1406
- mtval_en = 1'b1;
1407
- mtval_d = csr_mtval_i;
1408
- mstatus_en = 1'b1;
1409
- mstatus_d.mie = 1'b0; // disable interrupts
1410
- // save current status
1411
- mstatus_d.mpie = mstatus_q.mie;
1412
- mstatus_d.mpp = priv_lvl_q;
1413
- mepc_en = 1'b1;
1414
- mepc_d = exception_pc;
1415
- mcause_en = 1'b1;
1416
- mcause_d = {csr_mcause_i};
1417
- // save previous status for recoverable NMI
1418
- mstack_en = 1'b1;
1419
- end
1420
- end // csr_save_cause_i
1421
- csr_restore_dret_i: begin // DRET
1422
- priv_lvl_d = dcsr_q.prv;
1423
- end // csr_restore_dret_i
1424
- csr_restore_mret_i: begin // MRET
1425
- priv_lvl_d = mstatus_q.mpp;
1426
- mstatus_en = 1'b1;
1427
- mstatus_d.mie = mstatus_q.mpie; // re-enable interrupts
1428
- if (mstatus_q.mpp != PRIV_LVL_M) begin
1429
- mstatus_d.mprv = 1'b0;
1430
- end
1431
- // SEC_CM: EXCEPTION.CTRL_FLOW.LOCAL_ESC
1432
- // SEC_CM: EXCEPTION.CTRL_FLOW.GLOBAL_ESC
1433
- if (nmi_mode_i) begin
1434
- // when returning from an NMI restore state from mstack CSR
1435
- mstatus_d.mpie = mstack_q.mpie;
1436
- mstatus_d.mpp = mstack_q.mpp;
1437
- mepc_en = 1'b1;
1438
- mepc_d = mstack_epc_q;
1439
- mcause_en = 1'b1;
1440
- mcause_d = mstack_cause_q;
1441
- end else begin
1442
- // otherwise just set mstatus.MPIE/MPP
1443
- // See RISC-V Privileged Specification, version 1.11, Section 3.1.6.1
1444
- mstatus_d.mpie = 1'b1;
1445
- mstatus_d.mpp = PRIV_LVL_U;
1446
- end
1447
- end // csr_restore_mret_i
1448
- default:;
1449
- endcase
1450
- end
1451
- // Update current priv level
1452
- always_ff @(posedge clk_i or negedge rst_ni) begin
1453
- if (!rst_ni) begin
1454
- priv_lvl_q <= PRIV_LVL_M;
1455
- end else begin
1456
- priv_lvl_q <= priv_lvl_d;
1457
- end
1458
- end
1459
- // Send current priv level to the decoder
1460
- assign priv_mode_id_o = priv_lvl_q;
1461
- // Load/store instructions must factor in MPRV for PMP checking
1462
- assign priv_mode_lsu_o = mstatus_q.mprv ? mstatus_q.mpp : priv_lvl_q;
1463
- // CSR operation logic
1464
- always_comb begin
1465
- unique case (csr_op_i)
1466
- CSR_OP_WRITE: csr_wdata_int = csr_wdata_i;
1467
- CSR_OP_SET: csr_wdata_int = csr_wdata_i | csr_rdata_o;
1468
- CSR_OP_CLEAR: csr_wdata_int = ~csr_wdata_i & csr_rdata_o;
1469
- CSR_OP_READ: csr_wdata_int = csr_wdata_i;
1470
- default: csr_wdata_int = csr_wdata_i;
1471
- endcase
1472
- end
1473
- assign csr_wr = (csr_op_i inside {CSR_OP_WRITE, CSR_OP_SET, CSR_OP_CLEAR});
1474
- // only write CSRs during one clock cycle
1475
- assign csr_we_int = csr_wr & csr_op_en_i & ~illegal_csr_insn_o;
1476
- assign csr_rdata_o = csr_rdata_int;
1477
- // directly output some registers
1478
- assign csr_mepc_o = mepc_q;
1479
- assign csr_depc_o = depc_q;
1480
- assign csr_mtvec_o = mtvec_q;
1481
- assign csr_mstatus_mie_o = mstatus_q.mie;
1482
- assign csr_mstatus_tw_o = mstatus_q.tw;
1483
- assign debug_single_step_o = dcsr_q.step;
1484
- assign debug_ebreakm_o = dcsr_q.ebreakm;
1485
- assign debug_ebreaku_o = dcsr_q.ebreaku;
1486
- // Qualify incoming interrupt requests in mip CSR with mie CSR for controller and to re-enable
1487
- // clock upon WFI (must be purely combinational).
1488
- assign irqs_o = mip & mie_q;
1489
- assign irq_pending_o = |irqs_o;
1490
- ////////////////////////
1491
- // CSR instantiations //
1492
- ////////////////////////
1493
- // MSTATUS
1494
- localparam status_t MSTATUS_RST_VAL = '{mie: 1'b0,
1495
- mpie: 1'b0,
1496
- mpp: PRIV_LVL_M,
1497
- mprv: 1'b0,
1498
- tw: 1'b0};
1499
- cve2_csr #(
1500
- .Width ($bits(status_t)),
1501
- .ResetValue({MSTATUS_RST_VAL})
1502
- ) u_mstatus_csr (
1503
- .clk_i (clk_i),
1504
- .rst_ni (rst_ni),
1505
- .wr_data_i ({mstatus_d}),
1506
- .wr_en_i (mstatus_en),
1507
- .rd_data_o (mstatus_q),
1508
- .rd_error_o()
1509
- );
1510
- // MEPC
1511
- cve2_csr #(
1512
- .Width (32),
1513
- .ShadowCopy(1'b0),
1514
- .ResetValue('0)
1515
- ) u_mepc_csr (
1516
- .clk_i (clk_i),
1517
- .rst_ni (rst_ni),
1518
- .wr_data_i (mepc_d),
1519
- .wr_en_i (mepc_en),
1520
- .rd_data_o (mepc_q),
1521
- .rd_error_o()
1522
- );
1523
- // MIE
1524
- assign mie_d.irq_software = csr_wdata_int[CSR_MSIX_BIT];
1525
- assign mie_d.irq_timer = csr_wdata_int[CSR_MTIX_BIT];
1526
- assign mie_d.irq_external = csr_wdata_int[CSR_MEIX_BIT];
1527
- assign mie_d.irq_fast = csr_wdata_int[CSR_MFIX_BIT_HIGH:CSR_MFIX_BIT_LOW];
1528
- cve2_csr #(
1529
- .Width ($bits(irqs_t)),
1530
- .ShadowCopy(1'b0),
1531
- .ResetValue('0)
1532
- ) u_mie_csr (
1533
- .clk_i (clk_i),
1534
- .rst_ni (rst_ni),
1535
- .wr_data_i ({mie_d}),
1536
- .wr_en_i (mie_en),
1537
- .rd_data_o (mie_q),
1538
- .rd_error_o()
1539
- );
1540
- // MSCRATCH
1541
- cve2_csr #(
1542
- .Width (32),
1543
- .ShadowCopy(1'b0),
1544
- .ResetValue('0)
1545
- ) u_mscratch_csr (
1546
- .clk_i (clk_i),
1547
- .rst_ni (rst_ni),
1548
- .wr_data_i (csr_wdata_int),
1549
- .wr_en_i (mscratch_en),
1550
- .rd_data_o (mscratch_q),
1551
- .rd_error_o()
1552
- );
1553
- // MCAUSE
1554
- cve2_csr #(
1555
- .Width (7),
1556
- .ShadowCopy(1'b0),
1557
- .ResetValue('0)
1558
- ) u_mcause_csr (
1559
- .clk_i (clk_i),
1560
- .rst_ni (rst_ni),
1561
- .wr_data_i (mcause_d),
1562
- .wr_en_i (mcause_en),
1563
- .rd_data_o (mcause_q),
1564
- .rd_error_o()
1565
- );
1566
- // MTVAL
1567
- cve2_csr #(
1568
- .Width (32),
1569
- .ShadowCopy(1'b0),
1570
- .ResetValue('0)
1571
- ) u_mtval_csr (
1572
- .clk_i (clk_i),
1573
- .rst_ni (rst_ni),
1574
- .wr_data_i (mtval_d),
1575
- .wr_en_i (mtval_en),
1576
- .rd_data_o (mtval_q),
1577
- .rd_error_o()
1578
- );
1579
- // MTVEC
1580
- cve2_csr #(
1581
- .Width (32),
1582
- .ResetValue(32'd1)
1583
- ) u_mtvec_csr (
1584
- .clk_i (clk_i),
1585
- .rst_ni (rst_ni),
1586
- .wr_data_i (mtvec_d),
1587
- .wr_en_i (mtvec_en),
1588
- .rd_data_o (mtvec_q),
1589
- .rd_error_o()
1590
- );
1591
- // DCSR
1592
- localparam dcsr_t DCSR_RESET_VAL = '{
1593
- xdebugver: XDEBUGVER_STD,
1594
- cause: DBG_CAUSE_NONE, // 3'h0
1595
- prv: PRIV_LVL_M,
1596
- default: '0
1597
- };
1598
- cve2_csr #(
1599
- .Width ($bits(dcsr_t)),
1600
- .ShadowCopy(1'b0),
1601
- .ResetValue({DCSR_RESET_VAL})
1602
- ) u_dcsr_csr (
1603
- .clk_i (clk_i),
1604
- .rst_ni (rst_ni),
1605
- .wr_data_i ({dcsr_d}),
1606
- .wr_en_i (dcsr_en),
1607
- .rd_data_o (dcsr_q),
1608
- .rd_error_o()
1609
- );
1610
- // DEPC
1611
- cve2_csr #(
1612
- .Width (32),
1613
- .ShadowCopy(1'b0),
1614
- .ResetValue('0)
1615
- ) u_depc_csr (
1616
- .clk_i (clk_i),
1617
- .rst_ni (rst_ni),
1618
- .wr_data_i (depc_d),
1619
- .wr_en_i (depc_en),
1620
- .rd_data_o (depc_q),
1621
- .rd_error_o()
1622
- );
1623
- // DSCRATCH0
1624
- cve2_csr #(
1625
- .Width (32),
1626
- .ShadowCopy(1'b0),
1627
- .ResetValue('0)
1628
- ) u_dscratch0_csr (
1629
- .clk_i (clk_i),
1630
- .rst_ni (rst_ni),
1631
- .wr_data_i (csr_wdata_int),
1632
- .wr_en_i (dscratch0_en),
1633
- .rd_data_o (dscratch0_q),
1634
- .rd_error_o()
1635
- );
1636
- // DSCRATCH1
1637
- cve2_csr #(
1638
- .Width (32),
1639
- .ShadowCopy(1'b0),
1640
- .ResetValue('0)
1641
- ) u_dscratch1_csr (
1642
- .clk_i (clk_i),
1643
- .rst_ni (rst_ni),
1644
- .wr_data_i (csr_wdata_int),
1645
- .wr_en_i (dscratch1_en),
1646
- .rd_data_o (dscratch1_q),
1647
- .rd_error_o()
1648
- );
1649
- // MSTACK
1650
- localparam status_stk_t MSTACK_RESET_VAL = '{mpie: 1'b1, mpp: PRIV_LVL_U};
1651
- cve2_csr #(
1652
- .Width ($bits(status_stk_t)),
1653
- .ShadowCopy(1'b0),
1654
- .ResetValue({MSTACK_RESET_VAL})
1655
- ) u_mstack_csr (
1656
- .clk_i (clk_i),
1657
- .rst_ni (rst_ni),
1658
- .wr_data_i ({mstack_d}),
1659
- .wr_en_i (mstack_en),
1660
- .rd_data_o (mstack_q),
1661
- .rd_error_o()
1662
- );
1663
- // MSTACK_EPC
1664
- cve2_csr #(
1665
- .Width (32),
1666
- .ShadowCopy(1'b0),
1667
- .ResetValue('0)
1668
- ) u_mstack_epc_csr (
1669
- .clk_i (clk_i),
1670
- .rst_ni (rst_ni),
1671
- .wr_data_i (mstack_epc_d),
1672
- .wr_en_i (mstack_en),
1673
- .rd_data_o (mstack_epc_q),
1674
- .rd_error_o()
1675
- );
1676
- // MSTACK_CAUSE
1677
- cve2_csr #(
1678
- .Width (7),
1679
- .ShadowCopy(1'b0),
1680
- .ResetValue('0)
1681
- ) u_mstack_cause_csr (
1682
- .clk_i (clk_i),
1683
- .rst_ni (rst_ni),
1684
- .wr_data_i (mstack_cause_d),
1685
- .wr_en_i (mstack_en),
1686
- .rd_data_o (mstack_cause_q),
1687
- .rd_error_o()
1688
- );
1689
- // -----------------
1690
- // PMP registers
1691
- // -----------------
1692
- if (PMPEnable) begin : g_pmp_registers
1693
- // PMP reset values
1694
- // Copyright (c) 2025 Eclipse Foundation
1695
- // Copyright lowRISC contributors.
1696
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
1697
- // SPDX-License-Identifier: Apache-2.0
1698
- // Default reset values for PMP CSRs. Where the number of regions
1699
- // (PMPNumRegions) is less than 16 the reset values for the higher numbered
1700
- // regions are ignored.
1701
- //
1702
- // See the CVE2 Reference Guide (Custom Reset Values under Physical Memory
1703
- // Protection) for more information.
1704
- localparam pmp_cfg_t pmp_cfg_rst[16] = '{
1705
- '{lock: 1'b0, mode: PMP_MODE_OFF, exec: 1'b0, write: 1'b0, read: 1'b0}, // region 0
1706
- '{lock: 1'b0, mode: PMP_MODE_OFF, exec: 1'b0, write: 1'b0, read: 1'b0}, // region 1
1707
- '{lock: 1'b0, mode: PMP_MODE_OFF, exec: 1'b0, write: 1'b0, read: 1'b0}, // region 2
1708
- '{lock: 1'b0, mode: PMP_MODE_OFF, exec: 1'b0, write: 1'b0, read: 1'b0}, // region 3
1709
- '{lock: 1'b0, mode: PMP_MODE_OFF, exec: 1'b0, write: 1'b0, read: 1'b0}, // region 4
1710
- '{lock: 1'b0, mode: PMP_MODE_OFF, exec: 1'b0, write: 1'b0, read: 1'b0}, // region 5
1711
- '{lock: 1'b0, mode: PMP_MODE_OFF, exec: 1'b0, write: 1'b0, read: 1'b0}, // region 6
1712
- '{lock: 1'b0, mode: PMP_MODE_OFF, exec: 1'b0, write: 1'b0, read: 1'b0}, // region 7
1713
- '{lock: 1'b0, mode: PMP_MODE_OFF, exec: 1'b0, write: 1'b0, read: 1'b0}, // region 8
1714
- '{lock: 1'b0, mode: PMP_MODE_OFF, exec: 1'b0, write: 1'b0, read: 1'b0}, // region 9
1715
- '{lock: 1'b0, mode: PMP_MODE_OFF, exec: 1'b0, write: 1'b0, read: 1'b0}, // region 10
1716
- '{lock: 1'b0, mode: PMP_MODE_OFF, exec: 1'b0, write: 1'b0, read: 1'b0}, // region 11
1717
- '{lock: 1'b0, mode: PMP_MODE_OFF, exec: 1'b0, write: 1'b0, read: 1'b0}, // region 12
1718
- '{lock: 1'b0, mode: PMP_MODE_OFF, exec: 1'b0, write: 1'b0, read: 1'b0}, // region 13
1719
- '{lock: 1'b0, mode: PMP_MODE_OFF, exec: 1'b0, write: 1'b0, read: 1'b0}, // region 14
1720
- '{lock: 1'b0, mode: PMP_MODE_OFF, exec: 1'b0, write: 1'b0, read: 1'b0} // region 15
1721
- };
1722
- // Addresses are given in byte granularity for readibility. A minimum of two
1723
- // bits will be stripped off the bottom (PMPGranularity == 0) with more stripped
1724
- // off at coarser granularities.
1725
- localparam [33:0] pmp_addr_rst[16] = '{
1726
- 34'h0, // region 0
1727
- 34'h0, // region 1
1728
- 34'h0, // region 2
1729
- 34'h0, // region 3
1730
- 34'h0, // region 4
1731
- 34'h0, // region 5
1732
- 34'h0, // region 6
1733
- 34'h0, // region 7
1734
- 34'h0, // region 8
1735
- 34'h0, // region 9
1736
- 34'h0, // region 10
1737
- 34'h0, // region 11
1738
- 34'h0, // region 12
1739
- 34'h0, // region 13
1740
- 34'h0, // region 14
1741
- 34'h0 // region 15
1742
- };
1743
- localparam pmp_mseccfg_t pmp_mseccfg_rst = '{rlb : 1'b0, mmwp: 1'b0, mml: 1'b0};
1744
- pmp_mseccfg_t pmp_mseccfg_q, pmp_mseccfg_d;
1745
- logic pmp_mseccfg_we;
1746
- logic pmp_mseccfg_err;
1747
- pmp_cfg_t pmp_cfg [PMPNumRegions];
1748
- logic [PMPNumRegions-1:0] pmp_cfg_locked;
1749
- pmp_cfg_t pmp_cfg_wdata [PMPNumRegions];
1750
- logic [PMPAddrWidth-1:0] pmp_addr [PMPNumRegions];
1751
- logic [PMPNumRegions-1:0] pmp_cfg_we;
1752
- logic [PMPNumRegions-1:0] pmp_cfg_err;
1753
- logic [PMPNumRegions-1:0] pmp_addr_we;
1754
- logic [PMPNumRegions-1:0] pmp_addr_err;
1755
- logic any_pmp_entry_locked;
1756
- // Expanded / qualified register read data
1757
- for (genvar i = 0; i < PMP_MAX_REGIONS; i++) begin : g_exp_rd_data
1758
- if (i < PMPNumRegions) begin : g_implemented_regions
1759
- // Add in zero padding for reserved fields
1760
- assign pmp_cfg_rdata[i] = {pmp_cfg[i].lock, 2'b00, pmp_cfg[i].mode,
1761
- pmp_cfg[i].exec, pmp_cfg[i].write, pmp_cfg[i].read};
1762
- // Address field read data depends on the current programmed mode and the granularity
1763
- // See RISC-V Privileged Specification, version 1.11, Section 3.6.1
1764
- if (PMPGranularity == 0) begin : g_pmp_g0
1765
- // If G == 0, read data is unmodified
1766
- assign pmp_addr_rdata[i] = pmp_addr[i];
1767
- end else if (PMPGranularity == 1) begin : g_pmp_g1
1768
- // If G == 1, bit [G-1] reads as zero in TOR or OFF mode
1769
- always_comb begin
1770
- pmp_addr_rdata[i] = pmp_addr[i];
1771
- if ((pmp_cfg[i].mode == PMP_MODE_OFF) || (pmp_cfg[i].mode == PMP_MODE_TOR)) begin
1772
- pmp_addr_rdata[i][PMPGranularity-1:0] = '0;
1773
- end
1774
- end
1775
- end else begin : g_pmp_g2
1776
- // For G >= 2, bits are masked to one or zero depending on the mode
1777
- always_comb begin
1778
- // In NAPOT mode, bits [G-2:0] must read as one
1779
- pmp_addr_rdata[i] = {pmp_addr[i], {PMPGranularity - 1{1'b1}}};
1780
- if ((pmp_cfg[i].mode == PMP_MODE_OFF) || (pmp_cfg[i].mode == PMP_MODE_TOR)) begin
1781
- // In TOR or OFF mode, bits [G-1:0] must read as zero
1782
- pmp_addr_rdata[i][PMPGranularity-1:0] = '0;
1783
- end
1784
- end
1785
- end
1786
- end else begin : g_other_regions
1787
- // Non-implemented regions read as zero
1788
- assign pmp_cfg_rdata[i] = '0;
1789
- assign pmp_addr_rdata[i] = '0;
1790
- end
1791
- end
1792
- // Write data calculation
1793
- for (genvar i = 0; i < PMPNumRegions; i++) begin : g_pmp_csrs
1794
- // -------------------------
1795
- // Instantiate cfg registers
1796
- // -------------------------
1797
- assign pmp_cfg_we[i] = csr_we_int & ~pmp_cfg_locked[i] &
1798
- (csr_addr == (CSR_OFF_PMP_CFG + (i[11:0] >> 2)));
1799
- // Select the correct WDATA (each CSR contains 4 CFG fields, each with 2 RES bits)
1800
- assign pmp_cfg_wdata[i].lock = csr_wdata_int[(i%4)*PMP_CFG_W+7];
1801
- // NA4 mode is not selectable when G > 0, mode is treated as OFF
1802
- always_comb begin
1803
- unique case (csr_wdata_int[(i%4)*PMP_CFG_W+3+:2])
1804
- 2'b00 : pmp_cfg_wdata[i].mode = PMP_MODE_OFF;
1805
- 2'b01 : pmp_cfg_wdata[i].mode = PMP_MODE_TOR;
1806
- 2'b10 : pmp_cfg_wdata[i].mode = (PMPGranularity == 0) ? PMP_MODE_NA4:
1807
- PMP_MODE_OFF;
1808
- 2'b11 : pmp_cfg_wdata[i].mode = PMP_MODE_NAPOT;
1809
- default : pmp_cfg_wdata[i].mode = PMP_MODE_OFF;
1810
- endcase
1811
- end
1812
- assign pmp_cfg_wdata[i].exec = csr_wdata_int[(i%4)*PMP_CFG_W+2];
1813
- // When MSECCFG.MML is unset, W = 1, R = 0 is a reserved combination, so force W to 0 if R ==
1814
- // 0. Otherwise allow all possible values to be written.
1815
- assign pmp_cfg_wdata[i].write = pmp_mseccfg_q.mml ? csr_wdata_int[(i%4)*PMP_CFG_W+1] :
1816
- &csr_wdata_int[(i%4)*PMP_CFG_W+:2];
1817
- assign pmp_cfg_wdata[i].read = csr_wdata_int[(i%4)*PMP_CFG_W];
1818
- cve2_csr #(
1819
- .Width ($bits(pmp_cfg_t)),
1820
- .ResetValue(pmp_cfg_rst[i])
1821
- ) u_pmp_cfg_csr (
1822
- .clk_i (clk_i),
1823
- .rst_ni (rst_ni),
1824
- .wr_data_i ({pmp_cfg_wdata[i]}),
1825
- .wr_en_i (pmp_cfg_we[i]),
1826
- .rd_data_o (pmp_cfg[i]),
1827
- .rd_error_o(pmp_cfg_err[i])
1828
- );
1829
- // MSECCFG.RLB allows the lock bit to be bypassed (allowing cfg writes when MSECCFG.RLB is
1830
- // set).
1831
- assign pmp_cfg_locked[i] = pmp_cfg[i].lock & ~pmp_mseccfg_q.rlb;
1832
- // --------------------------
1833
- // Instantiate addr registers
1834
- // --------------------------
1835
- if (i < PMPNumRegions - 1) begin : g_lower
1836
- assign pmp_addr_we[i] = csr_we_int & ~pmp_cfg_locked[i] &
1837
- (~pmp_cfg_locked[i+1] | (pmp_cfg[i+1].mode != PMP_MODE_TOR)) &
1838
- (csr_addr == (CSR_OFF_PMP_ADDR + i[11:0]));
1839
- end else begin : g_upper
1840
- assign pmp_addr_we[i] = csr_we_int & ~pmp_cfg_locked[i] &
1841
- (csr_addr == (CSR_OFF_PMP_ADDR + i[11:0]));
1842
- end
1843
- cve2_csr #(
1844
- .Width (PMPAddrWidth),
1845
- .ResetValue(pmp_addr_rst[i][33-:PMPAddrWidth])
1846
- ) u_pmp_addr_csr (
1847
- .clk_i (clk_i),
1848
- .rst_ni (rst_ni),
1849
- .wr_data_i (csr_wdata_int[31-:PMPAddrWidth]),
1850
- .wr_en_i (pmp_addr_we[i]),
1851
- .rd_data_o (pmp_addr[i]),
1852
- .rd_error_o(pmp_addr_err[i])
1853
- );
1854
- assign csr_pmp_cfg_o[i] = pmp_cfg[i];
1855
- assign csr_pmp_addr_o[i] = {pmp_addr_rdata[i], 2'b00};
1856
- end
1857
- assign pmp_mseccfg_we = csr_we_int & (csr_addr == CSR_MSECCFG);
1858
- // MSECCFG.MML/MSECCFG.MMWP cannot be unset once set
1859
- assign pmp_mseccfg_d.mml = pmp_mseccfg_q.mml ? 1'b1 : csr_wdata_int[CSR_MSECCFG_MML_BIT];
1860
- assign pmp_mseccfg_d.mmwp = pmp_mseccfg_q.mmwp ? 1'b1 : csr_wdata_int[CSR_MSECCFG_MMWP_BIT];
1861
- // pmp_cfg_locked factors in MSECCFG.RLB so any_pmp_entry_locked will only be set if MSECCFG.RLB
1862
- // is unset
1863
- assign any_pmp_entry_locked = |pmp_cfg_locked;
1864
- // When any PMP entry is locked (A PMP entry has the L bit set and MSECCFG.RLB is unset),
1865
- // MSECCFG.RLB cannot be set again
1866
- assign pmp_mseccfg_d.rlb = any_pmp_entry_locked ? 1'b0 : csr_wdata_int[CSR_MSECCFG_RLB_BIT];
1867
- cve2_csr #(
1868
- .Width ($bits(pmp_mseccfg_t)),
1869
- .ResetValue(pmp_mseccfg_rst)
1870
- ) u_pmp_mseccfg (
1871
- .clk_i (clk_i),
1872
- .rst_ni (rst_ni),
1873
- .wr_data_i (pmp_mseccfg_d),
1874
- .wr_en_i (pmp_mseccfg_we),
1875
- .rd_data_o (pmp_mseccfg_q),
1876
- .rd_error_o(pmp_mseccfg_err)
1877
- );
1878
- assign pmp_mseccfg = pmp_mseccfg_q;
1879
- end else begin : g_no_pmp_tieoffs
1880
- // Generate tieoffs when PMP is not configured
1881
- for (genvar i = 0; i < PMP_MAX_REGIONS; i++) begin : g_rdata
1882
- assign pmp_addr_rdata[i] = '0;
1883
- assign pmp_cfg_rdata[i] = '0;
1884
- end
1885
- for (genvar i = 0; i < PMPNumRegions; i++) begin : g_outputs
1886
- assign csr_pmp_cfg_o[i] = pmp_cfg_t'(1'b0);
1887
- assign csr_pmp_addr_o[i] = '0;
1888
- end
1889
- assign pmp_mseccfg = '0;
1890
- end
1891
- assign csr_pmp_mseccfg_o = pmp_mseccfg;
1892
- //////////////////////////
1893
- // Performance monitor //
1894
- //////////////////////////
1895
- // update enable signals
1896
- always_comb begin : mcountinhibit_update
1897
- if (mcountinhibit_we == 1'b1) begin
1898
- // bit 1 must always be 0
1899
- mcountinhibit_d = {csr_wdata_int[MHPMCounterNum+2:2], 1'b0, csr_wdata_int[0]};
1900
- end else begin
1901
- mcountinhibit_d = mcountinhibit_q;
1902
- end
1903
- end
1904
- // event selection (hardwired) & control
1905
- always_comb begin : gen_mhpmcounter_incr
1906
- // Assign inactive counters (first to prevent latch inference)
1907
- for (int unsigned i = 0; i < 32; i++) begin : gen_mhpmcounter_incr_inactive
1908
- mhpmcounter_incr[i] = 1'b0;
1909
- end
1910
- // When adding or altering performance counter meanings and default
1911
- // mappings please update dv/verilator/pcount/cpp/cve2_pcounts.cc
1912
- // appropriately.
1913
- //
1914
- // active counters
1915
- mhpmcounter_incr[0] = 1'b1; // mcycle
1916
- mhpmcounter_incr[1] = 1'b0; // reserved
1917
- mhpmcounter_incr[2] = instr_ret_i; // minstret
1918
- mhpmcounter_incr[3] = dside_wait_i; // cycles waiting for data memory
1919
- mhpmcounter_incr[4] = iside_wait_i; // cycles waiting for instr fetches
1920
- mhpmcounter_incr[5] = mem_load_i; // num of loads
1921
- mhpmcounter_incr[6] = mem_store_i; // num of stores
1922
- mhpmcounter_incr[7] = jump_i; // num of jumps (unconditional)
1923
- mhpmcounter_incr[8] = branch_i; // num of branches (conditional)
1924
- mhpmcounter_incr[9] = branch_taken_i; // num of taken branches (conditional)
1925
- mhpmcounter_incr[10] = instr_ret_compressed_i; // num of compressed instr
1926
- mhpmcounter_incr[11] = wfi_wait_i; // cycles waiting for multiply
1927
- mhpmcounter_incr[12] = div_wait_i; // cycles waiting for divide
1928
- end
1929
- // event selector (hardwired, 0 means no event)
1930
- always_comb begin : gen_mhpmevent
1931
- // activate all
1932
- for (int i = 0; i < 32; i++) begin : gen_mhpmevent_active
1933
- mhpmevent[i] = '0;
1934
- mhpmevent[i][i] = 1'b1;
1935
- end
1936
- // deactivate
1937
- mhpmevent[1] = '0; // not existing, reserved
1938
- for (int unsigned i = 3 + MHPMCounterNum; i < 32; i++) begin : gen_mhpmevent_inactive
1939
- mhpmevent[i] = '0;
1940
- end
1941
- end
1942
- // mcycle
1943
- cve2_counter #(
1944
- .CounterWidth(64)
1945
- ) mcycle_counter_i (
1946
- .clk_i(clk_i),
1947
- .rst_ni(rst_ni),
1948
- .counter_inc_i(mhpmcounter_incr[0] & ~mcountinhibit[0]),
1949
- .counterh_we_i(mhpmcounterh_we[0]),
1950
- .counter_we_i(mhpmcounter_we[0]),
1951
- .counter_val_i(csr_wdata_int),
1952
- .counter_val_o(mhpmcounter[0]),
1953
- .counter_val_upd_o()
1954
- );
1955
- // minstret
1956
- cve2_counter #(
1957
- .CounterWidth(64),
1958
- .ProvideValUpd(1)
1959
- ) minstret_counter_i (
1960
- .clk_i(clk_i),
1961
- .rst_ni(rst_ni),
1962
- .counter_inc_i(mhpmcounter_incr[2] & ~mcountinhibit[2]),
1963
- .counterh_we_i(mhpmcounterh_we[2]),
1964
- .counter_we_i(mhpmcounter_we[2]),
1965
- .counter_val_i(csr_wdata_int),
1966
- .counter_val_o(minstret_raw),
1967
- .counter_val_upd_o()
1968
- );
1969
- // Where the writeback stage is present instruction in ID observing value of minstret must take
1970
- // into account any instruction in the writeback stage. If one is present the incremented value of
1971
- // minstret is used. A speculative version of the signal is used to aid timing. When the writeback
1972
- // stage sees an exception (so the speculative signal is incorrect) the ID stage will be flushed
1973
- // so the incorrect value doesn't matter. A similar behaviour is required for the compressed
1974
- // instruction retired counter below. When the writeback stage isn't present the speculative
1975
- // signals are always 0.
1976
- assign mhpmcounter[2] = minstret_raw;
1977
- // reserved:
1978
- assign mhpmcounter[1] = '0;
1979
- assign unused_mhpmcounter_we_1 = mhpmcounter_we[1];
1980
- assign unused_mhpmcounterh_we_1 = mhpmcounterh_we[1];
1981
- assign unused_mhpmcounter_incr_1 = mhpmcounter_incr[1];
1982
- // Iterate through optionally included counters (MHPMCounterNum controls how many are included)
1983
- for (genvar i = 0; i < 29; i++) begin : gen_cntrs
1984
- localparam int Cnt = i + 3;
1985
- if (i < MHPMCounterNum) begin : gen_imp
1986
- logic [63:0] mhpmcounter_raw, mhpmcounter_next;
1987
- cve2_counter #(
1988
- .CounterWidth(MHPMCounterWidth),
1989
- .ProvideValUpd(Cnt == 10)
1990
- ) mcounters_variable_i (
1991
- .clk_i(clk_i),
1992
- .rst_ni(rst_ni),
1993
- .counter_inc_i(mhpmcounter_incr[Cnt] & ~mcountinhibit[Cnt]),
1994
- .counterh_we_i(mhpmcounterh_we[Cnt]),
1995
- .counter_we_i(mhpmcounter_we[Cnt]),
1996
- .counter_val_i(csr_wdata_int),
1997
- .counter_val_o(mhpmcounter_raw),
1998
- .counter_val_upd_o(mhpmcounter_next)
1999
- );
2000
- if (Cnt == 10) begin : gen_compressed_instr_cnt
2001
- // Special behaviour for reading compressed instruction retired counter, see comment on
2002
- // `mhpmcounter[2]` above for further information.
2003
- assign mhpmcounter[Cnt] =
2004
- mhpmcounter_raw;
2005
- end else begin : gen_other_cnts
2006
- logic [63:0] unused_mhpmcounter_next;
2007
- // All other counters just see the raw counter value directly.
2008
- assign mhpmcounter[Cnt] = mhpmcounter_raw;
2009
- assign unused_mhpmcounter_next = mhpmcounter_next;
2010
- end
2011
- end else begin : gen_unimp
2012
- assign mhpmcounter[Cnt] = '0;
2013
- end
2014
- end
2015
- if (MHPMCounterNum < 29) begin : g_mcountinhibit_reduced
2016
- logic [29-MHPMCounterNum-1:0] unused_mhphcounter_we;
2017
- logic [29-MHPMCounterNum-1:0] unused_mhphcounterh_we;
2018
- logic [29-MHPMCounterNum-1:0] unused_mhphcounter_incr;
2019
- assign mcountinhibit = {{29 - MHPMCounterNum{1'b1}}, mcountinhibit_q};
2020
- // Lint tieoffs for unused bits
2021
- assign unused_mhphcounter_we = mhpmcounter_we[31:MHPMCounterNum+3];
2022
- assign unused_mhphcounterh_we = mhpmcounterh_we[31:MHPMCounterNum+3];
2023
- assign unused_mhphcounter_incr = mhpmcounter_incr[31:MHPMCounterNum+3];
2024
- end else begin : g_mcountinhibit_full
2025
- assign mcountinhibit = mcountinhibit_q;
2026
- end
2027
- always_ff @(posedge clk_i or negedge rst_ni) begin
2028
- if (!rst_ni) begin
2029
- mcountinhibit_q <= '0;
2030
- end else begin
2031
- mcountinhibit_q <= mcountinhibit_d;
2032
- end
2033
- end
2034
- /////////////////////////////
2035
- // Debug trigger registers //
2036
- /////////////////////////////
2037
- if (DbgTriggerEn) begin : gen_trigger_regs
2038
- localparam int unsigned DbgHwNumLen = DbgHwBreakNum > 1 ? $clog2(DbgHwBreakNum) : 1;
2039
- localparam int unsigned MaxTselect = DbgHwBreakNum - 1;
2040
- // Register values
2041
- logic [DbgHwNumLen-1:0] tselect_d, tselect_q;
2042
- logic tmatch_control_d;
2043
- logic [DbgHwBreakNum-1:0] tmatch_control_q;
2044
- logic [31:0] tmatch_value_d;
2045
- logic [31:0] tmatch_value_q[DbgHwBreakNum];
2046
- logic selected_tmatch_control;
2047
- logic [31:0] selected_tmatch_value;
2048
- // Write enables
2049
- logic tselect_we;
2050
- logic [DbgHwBreakNum-1:0] tmatch_control_we;
2051
- logic [DbgHwBreakNum-1:0] tmatch_value_we;
2052
- // Trigger comparison result
2053
- logic [DbgHwBreakNum-1:0] trigger_match;
2054
- // Write select
2055
- assign tselect_we = csr_we_int & debug_mode_i & (csr_addr_i == CSR_TSELECT);
2056
- for (genvar i = 0; i < DbgHwBreakNum; i++) begin : g_dbg_tmatch_we
2057
- assign tmatch_control_we[i] = (i[DbgHwNumLen-1:0] == tselect_q) & csr_we_int & debug_mode_i &
2058
- (csr_addr_i == CSR_TDATA1);
2059
- assign tmatch_value_we[i] = (i[DbgHwNumLen-1:0] == tselect_q) & csr_we_int & debug_mode_i &
2060
- (csr_addr_i == CSR_TDATA2);
2061
- end
2062
- // Debug interface tests the available number of triggers by writing and reading the trigger
2063
- // select register. Only allow changes to the register if it is within the supported region.
2064
- assign tselect_d = (csr_wdata_int < DbgHwBreakNum) ? csr_wdata_int[DbgHwNumLen-1:0] :
2065
- MaxTselect[DbgHwNumLen-1:0];
2066
- // tmatch_control is enabled when the execute bit is set
2067
- assign tmatch_control_d = csr_wdata_int[2];
2068
- assign tmatch_value_d = csr_wdata_int[31:0];
2069
- // Registers
2070
- cve2_csr #(
2071
- .Width (DbgHwNumLen),
2072
- .ShadowCopy(1'b0),
2073
- .ResetValue('0)
2074
- ) u_tselect_csr (
2075
- .clk_i (clk_i),
2076
- .rst_ni (rst_ni),
2077
- .wr_data_i (tselect_d),
2078
- .wr_en_i (tselect_we),
2079
- .rd_data_o (tselect_q),
2080
- .rd_error_o()
2081
- );
2082
- for (genvar i = 0; i < DbgHwBreakNum; i++) begin : g_dbg_tmatch_reg
2083
- cve2_csr #(
2084
- .Width (1),
2085
- .ShadowCopy(1'b0),
2086
- .ResetValue('0)
2087
- ) u_tmatch_control_csr (
2088
- .clk_i (clk_i),
2089
- .rst_ni (rst_ni),
2090
- .wr_data_i (tmatch_control_d),
2091
- .wr_en_i (tmatch_control_we[i]),
2092
- .rd_data_o (tmatch_control_q[i]),
2093
- .rd_error_o()
2094
- );
2095
- cve2_csr #(
2096
- .Width (32),
2097
- .ShadowCopy(1'b0),
2098
- .ResetValue('0)
2099
- ) u_tmatch_value_csr (
2100
- .clk_i (clk_i),
2101
- .rst_ni (rst_ni),
2102
- .wr_data_i (tmatch_value_d),
2103
- .wr_en_i (tmatch_value_we[i]),
2104
- .rd_data_o (tmatch_value_q[i]),
2105
- .rd_error_o()
2106
- );
2107
- end
2108
- // Assign read data
2109
- // TSELECT - number of supported triggers defined by parameter DbgHwBreakNum
2110
- localparam int unsigned TSelectRdataPadlen = DbgHwNumLen >= 32 ? 0 : (32 - DbgHwNumLen);
2111
- assign tselect_rdata = {{TSelectRdataPadlen{1'b0}}, tselect_q};
2112
- if (DbgHwBreakNum > 1) begin : g_dbg_tmatch_multiple_select
2113
- assign selected_tmatch_control = tmatch_control_q[tselect_q];
2114
- assign selected_tmatch_value = tmatch_value_q[tselect_q];
2115
- end else begin : g_dbg_tmatch_single_select
2116
- assign selected_tmatch_control = tmatch_control_q[0];
2117
- assign selected_tmatch_value = tmatch_value_q[0];
2118
- end
2119
- // TDATA0 - only support simple address matching
2120
- assign tmatch_control_rdata = {4'h2, // type : address/data match
2121
- 1'b1, // dmode : access from D mode only
2122
- 6'h00, // maskmax : exact match only
2123
- 1'b0, // hit : not supported
2124
- 1'b0, // select : address match only
2125
- 1'b0, // timing : match before execution
2126
- 2'b00, // sizelo : match any access
2127
- 4'h1, // action : enter debug mode
2128
- 1'b0, // chain : not supported
2129
- 4'h0, // match : simple match
2130
- 1'b1, // m : match in m-mode
2131
- 1'b0, // 0 : zero
2132
- 1'b0, // s : not supported
2133
- 1'b1, // u : match in u-mode
2134
- selected_tmatch_control, // execute : match instruction address
2135
- 1'b0, // store : not supported
2136
- 1'b0}; // load : not supported
2137
- // TDATA1 - address match value only
2138
- assign tmatch_value_rdata = selected_tmatch_value;
2139
- // Breakpoint matching
2140
- // We match against the next address, as the breakpoint must be taken before execution
2141
- for (genvar i = 0; i < DbgHwBreakNum; i++) begin : g_dbg_trigger_match
2142
- assign trigger_match[i] = tmatch_control_q[i] & (pc_if_i[31:0] == tmatch_value_q[i]);
2143
- end
2144
- assign trigger_match_o = |trigger_match;
2145
- end else begin : gen_no_trigger_regs
2146
- assign tselect_rdata = 'b0;
2147
- assign tmatch_control_rdata = 'b0;
2148
- assign tmatch_value_rdata = 'b0;
2149
- assign trigger_match_o = 'b0;
2150
- end
2151
- //////////////////////////
2152
- // CPU control register //
2153
- //////////////////////////
2154
- ////////////////
2155
- // Assertions //
2156
- ////////////////
2157
- endmodule
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p5/mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"conditional_statement": [[53195, 53312], [51262, 51969], [25578, 25676], [23261, 23376], [52480, 53040], [45257, 45762], [75216, 75332], [52289, 52372], [23610, 23670], [39771, 40104], [46870, 50486], [40149, 40264]], "blocking_assignment": [[70941, 71016], [45974, 45994], [45924, 45944], [25344, 25386], [25412, 25450], [38496, 38567], [52665, 52687], [47848, 47864], [46072, 46127]], "module_program_interface_instantiation": [[57857, 58119], [55085, 55344], [58793, 59053], [73359, 73821], [59074, 59339], [55357, 55597], [58491, 58774], [55867, 56116], [56926, 57150], [56133, 56392], [71826, 72189], [57319, 57586], [71469, 71809], [56407, 56654], [57599, 57839], [58137, 58399], [56668, 56912]], "always_construct": [[23206, 23382], [69602, 71022], [71075, 71454], [69285, 69556], [24932, 25464], [53140, 53318], [25523, 25682], [53566, 53904], [36761, 45768], [75161, 75338], [45788, 53106]], "case_statement": [[36833, 45252], [46898, 50478], [50551, 53100], [50608, 50824], [53588, 53898]], "ansi_port_declaration": [[29307, 29369], [28127, 28171], [29814, 29851], [30722, 30809], [24481, 24514], [30254, 30337], [28676, 28717], [31175, 31265], [24444, 24478]], "continuous_assign": [[36576, 36617], [55727, 55783], [36705, 36742], [81148, 81182], [36325, 36390], [53469, 53538], [36150, 36192]], "parameter_declaration": [[13332, 13380], [16946, 16990], [27543, 27594], [13140, 13186], [12379, 12461], [27809, 27877], [13434, 13482], [12680, 12733], [13238, 13284], [6523, 6571], [27436, 27486], [24310, 24341]], "nonblocking_assignment": [[75289, 75324], [23347, 23368], [53275, 53304], [25645, 25668]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p6/all_mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"module_program_interface_instantiation": [], "continuous_assign": [[28366, 28399], [28402, 28439], [28610, 28666], [28669, 28738], [28741, 28837], [28840, 28886], [28889, 28976], [29031, 29084], [29499, 29525], [29530, 29559], [29583, 29612], [29643, 29675], [29678, 29710], [29713, 29745], [29748, 29842], [29845, 29884], [29887, 29937], [29966, 29996], [29999, 30036], [30158, 30391], [30444, 30476], [67315, 67367], [67370, 67421], [67537, 67594], [67688, 67732], [67762, 67823]], "blocking_assignment": [[30605, 30623], [30843, 30866], [30953, 30982], [30987, 31016], [31021, 31050], [31055, 31090], [31095, 31125], [31130, 31189], [31194, 31223], [31228, 31257], [31262, 31291], [31296, 31325], [31330, 31359], [31364, 31393], [31398, 31434], [31439, 31468], [31473, 31503], [31508, 31537], [31542, 31571], [31576, 31605], [31610, 31639], [31644, 31673], [31678, 31707], [31712, 31741], [31746, 31775], [31780, 31826], [31957, 31983], [32083, 32107], [32118, 32142], [32214, 32238], [32321, 32347], [32447, 32471], [32482, 32506], [32578, 32602], [32665, 32685], [32706, 32724], [32780, 32809], [32998, 33018], [33038, 33058], [33083, 33101], [33110, 33128], [33242, 33268], [33277, 33303], [33312, 33338], [33347, 33373], [33413, 33433], [33522, 33549], [33569, 33596], [33616, 33643], [33663, 33683], [33743, 33770], [33779, 33806], [33815, 33843], [33883, 33918], [33992, 34021], [34039, 34068], [34104, 34135], [34183, 34228], [34296, 34316], [34462, 34486], [34561, 34585], [34668, 34692], [34701, 34725], [34869, 34889], [34978, 35046], [35157, 35235], [35469, 35538], [35682, 35760], [35810, 35830], [36353, 36418], [37030, 37108], [37158, 37178], [37245, 37265], [37371, 37451], [37642, 37709], [37823, 37901], [38044, 38112], [38242, 38317], [38399, 38473], [38527, 38547], [38719, 38793], [38877, 38951], [39005, 39025], [39217, 39295], [39349, 39369], [39437, 39457], [39529, 39549], [39643, 39666], [39675, 39698], [39707, 39730], [39803, 39880], [40343, 40363], [41319, 41376], [41977, 42055], [42182, 42245], [42342, 42377], [42392, 42422], [42437, 42496], [42576, 42611], [42626, 42656], [42671, 42730], [42812, 42847], [42862, 42892], [42907, 42966], [43047, 43082], [43097, 43127], [43142, 43201], [43280, 43314], [43329, 43359], [43374, 43433], [43513, 43547], [43562, 43592], [43607, 43666], [43745, 43779], [43794, 43824], [43839, 43898], [43978, 44012], [44027, 44057], [44072, 44131], [44189, 44209], [44525, 44548], [44832, 44855], [44868, 44891], [44949, 44973], [45041, 45067], [45351, 45371], [45449, 45468], [45513, 45532], [45577, 45596], [45640, 45658], [45694, 45714], [45838, 45858], [45950, 45974], [45985, 46040], [46051, 46075], [46120, 46146], [46219, 46241], [46263, 46283], [46305, 46327], [46349, 46368], [46397, 46424], [46476, 46496], [46643, 46663], [47069, 47092], [47099, 47122], [47129, 47152], [47159, 47182], [47189, 47212], [47219, 47242], [47249, 47272], [47325, 47376], [47385, 47436], [47445, 47496], [47505, 47563], [47709, 47739], [47744, 47774], [47779, 47809], [47814, 47846], [47851, 47880], [47885, 47932], [47937, 47963], [47968, 47994], [47999, 48025], [48030, 48056], [48316, 48350], [48361, 48392], [48403, 48433], [48444, 48474], [48546, 48580], [48591, 48622], [48633, 48669], [48680, 48710], [48919, 48952], [48963, 48994], [49005, 49035], [49046, 49076], [49148, 49182], [49193, 49224], [49235, 49271], [49282, 49312], [49474, 49498], [49518, 49542], [49562, 49586], [49606, 49630], [49650, 49675], [49695, 49720], [49973, 50006], [50017, 50050], [50124, 50158], [50169, 50200], [50293, 50323], [50334, 50364], [50490, 50522], [50531, 50563], [50572, 50601], [50681, 50711], [50722, 50753], [50809, 50842], [50884, 50914], [50923, 50954], [50963, 50993], [51109, 51140], [51149, 51180], [51189, 51222], [51231, 51261], [51270, 51300], [51375, 51409], [51418, 51449], [51458, 51488], [51497, 51527], [51610, 51643], [51652, 51683], [51692, 51722], [51780, 51823], [51842, 51906], [51925, 51998], [52017, 52074], [52093, 52140], [52159, 52207], [52346, 52409], [52561, 52586], [52634, 52696], [52724, 52784], [52812, 52876], [52984, 53010], [53126, 53160], [53194, 53228], [53262, 53297], [53331, 53368], [53402, 53439], [53583, 53624], [53649, 53673], [53867, 53908], [53933, 53957], [54151, 54192], [54217, 54241], [54435, 54477], [54502, 54526], [54720, 54762], [54787, 54811], [55005, 55047], [55072, 55096], [55314, 55374], [55534, 55559], [55576, 55600], [55666, 55683], [55733, 55750], [55876, 55939], [55969, 56039], [56198, 56223], [56275, 56341], [56397, 56462], [56483, 56507], [56559, 56626], [56656, 56726], [56949, 56977], [57193, 57268], [57349, 57431], [57594, 57626], [57635, 57667], [57857, 57893], [57910, 57934], [58000, 58017], [58067, 58084], [58176, 58212], [58229, 58253], [58319, 58336], [58386, 58403], [58495, 58530], [58547, 58571], [58637, 58654], [58704, 58721], [58813, 58848], [58865, 58889], [58955, 58972], [59022, 59039], [59292, 59326], [59362, 59396], [59432, 59477], [59513, 59567], [59603, 59637], [59673, 59706], [59742, 59776], [59812, 59861], [59897, 59947], [59983, 60036], [60174, 60199], [60216, 60240], [60376, 60401], [60418, 60442], [60536, 60561], [60621, 60646], [60706, 60732], [60792, 60818], [60878, 60904], [60964, 60991], [61051, 61078], [61138, 61164], [61224, 61249], [61309, 61335], [61420, 61448], [61508, 61536], [61596, 61624], [61709, 61735], [61795, 61821], [61881, 61907], [61967, 61993], [62078, 62103], [62188, 62214], [62274, 62300], [62408, 62434], [62558, 62586], [62710, 62739], [62863, 62892], [63016, 63045], [63169, 63194], [63318, 63343], [63492, 63519], [63643, 63671], [63795, 63823], [63966, 63999], [64016, 64040], [64176, 64207], [64224, 64248], [64411, 64436], [64451, 64503], [64583, 64608], [64623, 64675], [64757, 64782], [64797, 64849], [64930, 64955], [64970, 65022], [65101, 65126], [65141, 65193], [65273, 65298], [65313, 65365], [65444, 65469], [65484, 65536], [65616, 65641], [65656, 65708], [66051, 66087], [66100, 66132], [66145, 66175], [66315, 66348], [66363, 66393], [66408, 66443], [66458, 66487], [66681, 66713], [66724, 66754], [66832, 66862], [66873, 66902], [66913, 66978], [67072, 67102], [67140, 67172]], "nonblocking_assignment": [[29269, 29287], [29317, 29340]], "case_statement": [[31831, 46518], [32862, 33074], [33476, 33699], [33948, 34346], [34734, 39565], [34926, 37285], [35916, 37202], [37493, 39479], [39914, 44243], [44363, 45097], [45236, 45732], [46171, 46386], [48061, 67237], [49424, 49757], [51731, 57516], [52288, 55272], [53062, 55203], [55816, 57076], [57753, 59122], [59170, 65765], [65885, 66538]], "conditional_statement": [[29242, 29350], [30750, 30874], [31992, 32250], [32356, 32614], [32623, 32697], [33382, 33445], [34148, 34244], [35586, 35850], [37336, 39495], [38164, 38569], [38345, 38569], [38641, 39047], [38821, 39047], [39119, 39391], [39739, 44255], [44904, 44989], [45143, 46436], [45777, 45872], [46086, 46160], [46609, 46671], [47039, 47582], [47296, 47574], [48240, 48722], [48843, 49324], [49883, 50376], [50610, 50765], [52244, 55390], [52509, 52586], [52960, 53010], [53501, 53699], [53785, 53983], [54069, 54267], [54353, 54552], [54638, 54837], [54923, 55122], [55441, 57465], [55485, 57094], [55617, 55770], [56146, 56223], [56842, 57001], [56922, 56977], [57136, 57449], [57292, 57449], [57676, 65777], [57711, 59136], [57951, 58104], [58270, 58423], [58588, 58741], [58906, 59059], [60128, 60258], [60330, 60460], [60512, 60561], [60597, 60646], [60682, 60732], [60768, 60818], [60854, 60904], [60940, 60991], [61027, 61078], [61114, 61164], [61200, 61249], [61285, 61335], [61396, 61448], [61484, 61536], [61572, 61624], [61685, 61735], [61771, 61821], [61857, 61907], [61943, 61993], [62054, 62103], [62164, 62214], [62250, 62300], [62356, 62434], [62506, 62586], [62658, 62739], [62811, 62892], [62964, 63045], [63117, 63194], [63266, 63343], [63440, 63519], [63591, 63671], [63743, 63823], [63920, 64058], [64130, 64266], [66584, 67198], [66989, 67186]], "always_construct": [[29184, 29358], [30563, 30880], [30931, 47588], [47687, 67243]], "parameter_declaration": [[6471, 6520], [6523, 6571], [6594, 6628], [6631, 6665], [6668, 6702], [12379, 12461], [12464, 12546], [12570, 12622], [12625, 12677], [12680, 12733], [12736, 12789], [12792, 12845], [12848, 12901], [12925, 13002], [13044, 13089], [13092, 13137], [13140, 13186], [13189, 13235], [13238, 13284], [13332, 13380], [13383, 13431], [13434, 13482], [13551, 13619], [13622, 13688], [13787, 13814], [16708, 16752], [16755, 16799], [16802, 16847], [16850, 16895], [16898, 16943], [16946, 16990], [16993, 17037], [17040, 17096], [22970, 23008], [23011, 23067], [23070, 23126], [23129, 23177]], "ansi_port_declaration": [[23184, 23219], [23222, 23258], [23285, 23365], [23368, 23445], [23448, 23530], [23602, 23692], [23695, 23775], [23778, 23869], [23872, 23948], [23985, 24078], [24081, 24170], [24173, 24262], [24350, 24441], [24460, 24549], [24552, 24641], [24644, 24687], [24690, 24733], [24736, 24779], [24782, 24825], [24828, 24871], [24874, 24920], [24942, 25019], [25022, 25100], [25103, 25149], [25152, 25198], [25201, 25247], [25250, 25294], [25297, 25386], [25389, 25478], [25481, 25588], [25600, 25682], [25685, 25779], [25861, 25953], [26027, 26114], [26133, 26222], [26225, 26321], [26324, 26418], [26421, 26515], [26518, 26570], [26573, 26628], [26641, 26713], [26716, 26802], [26814, 26905], [26908, 26979], [26982, 27072], [27149, 27241], [27350, 27412], [27434, 27524], [27527, 27575]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p6/cve2_decoder.sv DELETED
@@ -1,1765 +0,0 @@
1
- // Copyright (c) 2025 Eclipse Foundation
2
- // Copyright lowRISC contributors.
3
- // Copyright 2017 ETH Zurich and University of Bologna, see also CREDITS.md.
4
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
5
- // SPDX-License-Identifier: Apache-2.0
6
- /**
7
- * Package with constants used by CVE2
8
- */
9
- package cve2_pkg;
10
- ////////////////
11
- // IO Structs //
12
- ////////////////
13
- typedef struct packed {
14
- logic [31:0] current_pc;
15
- logic [31:0] next_pc;
16
- logic [31:0] last_data_addr;
17
- logic [31:0] exception_addr;
18
- } crash_dump_t;
19
- typedef struct packed {
20
- logic dummy_instr_id;
21
- logic [4:0] raddr_a;
22
- logic [4:0] waddr_a;
23
- logic we_a;
24
- logic [4:0] raddr_b;
25
- } core2rf_t;
26
- /////////////////////
27
- // Parameter Enums //
28
- /////////////////////
29
- typedef enum integer {
30
- RV32MNone = 0,
31
- RV32MSlow = 1,
32
- RV32MFast = 2,
33
- RV32MSingleCycle = 3
34
- } rv32m_e;
35
- typedef enum integer {
36
- RV32BNone = 0,
37
- RV32BBalanced = 1,
38
- RV32BOTEarlGrey = 2,
39
- RV32BFull = 3
40
- } rv32b_e;
41
- /////////////
42
- // Opcodes //
43
- /////////////
44
- typedef enum logic [6:0] {
45
- OPCODE_LOAD = 7'h03,
46
- OPCODE_MISC_MEM = 7'h0f,
47
- OPCODE_OP_IMM = 7'h13,
48
- OPCODE_AUIPC = 7'h17,
49
- OPCODE_STORE = 7'h23,
50
- OPCODE_OP = 7'h33,
51
- OPCODE_LUI = 7'h37,
52
- OPCODE_BRANCH = 7'h63,
53
- OPCODE_JALR = 7'h67,
54
- OPCODE_JAL = 7'h6f,
55
- OPCODE_SYSTEM = 7'h73
56
- } opcode_e;
57
- ////////////////////
58
- // ALU operations //
59
- ////////////////////
60
- typedef enum logic [6:0] {
61
- // Arithmetics
62
- ALU_ADD,
63
- ALU_SUB,
64
- // Logics
65
- ALU_XOR,
66
- ALU_OR,
67
- ALU_AND,
68
- // RV32B
69
- ALU_XNOR,
70
- ALU_ORN,
71
- ALU_ANDN,
72
- // Shifts
73
- ALU_SRA,
74
- ALU_SRL,
75
- ALU_SLL,
76
- // RV32B
77
- ALU_SRO,
78
- ALU_SLO,
79
- ALU_ROR,
80
- ALU_ROL,
81
- ALU_GREV,
82
- ALU_GORC,
83
- ALU_SHFL,
84
- ALU_UNSHFL,
85
- ALU_XPERM_N,
86
- ALU_XPERM_B,
87
- ALU_XPERM_H,
88
- // Address Calculations
89
- // RV32B
90
- ALU_SH1ADD,
91
- ALU_SH2ADD,
92
- ALU_SH3ADD,
93
- // Comparisons
94
- ALU_LT,
95
- ALU_LTU,
96
- ALU_GE,
97
- ALU_GEU,
98
- ALU_EQ,
99
- ALU_NE,
100
- // RV32B
101
- ALU_MIN,
102
- ALU_MINU,
103
- ALU_MAX,
104
- ALU_MAXU,
105
- // Pack
106
- // RV32B
107
- ALU_PACK,
108
- ALU_PACKU,
109
- ALU_PACKH,
110
- // Sign-Extend
111
- // RV32B
112
- ALU_SEXTB,
113
- ALU_SEXTH,
114
- // Bitcounting
115
- // RV32B
116
- ALU_CLZ,
117
- ALU_CTZ,
118
- ALU_CPOP,
119
- // Set lower than
120
- ALU_SLT,
121
- ALU_SLTU,
122
- // Ternary Bitmanip Operations
123
- // RV32B
124
- ALU_CMOV,
125
- ALU_CMIX,
126
- ALU_FSL,
127
- ALU_FSR,
128
- // Single-Bit Operations
129
- // RV32B
130
- ALU_BSET,
131
- ALU_BCLR,
132
- ALU_BINV,
133
- ALU_BEXT,
134
- // Bit Compress / Decompress
135
- // RV32B
136
- ALU_BCOMPRESS,
137
- ALU_BDECOMPRESS,
138
- // Bit Field Place
139
- // RV32B
140
- ALU_BFP,
141
- // Carry-less Multiply
142
- // RV32B
143
- ALU_CLMUL,
144
- ALU_CLMULR,
145
- ALU_CLMULH,
146
- // Cyclic Redundancy Check
147
- ALU_CRC32_B,
148
- ALU_CRC32C_B,
149
- ALU_CRC32_H,
150
- ALU_CRC32C_H,
151
- ALU_CRC32_W,
152
- ALU_CRC32C_W
153
- } alu_op_e;
154
- typedef enum logic [1:0] {
155
- // Multiplier/divider
156
- MD_OP_MULL,
157
- MD_OP_MULH,
158
- MD_OP_DIV,
159
- MD_OP_REM
160
- } md_op_e;
161
- //////////////////////////////////
162
- // Control and status registers //
163
- //////////////////////////////////
164
- // CSR operations
165
- typedef enum logic [1:0] {
166
- CSR_OP_READ,
167
- CSR_OP_WRITE,
168
- CSR_OP_SET,
169
- CSR_OP_CLEAR
170
- } csr_op_e;
171
- // Privileged mode
172
- typedef enum logic[1:0] {
173
- PRIV_LVL_M = 2'b11,
174
- PRIV_LVL_H = 2'b10,
175
- PRIV_LVL_S = 2'b01,
176
- PRIV_LVL_U = 2'b00
177
- } priv_lvl_e;
178
- // Constants for the dcsr.xdebugver fields
179
- typedef enum logic[3:0] {
180
- XDEBUGVER_NO = 4'd0, // no external debug support
181
- XDEBUGVER_STD = 4'd4, // external debug according to RISC-V debug spec
182
- XDEBUGVER_NONSTD = 4'd15 // debug not conforming to RISC-V debug spec
183
- } x_debug_ver_e;
184
- //////////////
185
- // WB stage //
186
- //////////////
187
- // Type of instruction present in writeback stage
188
- typedef enum logic[1:0] {
189
- WB_INSTR_LOAD, // Instruction is awaiting load data
190
- WB_INSTR_STORE, // Instruction is awaiting store response
191
- WB_INSTR_OTHER // Instruction doesn't fit into above categories
192
- } wb_instr_type_e;
193
- //////////////
194
- // ID stage //
195
- //////////////
196
- // Operand a selection
197
- typedef enum logic[1:0] {
198
- OP_A_REG_A,
199
- OP_A_FWD,
200
- OP_A_CURRPC,
201
- OP_A_IMM
202
- } op_a_sel_e;
203
- // Immediate a selection
204
- typedef enum logic {
205
- IMM_A_Z,
206
- IMM_A_ZERO
207
- } imm_a_sel_e;
208
- // Operand b selection
209
- typedef enum logic {
210
- OP_B_REG_B,
211
- OP_B_IMM
212
- } op_b_sel_e;
213
- // Immediate b selection
214
- typedef enum logic [2:0] {
215
- IMM_B_I,
216
- IMM_B_S,
217
- IMM_B_B,
218
- IMM_B_U,
219
- IMM_B_J,
220
- IMM_B_INCR_PC,
221
- IMM_B_INCR_ADDR
222
- } imm_b_sel_e;
223
- // Regfile write data selection
224
- typedef enum {
225
- RF_WD_EX,
226
- RF_WD_CSR,
227
- RF_WD_COPROC // Only used when XInterface = 1
228
- } rf_wd_sel_e;
229
- //////////////
230
- // IF stage //
231
- //////////////
232
- // PC mux selection
233
- typedef enum logic [2:0] {
234
- PC_BOOT,
235
- PC_JUMP,
236
- PC_EXC,
237
- PC_ERET,
238
- PC_DRET,
239
- PC_BP
240
- } pc_sel_e;
241
- // Exception PC mux selection
242
- typedef enum logic [1:0] {
243
- EXC_PC_EXC,
244
- EXC_PC_IRQ,
245
- EXC_PC_DBD,
246
- EXC_PC_DBG_EXC // Exception while in debug mode
247
- } exc_pc_sel_e;
248
- // Interrupt requests
249
- typedef struct packed {
250
- logic irq_software;
251
- logic irq_timer;
252
- logic irq_external;
253
- logic [15:0] irq_fast; // 16 fast interrupts
254
- } irqs_t;
255
- // Exception cause
256
- typedef enum logic [6:0] {
257
- EXC_CAUSE_IRQ_SOFTWARE_M = {1'b1, 6'd03},
258
- EXC_CAUSE_IRQ_TIMER_M = {1'b1, 6'd07},
259
- EXC_CAUSE_IRQ_EXTERNAL_M = {1'b1, 6'd11},
260
- // EXC_CAUSE_IRQ_FAST_0 = {1'b1, 6'd16},
261
- // EXC_CAUSE_IRQ_FAST_15 = {1'b1, 6'd31},
262
- EXC_CAUSE_IRQ_NM = {1'b1, 6'd32},
263
- EXC_CAUSE_INSN_ADDR_MISA = {1'b0, 6'd00},
264
- EXC_CAUSE_INSTR_ACCESS_FAULT = {1'b0, 6'd01},
265
- EXC_CAUSE_ILLEGAL_INSN = {1'b0, 6'd02},
266
- EXC_CAUSE_BREAKPOINT = {1'b0, 6'd03},
267
- EXC_CAUSE_LOAD_ACCESS_FAULT = {1'b0, 6'd05},
268
- EXC_CAUSE_STORE_ACCESS_FAULT = {1'b0, 6'd07},
269
- EXC_CAUSE_ECALL_UMODE = {1'b0, 6'd08},
270
- EXC_CAUSE_ECALL_MMODE = {1'b0, 6'd11}
271
- } exc_cause_e;
272
- // Debug cause
273
- typedef enum logic [2:0] {
274
- DBG_CAUSE_NONE = 3'h0,
275
- DBG_CAUSE_EBREAK = 3'h1,
276
- DBG_CAUSE_TRIGGER = 3'h2,
277
- DBG_CAUSE_HALTREQ = 3'h3,
278
- DBG_CAUSE_STEP = 3'h4
279
- } dbg_cause_e;
280
- // PMP constants
281
- parameter int unsigned PMP_MAX_REGIONS = 16;
282
- parameter int unsigned PMP_CFG_W = 8;
283
- // PMP acces type
284
- parameter int unsigned PMP_I = 0;
285
- parameter int unsigned PMP_I2 = 1;
286
- parameter int unsigned PMP_D = 2;
287
- typedef enum logic [1:0] {
288
- PMP_ACC_EXEC = 2'b00,
289
- PMP_ACC_WRITE = 2'b01,
290
- PMP_ACC_READ = 2'b10
291
- } pmp_req_e;
292
- // PMP cfg structures
293
- typedef enum logic [1:0] {
294
- PMP_MODE_OFF = 2'b00,
295
- PMP_MODE_TOR = 2'b01,
296
- PMP_MODE_NA4 = 2'b10,
297
- PMP_MODE_NAPOT = 2'b11
298
- } pmp_cfg_mode_e;
299
- typedef struct packed {
300
- logic lock;
301
- pmp_cfg_mode_e mode;
302
- logic exec;
303
- logic write;
304
- logic read;
305
- } pmp_cfg_t;
306
- // Machine Security Configuration (ePMP)
307
- typedef struct packed {
308
- logic rlb; // Rule Locking Bypass
309
- logic mmwp; // Machine Mode Whitelist Policy
310
- logic mml; // Machine Mode Lockdown
311
- } pmp_mseccfg_t;
312
- // CSRs
313
- typedef enum logic[11:0] {
314
- // Machine information
315
- CSR_MVENDORID = 12'hF11,
316
- CSR_MARCHID = 12'hF12,
317
- CSR_MIMPID = 12'hF13,
318
- CSR_MHARTID = 12'hF14,
319
- CSR_MCONFIGPTR = 12'hF15,
320
- // Machine trap setup
321
- CSR_MSTATUS = 12'h300,
322
- CSR_MISA = 12'h301,
323
- CSR_MIE = 12'h304,
324
- CSR_MTVEC = 12'h305,
325
- CSR_MCOUNTEREN= 12'h306,
326
- CSR_MSTATUSH = 12'h310,
327
- CSR_MENVCFG = 12'h30A,
328
- CSR_MENVCFGH = 12'h31A,
329
- // Machine trap handling
330
- CSR_MSCRATCH = 12'h340,
331
- CSR_MEPC = 12'h341,
332
- CSR_MCAUSE = 12'h342,
333
- CSR_MTVAL = 12'h343,
334
- CSR_MIP = 12'h344,
335
- // Physical memory protection
336
- CSR_PMPCFG0 = 12'h3A0,
337
- CSR_PMPCFG1 = 12'h3A1,
338
- CSR_PMPCFG2 = 12'h3A2,
339
- CSR_PMPCFG3 = 12'h3A3,
340
- CSR_PMPADDR0 = 12'h3B0,
341
- CSR_PMPADDR1 = 12'h3B1,
342
- CSR_PMPADDR2 = 12'h3B2,
343
- CSR_PMPADDR3 = 12'h3B3,
344
- CSR_PMPADDR4 = 12'h3B4,
345
- CSR_PMPADDR5 = 12'h3B5,
346
- CSR_PMPADDR6 = 12'h3B6,
347
- CSR_PMPADDR7 = 12'h3B7,
348
- CSR_PMPADDR8 = 12'h3B8,
349
- CSR_PMPADDR9 = 12'h3B9,
350
- CSR_PMPADDR10 = 12'h3BA,
351
- CSR_PMPADDR11 = 12'h3BB,
352
- CSR_PMPADDR12 = 12'h3BC,
353
- CSR_PMPADDR13 = 12'h3BD,
354
- CSR_PMPADDR14 = 12'h3BE,
355
- CSR_PMPADDR15 = 12'h3BF,
356
- // ePMP control
357
- CSR_MSECCFG = 12'h747,
358
- CSR_MSECCFGH = 12'h757,
359
- // Debug trigger
360
- CSR_TSELECT = 12'h7A0,
361
- CSR_TDATA1 = 12'h7A1,
362
- CSR_TDATA2 = 12'h7A2,
363
- CSR_TDATA3 = 12'h7A3,
364
- CSR_MCONTEXT = 12'h7A8,
365
- CSR_SCONTEXT = 12'h7AA,
366
- // Debug/trace
367
- CSR_DCSR = 12'h7b0,
368
- CSR_DPC = 12'h7b1,
369
- // Debug
370
- CSR_DSCRATCH0 = 12'h7b2, // optional
371
- CSR_DSCRATCH1 = 12'h7b3, // optional
372
- // Machine Counter/Timers
373
- CSR_MCOUNTINHIBIT = 12'h320,
374
- CSR_MHPMEVENT3 = 12'h323,
375
- CSR_MHPMEVENT4 = 12'h324,
376
- CSR_MHPMEVENT5 = 12'h325,
377
- CSR_MHPMEVENT6 = 12'h326,
378
- CSR_MHPMEVENT7 = 12'h327,
379
- CSR_MHPMEVENT8 = 12'h328,
380
- CSR_MHPMEVENT9 = 12'h329,
381
- CSR_MHPMEVENT10 = 12'h32A,
382
- CSR_MHPMEVENT11 = 12'h32B,
383
- CSR_MHPMEVENT12 = 12'h32C,
384
- CSR_MHPMEVENT13 = 12'h32D,
385
- CSR_MHPMEVENT14 = 12'h32E,
386
- CSR_MHPMEVENT15 = 12'h32F,
387
- CSR_MHPMEVENT16 = 12'h330,
388
- CSR_MHPMEVENT17 = 12'h331,
389
- CSR_MHPMEVENT18 = 12'h332,
390
- CSR_MHPMEVENT19 = 12'h333,
391
- CSR_MHPMEVENT20 = 12'h334,
392
- CSR_MHPMEVENT21 = 12'h335,
393
- CSR_MHPMEVENT22 = 12'h336,
394
- CSR_MHPMEVENT23 = 12'h337,
395
- CSR_MHPMEVENT24 = 12'h338,
396
- CSR_MHPMEVENT25 = 12'h339,
397
- CSR_MHPMEVENT26 = 12'h33A,
398
- CSR_MHPMEVENT27 = 12'h33B,
399
- CSR_MHPMEVENT28 = 12'h33C,
400
- CSR_MHPMEVENT29 = 12'h33D,
401
- CSR_MHPMEVENT30 = 12'h33E,
402
- CSR_MHPMEVENT31 = 12'h33F,
403
- CSR_MCYCLE = 12'hB00,
404
- CSR_MINSTRET = 12'hB02,
405
- CSR_MHPMCOUNTER3 = 12'hB03,
406
- CSR_MHPMCOUNTER4 = 12'hB04,
407
- CSR_MHPMCOUNTER5 = 12'hB05,
408
- CSR_MHPMCOUNTER6 = 12'hB06,
409
- CSR_MHPMCOUNTER7 = 12'hB07,
410
- CSR_MHPMCOUNTER8 = 12'hB08,
411
- CSR_MHPMCOUNTER9 = 12'hB09,
412
- CSR_MHPMCOUNTER10 = 12'hB0A,
413
- CSR_MHPMCOUNTER11 = 12'hB0B,
414
- CSR_MHPMCOUNTER12 = 12'hB0C,
415
- CSR_MHPMCOUNTER13 = 12'hB0D,
416
- CSR_MHPMCOUNTER14 = 12'hB0E,
417
- CSR_MHPMCOUNTER15 = 12'hB0F,
418
- CSR_MHPMCOUNTER16 = 12'hB10,
419
- CSR_MHPMCOUNTER17 = 12'hB11,
420
- CSR_MHPMCOUNTER18 = 12'hB12,
421
- CSR_MHPMCOUNTER19 = 12'hB13,
422
- CSR_MHPMCOUNTER20 = 12'hB14,
423
- CSR_MHPMCOUNTER21 = 12'hB15,
424
- CSR_MHPMCOUNTER22 = 12'hB16,
425
- CSR_MHPMCOUNTER23 = 12'hB17,
426
- CSR_MHPMCOUNTER24 = 12'hB18,
427
- CSR_MHPMCOUNTER25 = 12'hB19,
428
- CSR_MHPMCOUNTER26 = 12'hB1A,
429
- CSR_MHPMCOUNTER27 = 12'hB1B,
430
- CSR_MHPMCOUNTER28 = 12'hB1C,
431
- CSR_MHPMCOUNTER29 = 12'hB1D,
432
- CSR_MHPMCOUNTER30 = 12'hB1E,
433
- CSR_MHPMCOUNTER31 = 12'hB1F,
434
- CSR_MCYCLEH = 12'hB80,
435
- CSR_MINSTRETH = 12'hB82,
436
- CSR_MHPMCOUNTER3H = 12'hB83,
437
- CSR_MHPMCOUNTER4H = 12'hB84,
438
- CSR_MHPMCOUNTER5H = 12'hB85,
439
- CSR_MHPMCOUNTER6H = 12'hB86,
440
- CSR_MHPMCOUNTER7H = 12'hB87,
441
- CSR_MHPMCOUNTER8H = 12'hB88,
442
- CSR_MHPMCOUNTER9H = 12'hB89,
443
- CSR_MHPMCOUNTER10H = 12'hB8A,
444
- CSR_MHPMCOUNTER11H = 12'hB8B,
445
- CSR_MHPMCOUNTER12H = 12'hB8C,
446
- CSR_MHPMCOUNTER13H = 12'hB8D,
447
- CSR_MHPMCOUNTER14H = 12'hB8E,
448
- CSR_MHPMCOUNTER15H = 12'hB8F,
449
- CSR_MHPMCOUNTER16H = 12'hB90,
450
- CSR_MHPMCOUNTER17H = 12'hB91,
451
- CSR_MHPMCOUNTER18H = 12'hB92,
452
- CSR_MHPMCOUNTER19H = 12'hB93,
453
- CSR_MHPMCOUNTER20H = 12'hB94,
454
- CSR_MHPMCOUNTER21H = 12'hB95,
455
- CSR_MHPMCOUNTER22H = 12'hB96,
456
- CSR_MHPMCOUNTER23H = 12'hB97,
457
- CSR_MHPMCOUNTER24H = 12'hB98,
458
- CSR_MHPMCOUNTER25H = 12'hB99,
459
- CSR_MHPMCOUNTER26H = 12'hB9A,
460
- CSR_MHPMCOUNTER27H = 12'hB9B,
461
- CSR_MHPMCOUNTER28H = 12'hB9C,
462
- CSR_MHPMCOUNTER29H = 12'hB9D,
463
- CSR_MHPMCOUNTER30H = 12'hB9E,
464
- CSR_MHPMCOUNTER31H = 12'hB9F,
465
- CSR_CPUCTRL = 12'h7C0,
466
- CSR_SECURESEED = 12'h7C1
467
- } csr_num_e;
468
- // CSR pmp-related offsets
469
- parameter logic [11:0] CSR_OFF_PMP_CFG = 12'h3A0; // pmp_cfg @ 12'h3a0 - 12'h3a3
470
- parameter logic [11:0] CSR_OFF_PMP_ADDR = 12'h3B0; // pmp_addr @ 12'h3b0 - 12'h3bf
471
- // CSR status bits
472
- parameter int unsigned CSR_MSTATUS_MIE_BIT = 3;
473
- parameter int unsigned CSR_MSTATUS_MPIE_BIT = 7;
474
- parameter int unsigned CSR_MSTATUS_MPP_BIT_LOW = 11;
475
- parameter int unsigned CSR_MSTATUS_MPP_BIT_HIGH = 12;
476
- parameter int unsigned CSR_MSTATUS_MPRV_BIT = 17;
477
- parameter int unsigned CSR_MSTATUS_TW_BIT = 21;
478
- // CSR machine ISA
479
- parameter logic [1:0] CSR_MISA_MXL = 2'd1; // M-XLEN: XLEN in M-Mode for RV32
480
- // CSR interrupt pending/enable bits
481
- parameter int unsigned CSR_MSIX_BIT = 3;
482
- parameter int unsigned CSR_MTIX_BIT = 7;
483
- parameter int unsigned CSR_MEIX_BIT = 11;
484
- parameter int unsigned CSR_MFIX_BIT_LOW = 16;
485
- parameter int unsigned CSR_MFIX_BIT_HIGH = 31;
486
- // CSR Machine Security Configuration bits
487
- parameter int unsigned CSR_MSECCFG_MML_BIT = 0;
488
- parameter int unsigned CSR_MSECCFG_MMWP_BIT = 1;
489
- parameter int unsigned CSR_MSECCFG_RLB_BIT = 2;
490
- // Machine Vendor ID - OpenHW JEDEC ID is '2 decimal (bank 13)'
491
- parameter MVENDORID_OFFSET = 7'h2; // Final byte without parity bit
492
- parameter MVENDORID_BANK = 25'hC; // Number of continuation codes
493
- // Machine Architecture ID (https://github.com/riscv/riscv-isa-manual/blob/master/marchid.md)
494
- parameter MARCHID = 32'd35;
495
- localparam logic [31:0] CSR_MVENDORID_VALUE = {MVENDORID_BANK, MVENDORID_OFFSET};
496
- localparam logic [31:0] CSR_MARCHID_VALUE = MARCHID;
497
- // Implementation ID
498
- // 0 indicates this field is not implemeted. cve2 implementors may wish to indicate an RTL/netlist
499
- // version here using their own unique encoding (e.g. 32 bits of the git hash of the implemented
500
- // commit).
501
- localparam logic [31:0] CSR_MIMPID_VALUE = 32'b0;
502
- // Machine Configuration Pointer
503
- // 0 indicates the configuration data structure does not eixst. cve2 implementors may wish to
504
- // alter this to point to their system specific configuration data structure.
505
- localparam logic [31:0] CSR_MCONFIGPTR_VALUE = 32'b0;
506
- // RVFI CSR element
507
- typedef struct packed {
508
- bit [63:0] rdata;
509
- bit [63:0] rmask;
510
- bit [63:0] wdata;
511
- bit [63:0] wmask;
512
- } rvfi_csr_elmt_t;
513
- // RVFI CSR structure
514
- typedef struct packed {
515
- rvfi_csr_elmt_t fflags;
516
- rvfi_csr_elmt_t frm;
517
- rvfi_csr_elmt_t fcsr;
518
- rvfi_csr_elmt_t ftran;
519
- rvfi_csr_elmt_t dcsr;
520
- rvfi_csr_elmt_t dpc;
521
- rvfi_csr_elmt_t dscratch0;
522
- rvfi_csr_elmt_t dscratch1;
523
- rvfi_csr_elmt_t sstatus;
524
- rvfi_csr_elmt_t sie;
525
- rvfi_csr_elmt_t sip;
526
- rvfi_csr_elmt_t stvec;
527
- rvfi_csr_elmt_t scounteren;
528
- rvfi_csr_elmt_t sscratch;
529
- rvfi_csr_elmt_t sepc;
530
- rvfi_csr_elmt_t scause;
531
- rvfi_csr_elmt_t stval;
532
- rvfi_csr_elmt_t satp;
533
- rvfi_csr_elmt_t mstatus;
534
- rvfi_csr_elmt_t mstatush;
535
- rvfi_csr_elmt_t misa;
536
- rvfi_csr_elmt_t medeleg;
537
- rvfi_csr_elmt_t mideleg;
538
- rvfi_csr_elmt_t mie;
539
- rvfi_csr_elmt_t mtvec;
540
- rvfi_csr_elmt_t mcounteren;
541
- rvfi_csr_elmt_t mscratch;
542
- rvfi_csr_elmt_t mepc;
543
- rvfi_csr_elmt_t mcause;
544
- rvfi_csr_elmt_t mtval;
545
- rvfi_csr_elmt_t mip;
546
- rvfi_csr_elmt_t menvcfg;
547
- rvfi_csr_elmt_t menvcfgh;
548
- rvfi_csr_elmt_t mvendorid;
549
- rvfi_csr_elmt_t marchid;
550
- rvfi_csr_elmt_t mhartid;
551
- rvfi_csr_elmt_t mcountinhibit;
552
- rvfi_csr_elmt_t mcycle;
553
- rvfi_csr_elmt_t mcycleh;
554
- rvfi_csr_elmt_t minstret;
555
- rvfi_csr_elmt_t minstreth;
556
- rvfi_csr_elmt_t cycle;
557
- rvfi_csr_elmt_t cycleh;
558
- rvfi_csr_elmt_t instret;
559
- rvfi_csr_elmt_t instreth;
560
- rvfi_csr_elmt_t dcache;
561
- rvfi_csr_elmt_t icache;
562
- rvfi_csr_elmt_t acc_cons;
563
- rvfi_csr_elmt_t pmpcfg0;
564
- rvfi_csr_elmt_t pmpcfg1;
565
- rvfi_csr_elmt_t pmpcfg2;
566
- rvfi_csr_elmt_t pmpcfg3;
567
- rvfi_csr_elmt_t pmpaddr0;
568
- rvfi_csr_elmt_t pmpaddr1;
569
- rvfi_csr_elmt_t pmpaddr2;
570
- rvfi_csr_elmt_t pmpaddr3;
571
- rvfi_csr_elmt_t pmpaddr4;
572
- rvfi_csr_elmt_t pmpaddr5;
573
- rvfi_csr_elmt_t pmpaddr6;
574
- rvfi_csr_elmt_t pmpaddr7;
575
- rvfi_csr_elmt_t pmpaddr8;
576
- rvfi_csr_elmt_t pmpaddr9;
577
- rvfi_csr_elmt_t pmpaddr10;
578
- rvfi_csr_elmt_t pmpaddr11;
579
- rvfi_csr_elmt_t pmpaddr12;
580
- rvfi_csr_elmt_t pmpaddr13;
581
- rvfi_csr_elmt_t pmpaddr14;
582
- rvfi_csr_elmt_t pmpaddr15;
583
- } rvfi_csr_t;
584
- // CV-X-IF
585
- parameter int unsigned X_NUM_RS = 3;
586
- parameter int unsigned X_ID_WIDTH = 4;
587
- parameter int unsigned X_RFR_WIDTH = 32;
588
- parameter int unsigned X_RFW_WIDTH = 32;
589
- parameter int unsigned X_HARTID_WIDTH = 32;
590
- parameter int unsigned X_DUAL_READ = 0;
591
- parameter int unsigned X_DUAL_WRITE = 0;
592
- parameter int unsigned X_INSTR_INFLIGHT = 2**X_ID_WIDTH;
593
- typedef logic [X_NUM_RS+X_DUAL_READ-1:0] readregflags_t;
594
- typedef logic [X_DUAL_WRITE:0] writeregflags_t;
595
- typedef logic [X_ID_WIDTH-1:0] id_t;
596
- typedef logic [X_HARTID_WIDTH-1:0] hartid_t;
597
- // Issue Interface
598
- typedef struct packed {
599
- logic [31:0] instr;
600
- hartid_t hartid;
601
- id_t id;
602
- } x_issue_req_t;
603
- typedef struct packed {
604
- logic accept;
605
- writeregflags_t writeback;
606
- readregflags_t register_read;
607
- } x_issue_resp_t;
608
- // Register Interface
609
- typedef struct packed {
610
- hartid_t hartid;
611
- id_t id;
612
- logic [X_NUM_RS-1:0][X_RFR_WIDTH-1:0] rs;
613
- readregflags_t rs_valid;
614
- } x_register_t;
615
- // Commit Interface
616
- typedef struct packed {
617
- hartid_t hartid;
618
- id_t id;
619
- logic commit_kill;
620
- } x_commit_t;
621
- // Result Interface
622
- typedef struct packed {
623
- hartid_t hartid;
624
- id_t id;
625
- logic [X_RFW_WIDTH-1:0] data;
626
- logic [4:0] rd;
627
- writeregflags_t we;
628
- } x_result_t;
629
- endpackage
630
- // Copyright (c) 2025 Eclipse Foundation
631
- // Copyright lowRISC contributors.
632
- // Copyright 2018 ETH Zurich and University of Bologna, see also CREDITS.md.
633
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
634
- // SPDX-License-Identifier: Apache-2.0
635
- /**
636
- * Instruction decoder
637
- *
638
- * This module is fully combinatorial, clock and reset are used for
639
- * assertions only.
640
- */
641
- // Copyright lowRISC contributors.
642
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
643
- // SPDX-License-Identifier: Apache-2.0
644
- // Macros and helper code for using assertions.
645
- // - Provides default clk and rst options to simplify code
646
- // - Provides boiler plate template for common assertions
647
- ///////////////////
648
- // Helper macros //
649
- ///////////////////
650
- // Default clk and reset signals used by assertion macros below.
651
- // Converts an arbitrary block of code into a Verilog string
652
- // ASSERT_ERROR logs an error message with either `uvm_error or with $error.
653
- //
654
- // This somewhat duplicates `DV_ERROR macro defined in hw/dv/sv/dv_utils/dv_macros.svh. The reason
655
- // for redefining it here is to avoid creating a dependency.
656
- // This macro is suitable for conditionally triggering lint errors, e.g., if a Sec parameter takes
657
- // on a non-default value. This may be required for pre-silicon/FPGA evaluation but we don't want
658
- // to allow this for tapeout.
659
- // The basic helper macros are actually defined in "implementation headers". The macros should do
660
- // the same thing in each case (except for the dummy flavour), but in a way that the respective
661
- // tools support.
662
- //
663
- // If the tool supports assertions in some form, we also define INC_ASSERT (which can be used to
664
- // hide signal definitions that are only used for assertions).
665
- //
666
- // The list of basic macros supported is:
667
- //
668
- // ASSERT_I: Immediate assertion. Note that immediate assertions are sensitive to simulation
669
- // glitches.
670
- //
671
- // ASSERT_INIT: Assertion in initial block. Can be used for things like parameter checking.
672
- //
673
- // ASSERT_INIT_NET: Assertion in initial block. Can be used for initial value of a net.
674
- //
675
- // ASSERT_FINAL: Assertion in final block. Can be used for things like queues being empty at end of
676
- // sim, all credits returned at end of sim, state machines in idle at end of sim.
677
- //
678
- // ASSERT: Assert a concurrent property directly. It can be called as a module (or
679
- // interface) body item.
680
- //
681
- // Note: We use (__rst !== '0) in the disable iff statements instead of (__rst ==
682
- // '1). This properly disables the assertion in cases when reset is X at the
683
- // beginning of a simulation. For that case, (reset == '1) does not disable the
684
- // assertion.
685
- //
686
- // ASSERT_NEVER: Assert a concurrent property NEVER happens
687
- //
688
- // ASSERT_KNOWN: Assert that signal has a known value (each bit is either '0' or '1') after reset.
689
- // It can be called as a module (or interface) body item.
690
- //
691
- // COVER: Cover a concurrent property
692
- //
693
- // ASSUME: Assume a concurrent property
694
- //
695
- // ASSUME_I: Assume an immediate property
696
- // Copyright lowRISC contributors.
697
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
698
- // SPDX-License-Identifier: Apache-2.0
699
- // Macro bodies included by prim_assert.sv for tools that don't support assertions. See
700
- // prim_assert.sv for documentation for each of the macros.
701
- //////////////////////////////
702
- // Complex assertion macros //
703
- //////////////////////////////
704
- // Assert that signal is an active-high pulse with pulse length of 1 clock cycle
705
- // Assert that a property is true only when an enable signal is set. It can be called as a module
706
- // (or interface) body item.
707
- // Assert that signal has a known value (each bit is either '0' or '1') after reset if enable is
708
- // set. It can be called as a module (or interface) body item.
709
- //////////////////////////////////
710
- // For formal verification only //
711
- //////////////////////////////////
712
- // Note that the existing set of ASSERT macros specified above shall be used for FPV,
713
- // thereby ensuring that the assertions are evaluated during DV simulations as well.
714
- // ASSUME_FPV
715
- // Assume a concurrent property during formal verification only.
716
- // ASSUME_I_FPV
717
- // Assume a concurrent property during formal verification only.
718
- // COVER_FPV
719
- // Cover a concurrent property during formal verification
720
- // Copyright lowRISC contributors.
721
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
722
- // SPDX-License-Identifier: Apache-2.0
723
- // // Macros and helper code for security countermeasures.
724
- // Helper macros
725
- // macros for security countermeasures
726
- // PRIM_ASSERT_SEC_CM_SVH
727
- // PRIM_ASSERT_SV
728
- module cve2_decoder #(
729
- parameter bit RV32E = 0,
730
- parameter cve2_pkg::rv32m_e RV32M = cve2_pkg::RV32MFast,
731
- parameter cve2_pkg::rv32b_e RV32B = cve2_pkg::RV32BNone,
732
- parameter bit XInterface = 1'b0
733
- ) (
734
- input logic clk_i,
735
- input logic rst_ni,
736
- // to/from controller
737
- output logic illegal_insn_o, // illegal instr encountered
738
- output logic ebrk_insn_o, // trap instr encountered
739
- output logic mret_insn_o, // return from exception instr
740
- // encountered
741
- output logic dret_insn_o, // return from debug instr encountered
742
- output logic ecall_insn_o, // syscall instr encountered
743
- output logic wfi_insn_o, // wait for interrupt instr encountered
744
- output logic jump_set_o, // jump taken set signal
745
- // from IF-ID pipeline register
746
- input logic instr_first_cycle_i, // instruction read is in its first cycle
747
- input logic [31:0] instr_rdata_i, // instruction read from memory/cache
748
- input logic [31:0] instr_rdata_alu_i, // instruction read from memory/cache
749
- // replicated to ease fan-out)
750
- input logic illegal_c_insn_i, // compressed instruction decode failed
751
- // immediates
752
- output cve2_pkg::imm_a_sel_e imm_a_mux_sel_o, // immediate selection for operand a
753
- output cve2_pkg::imm_b_sel_e imm_b_mux_sel_o, // immediate selection for operand b
754
- output logic [31:0] imm_i_type_o,
755
- output logic [31:0] imm_s_type_o,
756
- output logic [31:0] imm_b_type_o,
757
- output logic [31:0] imm_u_type_o,
758
- output logic [31:0] imm_j_type_o,
759
- output logic [31:0] zimm_rs1_type_o,
760
- // register file
761
- output logic [XInterface:0] rf_wdata_sel_o, // RF write data selection
762
- output logic rf_we_o, // write enable for regfile
763
- output logic [4:0] rf_raddr_a_o,
764
- output logic [4:0] rf_raddr_b_o,
765
- output logic [4:0] rf_raddr_c_o,
766
- output logic [4:0] rf_waddr_o,
767
- output logic rf_ren_a_o, // Instruction reads from RF addr A
768
- output logic rf_ren_b_o, // Instruction reads from RF addr B
769
- output logic rf_ren_c_o, // Instruction reads from RF addr C (if X-IF if used)
770
- // ALU
771
- output cve2_pkg::alu_op_e alu_operator_o, // ALU operation selection
772
- output cve2_pkg::op_a_sel_e alu_op_a_mux_sel_o, // operand a selection: reg value, PC,
773
- // immediate or zero
774
- output cve2_pkg::op_b_sel_e alu_op_b_mux_sel_o, // operand b selection: reg value or
775
- // immediate
776
- output logic alu_multicycle_o, // ternary bitmanip instruction
777
- // MULT & DIV
778
- output logic mult_en_o, // perform integer multiplication
779
- output logic div_en_o, // perform integer division or remainder
780
- output logic mult_sel_o, // as above but static, for data muxes
781
- output logic div_sel_o, // as above but static, for data muxes
782
- output cve2_pkg::md_op_e multdiv_operator_o,
783
- output logic [1:0] multdiv_signed_mode_o,
784
- // CSRs
785
- output logic csr_access_o, // access to CSR
786
- output cve2_pkg::csr_op_e csr_op_o, // operation to perform on CSR
787
- // LSU
788
- output logic data_req_o, // start transaction to data memory
789
- output logic data_we_o, // write enable
790
- output logic [1:0] data_type_o, // size of transaction: byte, half
791
- // word or word
792
- output logic data_sign_extension_o, // sign extension for data read from
793
- // memory
794
- // Core-V eXtension interface (CV-X-IF)
795
- input cve2_pkg::readregflags_t x_issue_resp_register_read_i,
796
- // jump/branches
797
- output logic jump_in_dec_o, // jump is being calculated in ALU
798
- output logic branch_in_dec_o
799
- );
800
- import cve2_pkg::*;
801
- logic illegal_insn;
802
- logic illegal_reg_rv32e;
803
- logic csr_illegal;
804
- logic rf_we;
805
- logic [31:0] instr;
806
- logic [31:0] instr_alu;
807
- logic [9:0] unused_instr_alu;
808
- // Source/Destination register instruction index
809
- logic [4:0] instr_rs1;
810
- logic [4:0] instr_rs2;
811
- logic [4:0] instr_rs3;
812
- logic [4:0] instr_rd;
813
- logic use_rs3_d;
814
- logic use_rs3_q;
815
- csr_op_e csr_op;
816
- opcode_e opcode;
817
- opcode_e opcode_alu;
818
- // To help timing the flops containing the current instruction are replicated to reduce fan-out.
819
- // instr_alu is used to determine the ALU control logic and associated operand/imm select signals
820
- // as the ALU is often on the more critical timing paths. instr is used for everything else.
821
- assign instr = instr_rdata_i;
822
- assign instr_alu = instr_rdata_alu_i;
823
- //////////////////////////////////////
824
- // Register and immediate selection //
825
- //////////////////////////////////////
826
- // immediate extraction and sign extension
827
- assign imm_i_type_o = { {20{instr[31]}}, instr[31:20] };
828
- assign imm_s_type_o = { {20{instr[31]}}, instr[31:25], instr[11:7] };
829
- assign imm_b_type_o = { {19{instr[31]}}, instr[31], instr[7], instr[30:25], instr[11:8], 1'b0 };
830
- assign imm_u_type_o = { instr[31:12], 12'b0 };
831
- assign imm_j_type_o = { {12{instr[31]}}, instr[19:12], instr[20], instr[30:21], 1'b0 };
832
- // immediate for CSR manipulation (zero extended)
833
- assign zimm_rs1_type_o = { 27'b0, instr_rs1 }; // rs1
834
- if (RV32B != RV32BNone) begin : gen_rs3_flop
835
- // the use of rs3 is known one cycle ahead.
836
- always_ff @(posedge clk_i or negedge rst_ni) begin
837
- if (!rst_ni) begin
838
- use_rs3_q <= 1'b0;
839
- end else begin
840
- use_rs3_q <= use_rs3_d;
841
- end
842
- end
843
- end else begin : gen_no_rs3_flop
844
- logic unused_clk;
845
- logic unused_rst_n;
846
- // Clock and reset unused when there's no rs3 flop
847
- assign unused_clk = clk_i;
848
- assign unused_rst_n = rst_ni;
849
- // always zero
850
- assign use_rs3_q = use_rs3_d;
851
- end
852
- // source registers
853
- assign instr_rs1 = instr[19:15];
854
- assign instr_rs2 = instr[24:20];
855
- assign instr_rs3 = instr[31:27];
856
- assign rf_raddr_a_o = (use_rs3_q & ~instr_first_cycle_i) ? instr_rs3 : instr_rs1; // rs3 / rs1
857
- assign rf_raddr_b_o = instr_rs2; // rs2
858
- assign rf_raddr_c_o = XInterface ? instr_rs3 : '0;
859
- // destination register
860
- assign instr_rd = instr[11:7];
861
- assign rf_waddr_o = instr_rd; // rd
862
- ////////////////////
863
- // Register check //
864
- ////////////////////
865
- if (RV32E) begin : gen_rv32e_reg_check_active
866
- assign illegal_reg_rv32e = ((rf_raddr_a_o[4] & (alu_op_a_mux_sel_o == OP_A_REG_A)) |
867
- (rf_raddr_b_o[4] & (alu_op_b_mux_sel_o == OP_B_REG_B)) |
868
- (rf_waddr_o[4] & rf_we));
869
- end else begin : gen_rv32e_reg_check_inactive
870
- assign illegal_reg_rv32e = 1'b0;
871
- end
872
- ///////////////////////
873
- // CSR operand check //
874
- ///////////////////////
875
- always_comb begin : csr_operand_check
876
- csr_op_o = csr_op;
877
- // CSRRSI/CSRRCI must not write 0 to CSRs (uimm[4:0]=='0)
878
- // CSRRS/CSRRC must not write from x0 to CSRs (rs1=='0)
879
- if ((csr_op == CSR_OP_SET || csr_op == CSR_OP_CLEAR) &&
880
- instr_rs1 == '0) begin
881
- csr_op_o = CSR_OP_READ;
882
- end
883
- end
884
- /////////////
885
- // Decoder //
886
- /////////////
887
- always_comb begin
888
- jump_in_dec_o = 1'b0;
889
- jump_set_o = 1'b0;
890
- branch_in_dec_o = 1'b0;
891
- multdiv_operator_o = MD_OP_MULL;
892
- multdiv_signed_mode_o = 2'b00;
893
- rf_wdata_sel_o = $bits(rf_wdata_sel_o)'({RF_WD_EX});
894
- rf_we = 1'b0;
895
- rf_ren_a_o = 1'b0;
896
- rf_ren_b_o = 1'b0;
897
- rf_ren_c_o = 1'b0;
898
- csr_access_o = 1'b0;
899
- csr_illegal = 1'b0;
900
- csr_op = CSR_OP_READ;
901
- data_we_o = 1'b0;
902
- data_type_o = 2'b00;
903
- data_sign_extension_o = 1'b0;
904
- data_req_o = 1'b0;
905
- illegal_insn = 1'b0;
906
- ebrk_insn_o = 1'b0;
907
- mret_insn_o = 1'b0;
908
- dret_insn_o = 1'b0;
909
- ecall_insn_o = 1'b0;
910
- wfi_insn_o = 1'b0;
911
- opcode = opcode_e'(instr[6:0]);
912
- unique case (opcode)
913
- ///////////
914
- // Jumps //
915
- ///////////
916
- OPCODE_JAL: begin // Jump and Link
917
- jump_in_dec_o = 1'b1;
918
- if (instr_first_cycle_i) begin
919
- // Calculate jump target (and store PC)
920
- rf_we = 1'b0;
921
- jump_set_o = 1'b1;
922
- end else begin
923
- // Calculate and store PC+4
924
- rf_we = 1'b1;
925
- end
926
- end
927
- OPCODE_JALR: begin // Jump and Link Register
928
- jump_in_dec_o = 1'b1;
929
- if (instr_first_cycle_i) begin
930
- // Calculate jump target (and store PC)
931
- rf_we = 1'b0;
932
- jump_set_o = 1'b1;
933
- end else begin
934
- // Calculate and store PC+4
935
- rf_we = 1'b1;
936
- end
937
- if (instr[14:12] != 3'b0) begin
938
- illegal_insn = 1'b1;
939
- end
940
- rf_ren_a_o = 1'b1;
941
- end
942
- OPCODE_BRANCH: begin // Branch
943
- branch_in_dec_o = 1'b1;
944
- // Check branch condition selection
945
- unique case (instr[14:12])
946
- 3'b000,
947
- 3'b001,
948
- 3'b100,
949
- 3'b101,
950
- 3'b110,
951
- 3'b111: illegal_insn = 1'b0;
952
- default: illegal_insn = 1'b1;
953
- endcase
954
- rf_ren_a_o = 1'b1;
955
- rf_ren_b_o = 1'b1;
956
- end
957
- ////////////////
958
- // Load/store //
959
- ////////////////
960
- OPCODE_STORE: begin
961
- rf_ren_a_o = 1'b1;
962
- rf_ren_b_o = 1'b1;
963
- data_req_o = 1'b1;
964
- data_we_o = 1'b1;
965
- if (instr[14]) begin
966
- illegal_insn = 1'b1;
967
- end
968
- // store size
969
- unique case (instr[13:12])
970
- 2'b00: data_type_o = 2'b10; // sb
971
- 2'b01: data_type_o = 2'b01; // sh
972
- 2'b10: data_type_o = 2'b00; // sw
973
- default: illegal_insn = 1'b1;
974
- endcase
975
- end
976
- OPCODE_LOAD: begin
977
- rf_ren_a_o = 1'b1;
978
- data_req_o = 1'b1;
979
- data_type_o = 2'b00;
980
- // sign/zero extension
981
- data_sign_extension_o = ~instr[14];
982
- // load size
983
- unique case (instr[13:12])
984
- 2'b00: data_type_o = 2'b10; // lb(u)
985
- 2'b01: data_type_o = 2'b01; // lh(u)
986
- 2'b10: begin
987
- data_type_o = 2'b00; // lw
988
- if (instr[14]) begin
989
- illegal_insn = 1'b1; // lwu does not exist
990
- end
991
- end
992
- default: begin
993
- illegal_insn = 1'b1;
994
- end
995
- endcase
996
- end
997
- /////////
998
- // ALU //
999
- /////////
1000
- OPCODE_LUI: begin // Load Upper Immediate
1001
- rf_we = 1'b1;
1002
- end
1003
- OPCODE_AUIPC: begin // Add Upper Immediate to PC
1004
- rf_we = 1'b1;
1005
- end
1006
- OPCODE_OP_IMM: begin // Register-Immediate ALU Operations
1007
- rf_ren_a_o = 1'b1;
1008
- rf_we = 1'b1;
1009
- unique case (instr[14:12])
1010
- 3'b000,
1011
- 3'b010,
1012
- 3'b011,
1013
- 3'b100,
1014
- 3'b110,
1015
- 3'b111: illegal_insn = 1'b0;
1016
- 3'b001: begin
1017
- unique case (instr[31:27])
1018
- 5'b0_0000: illegal_insn = (instr[26:25] == 2'b00) ? 1'b0 : 1'b1; // slli
1019
- 5'b0_0100: begin // sloi
1020
- illegal_insn = (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) ? 1'b0 : 1'b1;
1021
- end
1022
- 5'b0_1001, // bclri
1023
- 5'b0_0101, // bseti
1024
- 5'b0_1101: illegal_insn = (RV32B != RV32BNone) ? 1'b0 : 1'b1; // binvi
1025
- 5'b0_0001: begin
1026
- if (instr[26] == 1'b0) begin // shfl
1027
- illegal_insn = (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) ? 1'b0 : 1'b1;
1028
- end else begin
1029
- illegal_insn = 1'b1;
1030
- end
1031
- end
1032
- 5'b0_1100: begin
1033
- unique case(instr[26:20])
1034
- 7'b000_0000, // clz
1035
- 7'b000_0001, // ctz
1036
- 7'b000_0010, // cpop
1037
- 7'b000_0100, // sext.b
1038
- 7'b000_0101: illegal_insn = (RV32B != RV32BNone) ? 1'b0 : 1'b1; // sext.h
1039
- 7'b001_0000, // crc32.b
1040
- 7'b001_0001, // crc32.h
1041
- 7'b001_0010, // crc32.w
1042
- 7'b001_1000, // crc32c.b
1043
- 7'b001_1001, // crc32c.h
1044
- 7'b001_1010: begin // crc32c.w
1045
- illegal_insn = (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) ? 1'b0 : 1'b1;
1046
- end
1047
- default: illegal_insn = 1'b1;
1048
- endcase
1049
- end
1050
- default : illegal_insn = 1'b1;
1051
- endcase
1052
- end
1053
- 3'b101: begin
1054
- if (instr[26]) begin
1055
- illegal_insn = (RV32B != RV32BNone) ? 1'b0 : 1'b1; // fsri
1056
- end else begin
1057
- unique case (instr[31:27])
1058
- 5'b0_0000, // srli
1059
- 5'b0_1000: illegal_insn = (instr[26:25] == 2'b00) ? 1'b0 : 1'b1; // srai
1060
- 5'b0_0100: begin // sroi
1061
- illegal_insn = (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) ? 1'b0 : 1'b1;
1062
- end
1063
- 5'b0_1100, // rori
1064
- 5'b0_1001: illegal_insn = (RV32B != RV32BNone) ? 1'b0 : 1'b1; // bexti
1065
- 5'b0_1101: begin
1066
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) begin
1067
- illegal_insn = 1'b0; // grevi
1068
- end else if (RV32B == RV32BBalanced) begin
1069
- illegal_insn = (instr[24:20] == 5'b11000) ? 1'b0 : 1'b1; // rev8
1070
- end else begin
1071
- illegal_insn = 1'b1;
1072
- end
1073
- end
1074
- 5'b0_0101: begin
1075
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) begin
1076
- illegal_insn = 1'b0; // gorci
1077
- end else if (instr[24:20] == 5'b00111) begin
1078
- illegal_insn = (RV32B == RV32BBalanced) ? 1'b0 : 1'b1; // orc.b
1079
- end else begin
1080
- illegal_insn = 1'b1;
1081
- end
1082
- end
1083
- 5'b0_0001: begin
1084
- if (instr[26] == 1'b0) begin // unshfl
1085
- illegal_insn = (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) ? 1'b0 : 1'b1;
1086
- end else begin
1087
- illegal_insn = 1'b1;
1088
- end
1089
- end
1090
- default: illegal_insn = 1'b1;
1091
- endcase
1092
- end
1093
- end
1094
- default: illegal_insn = 1'b1;
1095
- endcase
1096
- end
1097
- OPCODE_OP: begin // Register-Register ALU operation
1098
- rf_ren_a_o = 1'b1;
1099
- rf_ren_b_o = 1'b1;
1100
- rf_we = 1'b1;
1101
- if ({instr[26], instr[13:12]} == {1'b1, 2'b01}) begin
1102
- illegal_insn = (RV32B != RV32BNone) ? 1'b0 : 1'b1; // cmix / cmov / fsl / fsr
1103
- end else begin
1104
- unique case ({instr[31:25], instr[14:12]})
1105
- // RV32I ALU operations
1106
- {7'b000_0000, 3'b000},
1107
- {7'b010_0000, 3'b000},
1108
- {7'b000_0000, 3'b010},
1109
- {7'b000_0000, 3'b011},
1110
- {7'b000_0000, 3'b100},
1111
- {7'b000_0000, 3'b110},
1112
- {7'b000_0000, 3'b111},
1113
- {7'b000_0000, 3'b001},
1114
- {7'b000_0000, 3'b101},
1115
- {7'b010_0000, 3'b101}: illegal_insn = 1'b0;
1116
- // RV32B zba
1117
- {7'b001_0000, 3'b010}, // sh1add
1118
- {7'b001_0000, 3'b100}, // sh2add
1119
- {7'b001_0000, 3'b110}, // sh3add
1120
- // RV32B zbb
1121
- {7'b010_0000, 3'b111}, // andn
1122
- {7'b010_0000, 3'b110}, // orn
1123
- {7'b010_0000, 3'b100}, // xnor
1124
- {7'b011_0000, 3'b001}, // rol
1125
- {7'b011_0000, 3'b101}, // ror
1126
- {7'b000_0101, 3'b100}, // min
1127
- {7'b000_0101, 3'b110}, // max
1128
- {7'b000_0101, 3'b101}, // minu
1129
- {7'b000_0101, 3'b111}, // maxu
1130
- {7'b000_0100, 3'b100}, // pack
1131
- {7'b010_0100, 3'b100}, // packu
1132
- {7'b000_0100, 3'b111}, // packh
1133
- // RV32B zbs
1134
- {7'b010_0100, 3'b001}, // bclr
1135
- {7'b001_0100, 3'b001}, // bset
1136
- {7'b011_0100, 3'b001}, // binv
1137
- {7'b010_0100, 3'b101}, // bext
1138
- // RV32B zbf
1139
- {7'b010_0100, 3'b111}: illegal_insn = (RV32B != RV32BNone) ? 1'b0 : 1'b1; // bfp
1140
- // RV32B zbp
1141
- {7'b011_0100, 3'b101}, // grev
1142
- {7'b001_0100, 3'b101}, // gorc
1143
- {7'b000_0100, 3'b001}, // shfl
1144
- {7'b000_0100, 3'b101}, // unshfl
1145
- {7'b001_0100, 3'b010}, // xperm.n
1146
- {7'b001_0100, 3'b100}, // xperm.b
1147
- {7'b001_0100, 3'b110}, // xperm.h
1148
- {7'b001_0000, 3'b001}, // slo
1149
- {7'b001_0000, 3'b101}, // sro
1150
- // RV32B zbc
1151
- {7'b000_0101, 3'b001}, // clmul
1152
- {7'b000_0101, 3'b010}, // clmulr
1153
- {7'b000_0101, 3'b011}: begin // clmulh
1154
- illegal_insn = (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) ? 1'b0 : 1'b1;
1155
- end
1156
- // RV32B zbe
1157
- {7'b010_0100, 3'b110}, // bdecompress
1158
- {7'b000_0100, 3'b110}: illegal_insn = (RV32B == RV32BFull) ? 1'b0 : 1'b1; // bcompress
1159
- // RV32M instructions
1160
- {7'b000_0001, 3'b000}: begin // mul
1161
- multdiv_operator_o = MD_OP_MULL;
1162
- multdiv_signed_mode_o = 2'b00;
1163
- illegal_insn = (RV32M == RV32MNone) ? 1'b1 : 1'b0;
1164
- end
1165
- {7'b000_0001, 3'b001}: begin // mulh
1166
- multdiv_operator_o = MD_OP_MULH;
1167
- multdiv_signed_mode_o = 2'b11;
1168
- illegal_insn = (RV32M == RV32MNone) ? 1'b1 : 1'b0;
1169
- end
1170
- {7'b000_0001, 3'b010}: begin // mulhsu
1171
- multdiv_operator_o = MD_OP_MULH;
1172
- multdiv_signed_mode_o = 2'b01;
1173
- illegal_insn = (RV32M == RV32MNone) ? 1'b1 : 1'b0;
1174
- end
1175
- {7'b000_0001, 3'b011}: begin // mulhu
1176
- multdiv_operator_o = MD_OP_MULH;
1177
- multdiv_signed_mode_o = 2'b00;
1178
- illegal_insn = (RV32M == RV32MNone) ? 1'b1 : 1'b0;
1179
- end
1180
- {7'b000_0001, 3'b100}: begin // div
1181
- multdiv_operator_o = MD_OP_DIV;
1182
- multdiv_signed_mode_o = 2'b11;
1183
- illegal_insn = (RV32M == RV32MNone) ? 1'b1 : 1'b0;
1184
- end
1185
- {7'b000_0001, 3'b101}: begin // divu
1186
- multdiv_operator_o = MD_OP_DIV;
1187
- multdiv_signed_mode_o = 2'b00;
1188
- illegal_insn = (RV32M == RV32MNone) ? 1'b1 : 1'b0;
1189
- end
1190
- {7'b000_0001, 3'b110}: begin // rem
1191
- multdiv_operator_o = MD_OP_REM;
1192
- multdiv_signed_mode_o = 2'b11;
1193
- illegal_insn = (RV32M == RV32MNone) ? 1'b1 : 1'b0;
1194
- end
1195
- {7'b000_0001, 3'b111}: begin // remu
1196
- multdiv_operator_o = MD_OP_REM;
1197
- multdiv_signed_mode_o = 2'b00;
1198
- illegal_insn = (RV32M == RV32MNone) ? 1'b1 : 1'b0;
1199
- end
1200
- default: begin
1201
- illegal_insn = 1'b1;
1202
- end
1203
- endcase
1204
- end
1205
- end
1206
- /////////////
1207
- // Special //
1208
- /////////////
1209
- OPCODE_MISC_MEM: begin
1210
- unique case (instr[14:12])
1211
- 3'b000: begin
1212
- // FENCE is treated as a NOP since all memory operations are already strictly ordered.
1213
- rf_we = 1'b0;
1214
- end
1215
- 3'b001: begin
1216
- // FENCE.I is implemented as a jump to the next PC, this gives the required flushing
1217
- // behaviour (iside prefetch buffer flushed and response to any outstanding iside
1218
- // requests will be ignored).
1219
- jump_in_dec_o = 1'b1;
1220
- rf_we = 1'b0;
1221
- if (instr_first_cycle_i) begin
1222
- jump_set_o = 1'b1;
1223
- end
1224
- end
1225
- default: begin
1226
- illegal_insn = 1'b1;
1227
- end
1228
- endcase
1229
- end
1230
- OPCODE_SYSTEM: begin
1231
- if (instr[14:12] == 3'b000) begin
1232
- // non CSR related SYSTEM instructions
1233
- unique case (instr[31:20])
1234
- 12'h000: // ECALL
1235
- // environment (system) call
1236
- ecall_insn_o = 1'b1;
1237
- 12'h001: // ebreak
1238
- // debugger trap
1239
- ebrk_insn_o = 1'b1;
1240
- 12'h302: // mret
1241
- mret_insn_o = 1'b1;
1242
- 12'h7b2: // dret
1243
- dret_insn_o = 1'b1;
1244
- 12'h105: // wfi
1245
- wfi_insn_o = 1'b1;
1246
- default:
1247
- illegal_insn = 1'b1;
1248
- endcase
1249
- // rs1 and rd must be 0
1250
- if (instr_rs1 != 5'b0 || instr_rd != 5'b0) begin
1251
- illegal_insn = 1'b1;
1252
- end
1253
- end else begin
1254
- // instruction to read/modify CSR
1255
- csr_access_o = 1'b1;
1256
- rf_wdata_sel_o = $bits(rf_wdata_sel_o)'({RF_WD_CSR});
1257
- rf_we = 1'b1;
1258
- if (~instr[14]) begin
1259
- rf_ren_a_o = 1'b1;
1260
- end
1261
- unique case (instr[13:12])
1262
- 2'b01: csr_op = CSR_OP_WRITE;
1263
- 2'b10: csr_op = CSR_OP_SET;
1264
- 2'b11: csr_op = CSR_OP_CLEAR;
1265
- default: csr_illegal = 1'b1;
1266
- endcase
1267
- illegal_insn = csr_illegal;
1268
- end
1269
- end
1270
- default: begin
1271
- illegal_insn = 1'b1;
1272
- end
1273
- endcase
1274
- // make sure illegal compressed instructions cause illegal instruction exceptions
1275
- if (illegal_c_insn_i) begin
1276
- illegal_insn = 1'b1;
1277
- end
1278
- // make sure illegal instructions detected in the decoder do not propagate from decoder
1279
- // into register file, LSU, EX, WB, CSRs, PC
1280
- // NOTE: instructions can also be detected to be illegal inside the CSRs (upon accesses with
1281
- // insufficient privileges), or when accessing non-available registers in RV32E,
1282
- // these cases are not handled here
1283
- if (illegal_insn) begin
1284
- rf_we = 1'b0;
1285
- data_req_o = 1'b0;
1286
- data_we_o = 1'b0;
1287
- jump_in_dec_o = 1'b0;
1288
- jump_set_o = 1'b0;
1289
- branch_in_dec_o = 1'b0;
1290
- csr_access_o = 1'b0;
1291
- // CV-X-IF
1292
- if(XInterface) begin
1293
- rf_ren_a_o = x_issue_resp_register_read_i[0];
1294
- rf_ren_b_o = x_issue_resp_register_read_i[1];
1295
- rf_ren_c_o = x_issue_resp_register_read_i[2];
1296
- rf_wdata_sel_o = $bits(rf_wdata_sel_o)'({RF_WD_COPROC});
1297
- end
1298
- end
1299
- end
1300
- /////////////////////////////
1301
- // Decoder for ALU control //
1302
- /////////////////////////////
1303
- always_comb begin
1304
- alu_operator_o = ALU_SLTU;
1305
- alu_op_a_mux_sel_o = OP_A_IMM;
1306
- alu_op_b_mux_sel_o = OP_B_IMM;
1307
- imm_a_mux_sel_o = IMM_A_ZERO;
1308
- imm_b_mux_sel_o = IMM_B_I;
1309
- opcode_alu = opcode_e'(instr_alu[6:0]);
1310
- use_rs3_d = 1'b0;
1311
- alu_multicycle_o = 1'b0;
1312
- mult_sel_o = 1'b0;
1313
- div_sel_o = 1'b0;
1314
- unique case (opcode_alu)
1315
- ///////////
1316
- // Jumps //
1317
- ///////////
1318
- OPCODE_JAL: begin // Jump and Link
1319
- // Jumps take two cycles without the BTALU
1320
- if (instr_first_cycle_i) begin
1321
- // Calculate jump target
1322
- alu_op_a_mux_sel_o = OP_A_CURRPC;
1323
- alu_op_b_mux_sel_o = OP_B_IMM;
1324
- imm_b_mux_sel_o = IMM_B_J;
1325
- alu_operator_o = ALU_ADD;
1326
- end else begin
1327
- // Calculate and store PC+4
1328
- alu_op_a_mux_sel_o = OP_A_CURRPC;
1329
- alu_op_b_mux_sel_o = OP_B_IMM;
1330
- imm_b_mux_sel_o = IMM_B_INCR_PC;
1331
- alu_operator_o = ALU_ADD;
1332
- end
1333
- end
1334
- OPCODE_JALR: begin // Jump and Link Register
1335
- // Jumps take two cycles without the BTALU
1336
- if (instr_first_cycle_i) begin
1337
- // Calculate jump target
1338
- alu_op_a_mux_sel_o = OP_A_REG_A;
1339
- alu_op_b_mux_sel_o = OP_B_IMM;
1340
- imm_b_mux_sel_o = IMM_B_I;
1341
- alu_operator_o = ALU_ADD;
1342
- end else begin
1343
- // Calculate and store PC+4
1344
- alu_op_a_mux_sel_o = OP_A_CURRPC;
1345
- alu_op_b_mux_sel_o = OP_B_IMM;
1346
- imm_b_mux_sel_o = IMM_B_INCR_PC;
1347
- alu_operator_o = ALU_ADD;
1348
- end
1349
- end
1350
- OPCODE_BRANCH: begin // Branch
1351
- // Check branch condition selection
1352
- unique case (instr_alu[14:12])
1353
- 3'b000: alu_operator_o = ALU_EQ;
1354
- 3'b001: alu_operator_o = ALU_NE;
1355
- 3'b100: alu_operator_o = ALU_LT;
1356
- 3'b101: alu_operator_o = ALU_GE;
1357
- 3'b110: alu_operator_o = ALU_LTU;
1358
- 3'b111: alu_operator_o = ALU_GEU;
1359
- default: ;
1360
- endcase
1361
- // Without branch target ALU, a branch is a two-stage operation using the Main ALU in both
1362
- // stages
1363
- if (instr_first_cycle_i) begin
1364
- // First evaluate the branch condition
1365
- alu_op_a_mux_sel_o = OP_A_REG_A;
1366
- alu_op_b_mux_sel_o = OP_B_REG_B;
1367
- end else begin
1368
- // Then calculate jump target
1369
- alu_op_a_mux_sel_o = OP_A_CURRPC;
1370
- alu_op_b_mux_sel_o = OP_B_IMM;
1371
- // Not-taken branch will jump to next instruction (used in secure mode)
1372
- imm_b_mux_sel_o = IMM_B_B;
1373
- alu_operator_o = ALU_ADD;
1374
- end
1375
- end
1376
- ////////////////
1377
- // Load/store //
1378
- ////////////////
1379
- OPCODE_STORE: begin
1380
- alu_op_a_mux_sel_o = OP_A_REG_A;
1381
- alu_op_b_mux_sel_o = OP_B_REG_B;
1382
- alu_operator_o = ALU_ADD;
1383
- if (!instr_alu[14]) begin
1384
- // offset from immediate
1385
- imm_b_mux_sel_o = IMM_B_S;
1386
- alu_op_b_mux_sel_o = OP_B_IMM;
1387
- end
1388
- end
1389
- OPCODE_LOAD: begin
1390
- alu_op_a_mux_sel_o = OP_A_REG_A;
1391
- // offset from immediate
1392
- alu_operator_o = ALU_ADD;
1393
- alu_op_b_mux_sel_o = OP_B_IMM;
1394
- imm_b_mux_sel_o = IMM_B_I;
1395
- end
1396
- /////////
1397
- // ALU //
1398
- /////////
1399
- OPCODE_LUI: begin // Load Upper Immediate
1400
- alu_op_a_mux_sel_o = OP_A_IMM;
1401
- alu_op_b_mux_sel_o = OP_B_IMM;
1402
- imm_a_mux_sel_o = IMM_A_ZERO;
1403
- imm_b_mux_sel_o = IMM_B_U;
1404
- alu_operator_o = ALU_ADD;
1405
- end
1406
- OPCODE_AUIPC: begin // Add Upper Immediate to PC
1407
- alu_op_a_mux_sel_o = OP_A_CURRPC;
1408
- alu_op_b_mux_sel_o = OP_B_IMM;
1409
- imm_b_mux_sel_o = IMM_B_U;
1410
- alu_operator_o = ALU_ADD;
1411
- end
1412
- OPCODE_OP_IMM: begin // Register-Immediate ALU Operations
1413
- alu_op_a_mux_sel_o = OP_A_REG_A;
1414
- alu_op_b_mux_sel_o = OP_B_IMM;
1415
- imm_b_mux_sel_o = IMM_B_I;
1416
- unique case (instr_alu[14:12])
1417
- 3'b000: alu_operator_o = ALU_ADD; // Add Immediate
1418
- 3'b010: alu_operator_o = ALU_SLT; // Set to one if Lower Than Immediate
1419
- 3'b011: alu_operator_o = ALU_SLTU; // Set to one if Lower Than Immediate Unsigned
1420
- 3'b100: alu_operator_o = ALU_XOR; // Exclusive Or with Immediate
1421
- 3'b110: alu_operator_o = ALU_OR; // Or with Immediate
1422
- 3'b111: alu_operator_o = ALU_AND; // And with Immediate
1423
- 3'b001: begin
1424
- if (RV32B != RV32BNone) begin
1425
- unique case (instr_alu[31:27])
1426
- 5'b0_0000: alu_operator_o = ALU_SLL; // Shift Left Logical by Immediate
1427
- // Shift Left Ones by Immediate
1428
- 5'b0_0100: begin
1429
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) alu_operator_o = ALU_SLO;
1430
- end
1431
- 5'b0_1001: alu_operator_o = ALU_BCLR; // Clear bit specified by immediate
1432
- 5'b0_0101: alu_operator_o = ALU_BSET; // Set bit specified by immediate
1433
- 5'b0_1101: alu_operator_o = ALU_BINV; // Invert bit specified by immediate.
1434
- // Shuffle with Immediate Control Value
1435
- 5'b0_0001: if (instr_alu[26] == 0) alu_operator_o = ALU_SHFL;
1436
- 5'b0_1100: begin
1437
- unique case (instr_alu[26:20])
1438
- 7'b000_0000: alu_operator_o = ALU_CLZ; // clz
1439
- 7'b000_0001: alu_operator_o = ALU_CTZ; // ctz
1440
- 7'b000_0010: alu_operator_o = ALU_CPOP; // cpop
1441
- 7'b000_0100: alu_operator_o = ALU_SEXTB; // sext.b
1442
- 7'b000_0101: alu_operator_o = ALU_SEXTH; // sext.h
1443
- 7'b001_0000: begin
1444
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) begin
1445
- alu_operator_o = ALU_CRC32_B; // crc32.b
1446
- alu_multicycle_o = 1'b1;
1447
- end
1448
- end
1449
- 7'b001_0001: begin
1450
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) begin
1451
- alu_operator_o = ALU_CRC32_H; // crc32.h
1452
- alu_multicycle_o = 1'b1;
1453
- end
1454
- end
1455
- 7'b001_0010: begin
1456
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) begin
1457
- alu_operator_o = ALU_CRC32_W; // crc32.w
1458
- alu_multicycle_o = 1'b1;
1459
- end
1460
- end
1461
- 7'b001_1000: begin
1462
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) begin
1463
- alu_operator_o = ALU_CRC32C_B; // crc32c.b
1464
- alu_multicycle_o = 1'b1;
1465
- end
1466
- end
1467
- 7'b001_1001: begin
1468
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) begin
1469
- alu_operator_o = ALU_CRC32C_H; // crc32c.h
1470
- alu_multicycle_o = 1'b1;
1471
- end
1472
- end
1473
- 7'b001_1010: begin
1474
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) begin
1475
- alu_operator_o = ALU_CRC32C_W; // crc32c.w
1476
- alu_multicycle_o = 1'b1;
1477
- end
1478
- end
1479
- default: ;
1480
- endcase
1481
- end
1482
- default: ;
1483
- endcase
1484
- end else begin
1485
- alu_operator_o = ALU_SLL; // Shift Left Logical by Immediate
1486
- end
1487
- end
1488
- 3'b101: begin
1489
- if (RV32B != RV32BNone) begin
1490
- if (instr_alu[26] == 1'b1) begin
1491
- alu_operator_o = ALU_FSR;
1492
- alu_multicycle_o = 1'b1;
1493
- if (instr_first_cycle_i) begin
1494
- use_rs3_d = 1'b1;
1495
- end else begin
1496
- use_rs3_d = 1'b0;
1497
- end
1498
- end else begin
1499
- unique case (instr_alu[31:27])
1500
- 5'b0_0000: alu_operator_o = ALU_SRL; // Shift Right Logical by Immediate
1501
- 5'b0_1000: alu_operator_o = ALU_SRA; // Shift Right Arithmetically by Immediate
1502
- // Shift Right Ones by Immediate
1503
- 5'b0_0100: begin
1504
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) alu_operator_o = ALU_SRO;
1505
- end
1506
- 5'b0_1001: alu_operator_o = ALU_BEXT; // Extract bit specified by immediate.
1507
- 5'b0_1100: begin
1508
- alu_operator_o = ALU_ROR; // Rotate Right by Immediate
1509
- alu_multicycle_o = 1'b1;
1510
- end
1511
- 5'b0_1101: alu_operator_o = ALU_GREV; // General Reverse with Imm Control Val
1512
- 5'b0_0101: alu_operator_o = ALU_GORC; // General Or-combine with Imm Control Val
1513
- // Unshuffle with Immediate Control Value
1514
- 5'b0_0001: begin
1515
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) begin
1516
- if (instr_alu[26] == 1'b0) alu_operator_o = ALU_UNSHFL;
1517
- end
1518
- end
1519
- default: ;
1520
- endcase
1521
- end
1522
- end else begin
1523
- if (instr_alu[31:27] == 5'b0_0000) begin
1524
- alu_operator_o = ALU_SRL; // Shift Right Logical by Immediate
1525
- end else if (instr_alu[31:27] == 5'b0_1000) begin
1526
- alu_operator_o = ALU_SRA; // Shift Right Arithmetically by Immediate
1527
- end
1528
- end
1529
- end
1530
- default: ;
1531
- endcase
1532
- end
1533
- OPCODE_OP: begin // Register-Register ALU operation
1534
- alu_op_a_mux_sel_o = OP_A_REG_A;
1535
- alu_op_b_mux_sel_o = OP_B_REG_B;
1536
- if (instr_alu[26]) begin
1537
- if (RV32B != RV32BNone) begin
1538
- unique case ({instr_alu[26:25], instr_alu[14:12]})
1539
- {2'b11, 3'b001}: begin
1540
- alu_operator_o = ALU_CMIX; // cmix
1541
- alu_multicycle_o = 1'b1;
1542
- if (instr_first_cycle_i) begin
1543
- use_rs3_d = 1'b1;
1544
- end else begin
1545
- use_rs3_d = 1'b0;
1546
- end
1547
- end
1548
- {2'b11, 3'b101}: begin
1549
- alu_operator_o = ALU_CMOV; // cmov
1550
- alu_multicycle_o = 1'b1;
1551
- if (instr_first_cycle_i) begin
1552
- use_rs3_d = 1'b1;
1553
- end else begin
1554
- use_rs3_d = 1'b0;
1555
- end
1556
- end
1557
- {2'b10, 3'b001}: begin
1558
- alu_operator_o = ALU_FSL; // fsl
1559
- alu_multicycle_o = 1'b1;
1560
- if (instr_first_cycle_i) begin
1561
- use_rs3_d = 1'b1;
1562
- end else begin
1563
- use_rs3_d = 1'b0;
1564
- end
1565
- end
1566
- {2'b10, 3'b101}: begin
1567
- alu_operator_o = ALU_FSR; // fsr
1568
- alu_multicycle_o = 1'b1;
1569
- if (instr_first_cycle_i) begin
1570
- use_rs3_d = 1'b1;
1571
- end else begin
1572
- use_rs3_d = 1'b0;
1573
- end
1574
- end
1575
- default: ;
1576
- endcase
1577
- end
1578
- end else begin
1579
- unique case ({instr_alu[31:25], instr_alu[14:12]})
1580
- // RV32I ALU operations
1581
- {7'b000_0000, 3'b000}: alu_operator_o = ALU_ADD; // Add
1582
- {7'b010_0000, 3'b000}: alu_operator_o = ALU_SUB; // Sub
1583
- {7'b000_0000, 3'b010}: alu_operator_o = ALU_SLT; // Set Lower Than
1584
- {7'b000_0000, 3'b011}: alu_operator_o = ALU_SLTU; // Set Lower Than Unsigned
1585
- {7'b000_0000, 3'b100}: alu_operator_o = ALU_XOR; // Xor
1586
- {7'b000_0000, 3'b110}: alu_operator_o = ALU_OR; // Or
1587
- {7'b000_0000, 3'b111}: alu_operator_o = ALU_AND; // And
1588
- {7'b000_0000, 3'b001}: alu_operator_o = ALU_SLL; // Shift Left Logical
1589
- {7'b000_0000, 3'b101}: alu_operator_o = ALU_SRL; // Shift Right Logical
1590
- {7'b010_0000, 3'b101}: alu_operator_o = ALU_SRA; // Shift Right Arithmetic
1591
- // RV32B ALU Operations
1592
- {7'b011_0000, 3'b001}: begin
1593
- if (RV32B != RV32BNone) begin
1594
- alu_operator_o = ALU_ROL;
1595
- alu_multicycle_o = 1'b1;
1596
- end
1597
- end
1598
- {7'b011_0000, 3'b101}: begin
1599
- if (RV32B != RV32BNone) begin
1600
- alu_operator_o = ALU_ROR;
1601
- alu_multicycle_o = 1'b1;
1602
- end
1603
- end
1604
- {7'b000_0101, 3'b100}: if (RV32B != RV32BNone) alu_operator_o = ALU_MIN;
1605
- {7'b000_0101, 3'b110}: if (RV32B != RV32BNone) alu_operator_o = ALU_MAX;
1606
- {7'b000_0101, 3'b101}: if (RV32B != RV32BNone) alu_operator_o = ALU_MINU;
1607
- {7'b000_0101, 3'b111}: if (RV32B != RV32BNone) alu_operator_o = ALU_MAXU;
1608
- {7'b000_0100, 3'b100}: if (RV32B != RV32BNone) alu_operator_o = ALU_PACK;
1609
- {7'b010_0100, 3'b100}: if (RV32B != RV32BNone) alu_operator_o = ALU_PACKU;
1610
- {7'b000_0100, 3'b111}: if (RV32B != RV32BNone) alu_operator_o = ALU_PACKH;
1611
- {7'b010_0000, 3'b100}: if (RV32B != RV32BNone) alu_operator_o = ALU_XNOR;
1612
- {7'b010_0000, 3'b110}: if (RV32B != RV32BNone) alu_operator_o = ALU_ORN;
1613
- {7'b010_0000, 3'b111}: if (RV32B != RV32BNone) alu_operator_o = ALU_ANDN;
1614
- // RV32B zba
1615
- {7'b001_0000, 3'b010}: if (RV32B != RV32BNone) alu_operator_o = ALU_SH1ADD;
1616
- {7'b001_0000, 3'b100}: if (RV32B != RV32BNone) alu_operator_o = ALU_SH2ADD;
1617
- {7'b001_0000, 3'b110}: if (RV32B != RV32BNone) alu_operator_o = ALU_SH3ADD;
1618
- // RV32B zbs
1619
- {7'b010_0100, 3'b001}: if (RV32B != RV32BNone) alu_operator_o = ALU_BCLR;
1620
- {7'b001_0100, 3'b001}: if (RV32B != RV32BNone) alu_operator_o = ALU_BSET;
1621
- {7'b011_0100, 3'b001}: if (RV32B != RV32BNone) alu_operator_o = ALU_BINV;
1622
- {7'b010_0100, 3'b101}: if (RV32B != RV32BNone) alu_operator_o = ALU_BEXT;
1623
- // RV32B zbf
1624
- {7'b010_0100, 3'b111}: if (RV32B != RV32BNone) alu_operator_o = ALU_BFP;
1625
- // RV32B zbp
1626
- {7'b011_0100, 3'b101}: if (RV32B != RV32BNone) alu_operator_o = ALU_GREV;
1627
- {7'b001_0100, 3'b101}: if (RV32B != RV32BNone) alu_operator_o = ALU_GORC;
1628
- {7'b000_0100, 3'b001}: begin
1629
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) alu_operator_o = ALU_SHFL;
1630
- end
1631
- {7'b000_0100, 3'b101}: begin
1632
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) alu_operator_o = ALU_UNSHFL;
1633
- end
1634
- {7'b001_0100, 3'b010}: begin
1635
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) alu_operator_o = ALU_XPERM_N;
1636
- end
1637
- {7'b001_0100, 3'b100}: begin
1638
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) alu_operator_o = ALU_XPERM_B;
1639
- end
1640
- {7'b001_0100, 3'b110}: begin
1641
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) alu_operator_o = ALU_XPERM_H;
1642
- end
1643
- {7'b001_0000, 3'b001}: begin
1644
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) alu_operator_o = ALU_SLO;
1645
- end
1646
- {7'b001_0000, 3'b101}: begin
1647
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) alu_operator_o = ALU_SRO;
1648
- end
1649
- // RV32B zbc
1650
- {7'b000_0101, 3'b001}: begin
1651
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) alu_operator_o = ALU_CLMUL;
1652
- end
1653
- {7'b000_0101, 3'b010}: begin
1654
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) alu_operator_o = ALU_CLMULR;
1655
- end
1656
- {7'b000_0101, 3'b011}: begin
1657
- if (RV32B == RV32BOTEarlGrey || RV32B == RV32BFull) alu_operator_o = ALU_CLMULH;
1658
- end
1659
- // RV32B zbe
1660
- {7'b010_0100, 3'b110}: begin
1661
- if (RV32B == RV32BFull) begin
1662
- alu_operator_o = ALU_BDECOMPRESS;
1663
- alu_multicycle_o = 1'b1;
1664
- end
1665
- end
1666
- {7'b000_0100, 3'b110}: begin
1667
- if (RV32B == RV32BFull) begin
1668
- alu_operator_o = ALU_BCOMPRESS;
1669
- alu_multicycle_o = 1'b1;
1670
- end
1671
- end
1672
- // RV32M instructions, all use the same ALU operation
1673
- {7'b000_0001, 3'b000}: begin // mul
1674
- alu_operator_o = ALU_ADD;
1675
- mult_sel_o = (RV32M == RV32MNone) ? 1'b0 : 1'b1;
1676
- end
1677
- {7'b000_0001, 3'b001}: begin // mulh
1678
- alu_operator_o = ALU_ADD;
1679
- mult_sel_o = (RV32M == RV32MNone) ? 1'b0 : 1'b1;
1680
- end
1681
- {7'b000_0001, 3'b010}: begin // mulhsu
1682
- alu_operator_o = ALU_ADD;
1683
- mult_sel_o = (RV32M == RV32MNone) ? 1'b0 : 1'b1;
1684
- end
1685
- {7'b000_0001, 3'b011}: begin // mulhu
1686
- alu_operator_o = ALU_ADD;
1687
- mult_sel_o = (RV32M == RV32MNone) ? 1'b0 : 1'b1;
1688
- end
1689
- {7'b000_0001, 3'b100}: begin // div
1690
- alu_operator_o = ALU_ADD;
1691
- div_sel_o = (RV32M == RV32MNone) ? 1'b0 : 1'b1;
1692
- end
1693
- {7'b000_0001, 3'b101}: begin // divu
1694
- alu_operator_o = ALU_ADD;
1695
- div_sel_o = (RV32M == RV32MNone) ? 1'b0 : 1'b1;
1696
- end
1697
- {7'b000_0001, 3'b110}: begin // rem
1698
- alu_operator_o = ALU_ADD;
1699
- div_sel_o = (RV32M == RV32MNone) ? 1'b0 : 1'b1;
1700
- end
1701
- {7'b000_0001, 3'b111}: begin // remu
1702
- alu_operator_o = ALU_ADD;
1703
- div_sel_o = (RV32M == RV32MNone) ? 1'b0 : 1'b1;
1704
- end
1705
- default: ;
1706
- endcase
1707
- end
1708
- end
1709
- /////////////
1710
- // Special //
1711
- /////////////
1712
- OPCODE_MISC_MEM: begin
1713
- unique case (instr_alu[14:12])
1714
- 3'b000: begin
1715
- // FENCE is treated as a NOP since all memory operations are already strictly ordered.
1716
- alu_operator_o = ALU_ADD; // nop
1717
- alu_op_a_mux_sel_o = OP_A_REG_A;
1718
- alu_op_b_mux_sel_o = OP_B_IMM;
1719
- end
1720
- 3'b001: begin
1721
- // FENCE.I will flush the IF stage, prefetch buffer and ICache if present.
1722
- alu_op_a_mux_sel_o = OP_A_CURRPC;
1723
- alu_op_b_mux_sel_o = OP_B_IMM;
1724
- imm_b_mux_sel_o = IMM_B_INCR_PC;
1725
- alu_operator_o = ALU_ADD;
1726
- end
1727
- default: ;
1728
- endcase
1729
- end
1730
- OPCODE_SYSTEM: begin
1731
- if (instr_alu[14:12] == 3'b000) begin
1732
- // non CSR related SYSTEM instructions
1733
- alu_op_a_mux_sel_o = OP_A_REG_A;
1734
- alu_op_b_mux_sel_o = OP_B_IMM;
1735
- end else begin
1736
- // instruction to read/modify CSR
1737
- alu_op_b_mux_sel_o = OP_B_IMM;
1738
- imm_a_mux_sel_o = IMM_A_Z;
1739
- imm_b_mux_sel_o = IMM_B_I; // CSR address is encoded in I imm
1740
- if (instr_alu[14]) begin
1741
- // rs1 field is used as immediate
1742
- alu_op_a_mux_sel_o = OP_A_IMM;
1743
- end else begin
1744
- alu_op_a_mux_sel_o = OP_A_REG_A;
1745
- end
1746
- end
1747
- end
1748
- default: ;
1749
- endcase
1750
- end
1751
- // do not enable multdiv in case of illegal instruction exceptions
1752
- assign mult_en_o = illegal_insn ? 1'b0 : mult_sel_o;
1753
- assign div_en_o = illegal_insn ? 1'b0 : div_sel_o;
1754
- // make sure instructions accessing non-available registers in RV32E cause illegal
1755
- // instruction exceptions
1756
- assign illegal_insn_o = illegal_insn | illegal_reg_rv32e;
1757
- // do not propgate regfile write enable if non-available registers are accessed in RV32E
1758
- assign rf_we_o = rf_we & ~illegal_reg_rv32e;
1759
- // Not all bits are used
1760
- assign unused_instr_alu = {instr_alu[19:15],instr_alu[11:7]};
1761
- ////////////////
1762
- // Assertions //
1763
- ////////////////
1764
- // Selectors must be known/valid.
1765
- endmodule // controller
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p6/mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"conditional_statement": [[61396, 61448], [61027, 61078], [44904, 44989], [60512, 60561], [39739, 44255], [66584, 67198], [48843, 49324], [34148, 34244], [57292, 57449], [35586, 35850], [62054, 62103], [38164, 38569], [61200, 61249], [48240, 48722]], "blocking_assignment": [[50722, 50753], [31678, 31707], [31712, 31741], [46305, 46327], [56949, 56977], [45694, 45714], [47249, 47272], [62274, 62300], [59812, 59861], [63643, 63671]], "always_construct": [[30563, 30880], [47687, 67243], [30931, 47588]], "case_statement": [[49424, 49757], [32862, 33074], [65885, 66538], [33948, 34346], [35916, 37202], [44363, 45097], [34926, 37285], [59170, 65765], [51731, 57516], [48061, 67237], [39914, 44243], [31831, 46518], [45236, 45732], [33476, 33699], [46171, 46386], [34734, 39565], [37493, 39479]], "ansi_port_declaration": [[24644, 24687], [24460, 24549], [24173, 24262], [23602, 23692], [23778, 23869], [26573, 26628], [24942, 25019], [23872, 23948], [23448, 23530]], "continuous_assign": [[67537, 67594], [30444, 30476], [67315, 67367], [29031, 29084], [28402, 28439], [28610, 28666], [28366, 28399], [29643, 29675]], "parameter_declaration": [[23011, 23067], [16946, 16990], [16850, 16895], [23070, 23126], [16898, 16943], [16993, 17037], [13787, 13814], [13622, 13688], [23129, 23177], [13551, 13619]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p7/all_mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"module_program_interface_instantiation": [[34716, 35504], [58435, 59548], [60533, 60848]], "continuous_assign": [[24673, 24725], [24728, 24778], [24781, 24820], [25392, 25538], [25929, 26183], [26349, 26488], [26576, 26687], [26734, 26798], [26801, 26865], [27661, 27722], [27805, 27937], [27940, 28112], [28115, 28215], [28446, 28492], [28575, 28612], [28892, 28940], [29114, 29201], [29353, 29395], [29436, 29493], [29589, 29692], [29745, 29817], [29866, 29913], [29990, 30205], [30258, 30320], [30325, 30385], [30448, 30521], [30524, 30621], [30624, 30700], [30703, 30772], [30775, 30851], [30854, 30901], [30904, 30949], [33753, 33806], [34177, 34206], [34358, 34426], [34655, 34713], [35650, 35765], [35768, 35815], [35884, 35930], [36005, 36069], [36885, 36953], [37006, 37040], [37383, 37448], [37451, 37704], [37914, 38082], [38085, 38141], [38570, 38691], [38848, 39058], [39230, 39417], [39424, 39700], [39768, 39925], [39928, 40079], [40162, 40220], [40223, 40249], [40792, 40824], [40827, 40870], [40873, 40900], [42171, 42201], [51114, 51163], [56994, 57037], [57040, 57083], [57133, 57169], [57172, 57256], [57694, 57732], [58313, 58372], [59551, 59597], [59600, 59630], [59633, 59665], [59668, 59703], [59854, 59983], [60025, 60076], [60171, 60326], [61132, 61272], [61275, 61329], [61591, 61634], [61725, 61766], [61836, 61878], [62846, 62881]], "blocking_assignment": [[27074, 27108], [27115, 27147], [27154, 27182], [27232, 27252], [27282, 27312], [27370, 27394], [27401, 27423], [27430, 27453], [27460, 27484], [42374, 42400], [42405, 42428], [42663, 42818], [42859, 42882], [42974, 43126], [43219, 43408], [43531, 43554], [43606, 43629], [44094, 44227], [44368, 44581], [44735, 44859], [45006, 45080], [45191, 45341], [45411, 45434], [45760, 45904], [45947, 45970], [46078, 46229], [46436, 46575], [46701, 46833], [46959, 47091], [47217, 47349], [47572, 47595], [47671, 47694], [47804, 47827], [48016, 48225], [48277, 48300], [48806, 48892], [48931, 48988], [49079, 49210], [49251, 49274], [49529, 49600], [49692, 49752], [49796, 49819], [50036, 50116], [50253, 50281], [50378, 50444], [50590, 50724], [50829, 50852], [50904, 50927], [51060, 51083], [57375, 57426], [57449, 57500], [57523, 57547], [57570, 57599], [57622, 57673], [57852, 57896], [57912, 57946], [57962, 58037], [58053, 58135], [58151, 58177], [58193, 58237]], "nonblocking_assignment": [[28298, 28317], [28362, 28391], [31101, 31115], [31141, 31160], [31326, 31343], [31354, 31371], [31422, 31447], [31458, 31481], [37190, 37210], [37256, 37287], [37787, 37806], [37851, 37880], [40386, 40415], [40422, 40451], [40458, 40486], [40493, 40521], [40547, 40583], [40590, 40628], [40635, 40679], [40686, 40727], [61412, 61437], [61444, 61469], [61495, 61532], [61539, 61574], [61961, 61992], [61999, 62030], [62037, 62068], [62075, 62106], [62113, 62144], [62151, 62182], [62189, 62220], [62227, 62258], [62307, 62354], [62455, 62502], [62509, 62550], [62557, 62604], [62611, 62681], [62688, 62736], [62743, 62786], [62793, 62829]], "case_statement": [[42485, 51105], [42551, 43659], [43964, 48330], [45485, 47865], [46291, 47740], [48635, 50957], [57326, 57685], [57807, 58249]], "conditional_statement": [[27019, 27492], [27189, 27322], [28273, 28399], [28331, 28399], [31076, 31168], [31297, 31493], [31389, 31493], [37165, 37295], [37224, 37295], [37762, 37888], [37820, 37888], [40361, 40735], [42831, 42882], [45093, 45357], [45370, 45434], [45921, 45970], [48905, 48988], [49223, 49274], [49325, 50498], [49370, 49837], [49769, 49819], [49879, 50482], [50162, 50464], [61387, 61582], [61936, 62837], [62272, 62837]], "always_construct": [[26997, 27498], [28218, 28405], [31021, 31174], [31238, 31503], [37110, 37301], [37707, 37894], [40306, 40741], [42285, 51111], [57291, 57691], [57768, 58255], [61332, 61588], [61881, 62843]], "parameter_declaration": [[6471, 6520], [6523, 6571], [6594, 6628], [6631, 6665], [6668, 6702], [12379, 12461], [12464, 12546], [12570, 12622], [12625, 12677], [12680, 12733], [12736, 12789], [12792, 12845], [12848, 12901], [12925, 13002], [13044, 13089], [13092, 13137], [13140, 13186], [13189, 13235], [13238, 13284], [13332, 13380], [13383, 13431], [13434, 13482], [13551, 13619], [13622, 13688], [13787, 13814], [16708, 16752], [16755, 16799], [16802, 16847], [16850, 16895], [16898, 16943], [16946, 16990], [16993, 17037], [17040, 17096], [23031, 23066]], "ansi_port_declaration": [[23073, 23107], [23110, 23145], [23169, 23242], [23245, 23280], [23299, 23338], [23341, 23379], [23382, 23421], [23424, 23461], [23481, 23521], [23524, 23564], [23567, 23606], [23609, 23649], [23652, 23690], [23693, 23736], [32149, 32175], [32178, 32205], [32208, 32234], [32237, 32266], [32269, 32296], [32299, 32327], [32330, 32358], [32361, 32389], [32392, 32419], [32422, 32448], [32451, 32483], [32538, 32570], [32573, 32605], [32608, 32641], [32644, 32678], [32681, 32713], [32716, 32751], [32782, 32808], [41754, 41780], [41783, 41810], [41813, 41841], [41844, 41872], [41875, 41903], [41906, 41942], [41945, 41980], [52130, 52173], [52176, 52220], [52223, 52308], [52311, 52404], [52440, 52488], [52491, 52540], [52543, 52591], [52594, 52645], [52648, 52698], [52701, 52749], [52776, 52864], [52867, 52953], [52956, 53039], [53042, 53136], [53224, 53318], [53515, 53610], [53702, 53785], [53788, 53873], [53876, 53971], [54061, 54105], [54108, 54152], [54155, 54204], [54207, 54262], [54286, 54381], [54384, 54474], [54477, 54569], [54572, 54656], [54659, 54747], [54872, 54963], [54976, 55069], [55163, 55256], [55344, 55440], [55443, 55537], [55559, 55644], [55647, 55732], [55755, 55851], [55872, 55968]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p7/cve2_if_stage.sv DELETED
@@ -1,1605 +0,0 @@
1
- // Copyright (c) 2025 Eclipse Foundation
2
- // Copyright lowRISC contributors.
3
- // Copyright 2017 ETH Zurich and University of Bologna, see also CREDITS.md.
4
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
5
- // SPDX-License-Identifier: Apache-2.0
6
- /**
7
- * Package with constants used by CVE2
8
- */
9
- package cve2_pkg;
10
- ////////////////
11
- // IO Structs //
12
- ////////////////
13
- typedef struct packed {
14
- logic [31:0] current_pc;
15
- logic [31:0] next_pc;
16
- logic [31:0] last_data_addr;
17
- logic [31:0] exception_addr;
18
- } crash_dump_t;
19
- typedef struct packed {
20
- logic dummy_instr_id;
21
- logic [4:0] raddr_a;
22
- logic [4:0] waddr_a;
23
- logic we_a;
24
- logic [4:0] raddr_b;
25
- } core2rf_t;
26
- /////////////////////
27
- // Parameter Enums //
28
- /////////////////////
29
- typedef enum integer {
30
- RV32MNone = 0,
31
- RV32MSlow = 1,
32
- RV32MFast = 2,
33
- RV32MSingleCycle = 3
34
- } rv32m_e;
35
- typedef enum integer {
36
- RV32BNone = 0,
37
- RV32BBalanced = 1,
38
- RV32BOTEarlGrey = 2,
39
- RV32BFull = 3
40
- } rv32b_e;
41
- /////////////
42
- // Opcodes //
43
- /////////////
44
- typedef enum logic [6:0] {
45
- OPCODE_LOAD = 7'h03,
46
- OPCODE_MISC_MEM = 7'h0f,
47
- OPCODE_OP_IMM = 7'h13,
48
- OPCODE_AUIPC = 7'h17,
49
- OPCODE_STORE = 7'h23,
50
- OPCODE_OP = 7'h33,
51
- OPCODE_LUI = 7'h37,
52
- OPCODE_BRANCH = 7'h63,
53
- OPCODE_JALR = 7'h67,
54
- OPCODE_JAL = 7'h6f,
55
- OPCODE_SYSTEM = 7'h73
56
- } opcode_e;
57
- ////////////////////
58
- // ALU operations //
59
- ////////////////////
60
- typedef enum logic [6:0] {
61
- // Arithmetics
62
- ALU_ADD,
63
- ALU_SUB,
64
- // Logics
65
- ALU_XOR,
66
- ALU_OR,
67
- ALU_AND,
68
- // RV32B
69
- ALU_XNOR,
70
- ALU_ORN,
71
- ALU_ANDN,
72
- // Shifts
73
- ALU_SRA,
74
- ALU_SRL,
75
- ALU_SLL,
76
- // RV32B
77
- ALU_SRO,
78
- ALU_SLO,
79
- ALU_ROR,
80
- ALU_ROL,
81
- ALU_GREV,
82
- ALU_GORC,
83
- ALU_SHFL,
84
- ALU_UNSHFL,
85
- ALU_XPERM_N,
86
- ALU_XPERM_B,
87
- ALU_XPERM_H,
88
- // Address Calculations
89
- // RV32B
90
- ALU_SH1ADD,
91
- ALU_SH2ADD,
92
- ALU_SH3ADD,
93
- // Comparisons
94
- ALU_LT,
95
- ALU_LTU,
96
- ALU_GE,
97
- ALU_GEU,
98
- ALU_EQ,
99
- ALU_NE,
100
- // RV32B
101
- ALU_MIN,
102
- ALU_MINU,
103
- ALU_MAX,
104
- ALU_MAXU,
105
- // Pack
106
- // RV32B
107
- ALU_PACK,
108
- ALU_PACKU,
109
- ALU_PACKH,
110
- // Sign-Extend
111
- // RV32B
112
- ALU_SEXTB,
113
- ALU_SEXTH,
114
- // Bitcounting
115
- // RV32B
116
- ALU_CLZ,
117
- ALU_CTZ,
118
- ALU_CPOP,
119
- // Set lower than
120
- ALU_SLT,
121
- ALU_SLTU,
122
- // Ternary Bitmanip Operations
123
- // RV32B
124
- ALU_CMOV,
125
- ALU_CMIX,
126
- ALU_FSL,
127
- ALU_FSR,
128
- // Single-Bit Operations
129
- // RV32B
130
- ALU_BSET,
131
- ALU_BCLR,
132
- ALU_BINV,
133
- ALU_BEXT,
134
- // Bit Compress / Decompress
135
- // RV32B
136
- ALU_BCOMPRESS,
137
- ALU_BDECOMPRESS,
138
- // Bit Field Place
139
- // RV32B
140
- ALU_BFP,
141
- // Carry-less Multiply
142
- // RV32B
143
- ALU_CLMUL,
144
- ALU_CLMULR,
145
- ALU_CLMULH,
146
- // Cyclic Redundancy Check
147
- ALU_CRC32_B,
148
- ALU_CRC32C_B,
149
- ALU_CRC32_H,
150
- ALU_CRC32C_H,
151
- ALU_CRC32_W,
152
- ALU_CRC32C_W
153
- } alu_op_e;
154
- typedef enum logic [1:0] {
155
- // Multiplier/divider
156
- MD_OP_MULL,
157
- MD_OP_MULH,
158
- MD_OP_DIV,
159
- MD_OP_REM
160
- } md_op_e;
161
- //////////////////////////////////
162
- // Control and status registers //
163
- //////////////////////////////////
164
- // CSR operations
165
- typedef enum logic [1:0] {
166
- CSR_OP_READ,
167
- CSR_OP_WRITE,
168
- CSR_OP_SET,
169
- CSR_OP_CLEAR
170
- } csr_op_e;
171
- // Privileged mode
172
- typedef enum logic[1:0] {
173
- PRIV_LVL_M = 2'b11,
174
- PRIV_LVL_H = 2'b10,
175
- PRIV_LVL_S = 2'b01,
176
- PRIV_LVL_U = 2'b00
177
- } priv_lvl_e;
178
- // Constants for the dcsr.xdebugver fields
179
- typedef enum logic[3:0] {
180
- XDEBUGVER_NO = 4'd0, // no external debug support
181
- XDEBUGVER_STD = 4'd4, // external debug according to RISC-V debug spec
182
- XDEBUGVER_NONSTD = 4'd15 // debug not conforming to RISC-V debug spec
183
- } x_debug_ver_e;
184
- //////////////
185
- // WB stage //
186
- //////////////
187
- // Type of instruction present in writeback stage
188
- typedef enum logic[1:0] {
189
- WB_INSTR_LOAD, // Instruction is awaiting load data
190
- WB_INSTR_STORE, // Instruction is awaiting store response
191
- WB_INSTR_OTHER // Instruction doesn't fit into above categories
192
- } wb_instr_type_e;
193
- //////////////
194
- // ID stage //
195
- //////////////
196
- // Operand a selection
197
- typedef enum logic[1:0] {
198
- OP_A_REG_A,
199
- OP_A_FWD,
200
- OP_A_CURRPC,
201
- OP_A_IMM
202
- } op_a_sel_e;
203
- // Immediate a selection
204
- typedef enum logic {
205
- IMM_A_Z,
206
- IMM_A_ZERO
207
- } imm_a_sel_e;
208
- // Operand b selection
209
- typedef enum logic {
210
- OP_B_REG_B,
211
- OP_B_IMM
212
- } op_b_sel_e;
213
- // Immediate b selection
214
- typedef enum logic [2:0] {
215
- IMM_B_I,
216
- IMM_B_S,
217
- IMM_B_B,
218
- IMM_B_U,
219
- IMM_B_J,
220
- IMM_B_INCR_PC,
221
- IMM_B_INCR_ADDR
222
- } imm_b_sel_e;
223
- // Regfile write data selection
224
- typedef enum {
225
- RF_WD_EX,
226
- RF_WD_CSR,
227
- RF_WD_COPROC // Only used when XInterface = 1
228
- } rf_wd_sel_e;
229
- //////////////
230
- // IF stage //
231
- //////////////
232
- // PC mux selection
233
- typedef enum logic [2:0] {
234
- PC_BOOT,
235
- PC_JUMP,
236
- PC_EXC,
237
- PC_ERET,
238
- PC_DRET,
239
- PC_BP
240
- } pc_sel_e;
241
- // Exception PC mux selection
242
- typedef enum logic [1:0] {
243
- EXC_PC_EXC,
244
- EXC_PC_IRQ,
245
- EXC_PC_DBD,
246
- EXC_PC_DBG_EXC // Exception while in debug mode
247
- } exc_pc_sel_e;
248
- // Interrupt requests
249
- typedef struct packed {
250
- logic irq_software;
251
- logic irq_timer;
252
- logic irq_external;
253
- logic [15:0] irq_fast; // 16 fast interrupts
254
- } irqs_t;
255
- // Exception cause
256
- typedef enum logic [6:0] {
257
- EXC_CAUSE_IRQ_SOFTWARE_M = {1'b1, 6'd03},
258
- EXC_CAUSE_IRQ_TIMER_M = {1'b1, 6'd07},
259
- EXC_CAUSE_IRQ_EXTERNAL_M = {1'b1, 6'd11},
260
- // EXC_CAUSE_IRQ_FAST_0 = {1'b1, 6'd16},
261
- // EXC_CAUSE_IRQ_FAST_15 = {1'b1, 6'd31},
262
- EXC_CAUSE_IRQ_NM = {1'b1, 6'd32},
263
- EXC_CAUSE_INSN_ADDR_MISA = {1'b0, 6'd00},
264
- EXC_CAUSE_INSTR_ACCESS_FAULT = {1'b0, 6'd01},
265
- EXC_CAUSE_ILLEGAL_INSN = {1'b0, 6'd02},
266
- EXC_CAUSE_BREAKPOINT = {1'b0, 6'd03},
267
- EXC_CAUSE_LOAD_ACCESS_FAULT = {1'b0, 6'd05},
268
- EXC_CAUSE_STORE_ACCESS_FAULT = {1'b0, 6'd07},
269
- EXC_CAUSE_ECALL_UMODE = {1'b0, 6'd08},
270
- EXC_CAUSE_ECALL_MMODE = {1'b0, 6'd11}
271
- } exc_cause_e;
272
- // Debug cause
273
- typedef enum logic [2:0] {
274
- DBG_CAUSE_NONE = 3'h0,
275
- DBG_CAUSE_EBREAK = 3'h1,
276
- DBG_CAUSE_TRIGGER = 3'h2,
277
- DBG_CAUSE_HALTREQ = 3'h3,
278
- DBG_CAUSE_STEP = 3'h4
279
- } dbg_cause_e;
280
- // PMP constants
281
- parameter int unsigned PMP_MAX_REGIONS = 16;
282
- parameter int unsigned PMP_CFG_W = 8;
283
- // PMP acces type
284
- parameter int unsigned PMP_I = 0;
285
- parameter int unsigned PMP_I2 = 1;
286
- parameter int unsigned PMP_D = 2;
287
- typedef enum logic [1:0] {
288
- PMP_ACC_EXEC = 2'b00,
289
- PMP_ACC_WRITE = 2'b01,
290
- PMP_ACC_READ = 2'b10
291
- } pmp_req_e;
292
- // PMP cfg structures
293
- typedef enum logic [1:0] {
294
- PMP_MODE_OFF = 2'b00,
295
- PMP_MODE_TOR = 2'b01,
296
- PMP_MODE_NA4 = 2'b10,
297
- PMP_MODE_NAPOT = 2'b11
298
- } pmp_cfg_mode_e;
299
- typedef struct packed {
300
- logic lock;
301
- pmp_cfg_mode_e mode;
302
- logic exec;
303
- logic write;
304
- logic read;
305
- } pmp_cfg_t;
306
- // Machine Security Configuration (ePMP)
307
- typedef struct packed {
308
- logic rlb; // Rule Locking Bypass
309
- logic mmwp; // Machine Mode Whitelist Policy
310
- logic mml; // Machine Mode Lockdown
311
- } pmp_mseccfg_t;
312
- // CSRs
313
- typedef enum logic[11:0] {
314
- // Machine information
315
- CSR_MVENDORID = 12'hF11,
316
- CSR_MARCHID = 12'hF12,
317
- CSR_MIMPID = 12'hF13,
318
- CSR_MHARTID = 12'hF14,
319
- CSR_MCONFIGPTR = 12'hF15,
320
- // Machine trap setup
321
- CSR_MSTATUS = 12'h300,
322
- CSR_MISA = 12'h301,
323
- CSR_MIE = 12'h304,
324
- CSR_MTVEC = 12'h305,
325
- CSR_MCOUNTEREN= 12'h306,
326
- CSR_MSTATUSH = 12'h310,
327
- CSR_MENVCFG = 12'h30A,
328
- CSR_MENVCFGH = 12'h31A,
329
- // Machine trap handling
330
- CSR_MSCRATCH = 12'h340,
331
- CSR_MEPC = 12'h341,
332
- CSR_MCAUSE = 12'h342,
333
- CSR_MTVAL = 12'h343,
334
- CSR_MIP = 12'h344,
335
- // Physical memory protection
336
- CSR_PMPCFG0 = 12'h3A0,
337
- CSR_PMPCFG1 = 12'h3A1,
338
- CSR_PMPCFG2 = 12'h3A2,
339
- CSR_PMPCFG3 = 12'h3A3,
340
- CSR_PMPADDR0 = 12'h3B0,
341
- CSR_PMPADDR1 = 12'h3B1,
342
- CSR_PMPADDR2 = 12'h3B2,
343
- CSR_PMPADDR3 = 12'h3B3,
344
- CSR_PMPADDR4 = 12'h3B4,
345
- CSR_PMPADDR5 = 12'h3B5,
346
- CSR_PMPADDR6 = 12'h3B6,
347
- CSR_PMPADDR7 = 12'h3B7,
348
- CSR_PMPADDR8 = 12'h3B8,
349
- CSR_PMPADDR9 = 12'h3B9,
350
- CSR_PMPADDR10 = 12'h3BA,
351
- CSR_PMPADDR11 = 12'h3BB,
352
- CSR_PMPADDR12 = 12'h3BC,
353
- CSR_PMPADDR13 = 12'h3BD,
354
- CSR_PMPADDR14 = 12'h3BE,
355
- CSR_PMPADDR15 = 12'h3BF,
356
- // ePMP control
357
- CSR_MSECCFG = 12'h747,
358
- CSR_MSECCFGH = 12'h757,
359
- // Debug trigger
360
- CSR_TSELECT = 12'h7A0,
361
- CSR_TDATA1 = 12'h7A1,
362
- CSR_TDATA2 = 12'h7A2,
363
- CSR_TDATA3 = 12'h7A3,
364
- CSR_MCONTEXT = 12'h7A8,
365
- CSR_SCONTEXT = 12'h7AA,
366
- // Debug/trace
367
- CSR_DCSR = 12'h7b0,
368
- CSR_DPC = 12'h7b1,
369
- // Debug
370
- CSR_DSCRATCH0 = 12'h7b2, // optional
371
- CSR_DSCRATCH1 = 12'h7b3, // optional
372
- // Machine Counter/Timers
373
- CSR_MCOUNTINHIBIT = 12'h320,
374
- CSR_MHPMEVENT3 = 12'h323,
375
- CSR_MHPMEVENT4 = 12'h324,
376
- CSR_MHPMEVENT5 = 12'h325,
377
- CSR_MHPMEVENT6 = 12'h326,
378
- CSR_MHPMEVENT7 = 12'h327,
379
- CSR_MHPMEVENT8 = 12'h328,
380
- CSR_MHPMEVENT9 = 12'h329,
381
- CSR_MHPMEVENT10 = 12'h32A,
382
- CSR_MHPMEVENT11 = 12'h32B,
383
- CSR_MHPMEVENT12 = 12'h32C,
384
- CSR_MHPMEVENT13 = 12'h32D,
385
- CSR_MHPMEVENT14 = 12'h32E,
386
- CSR_MHPMEVENT15 = 12'h32F,
387
- CSR_MHPMEVENT16 = 12'h330,
388
- CSR_MHPMEVENT17 = 12'h331,
389
- CSR_MHPMEVENT18 = 12'h332,
390
- CSR_MHPMEVENT19 = 12'h333,
391
- CSR_MHPMEVENT20 = 12'h334,
392
- CSR_MHPMEVENT21 = 12'h335,
393
- CSR_MHPMEVENT22 = 12'h336,
394
- CSR_MHPMEVENT23 = 12'h337,
395
- CSR_MHPMEVENT24 = 12'h338,
396
- CSR_MHPMEVENT25 = 12'h339,
397
- CSR_MHPMEVENT26 = 12'h33A,
398
- CSR_MHPMEVENT27 = 12'h33B,
399
- CSR_MHPMEVENT28 = 12'h33C,
400
- CSR_MHPMEVENT29 = 12'h33D,
401
- CSR_MHPMEVENT30 = 12'h33E,
402
- CSR_MHPMEVENT31 = 12'h33F,
403
- CSR_MCYCLE = 12'hB00,
404
- CSR_MINSTRET = 12'hB02,
405
- CSR_MHPMCOUNTER3 = 12'hB03,
406
- CSR_MHPMCOUNTER4 = 12'hB04,
407
- CSR_MHPMCOUNTER5 = 12'hB05,
408
- CSR_MHPMCOUNTER6 = 12'hB06,
409
- CSR_MHPMCOUNTER7 = 12'hB07,
410
- CSR_MHPMCOUNTER8 = 12'hB08,
411
- CSR_MHPMCOUNTER9 = 12'hB09,
412
- CSR_MHPMCOUNTER10 = 12'hB0A,
413
- CSR_MHPMCOUNTER11 = 12'hB0B,
414
- CSR_MHPMCOUNTER12 = 12'hB0C,
415
- CSR_MHPMCOUNTER13 = 12'hB0D,
416
- CSR_MHPMCOUNTER14 = 12'hB0E,
417
- CSR_MHPMCOUNTER15 = 12'hB0F,
418
- CSR_MHPMCOUNTER16 = 12'hB10,
419
- CSR_MHPMCOUNTER17 = 12'hB11,
420
- CSR_MHPMCOUNTER18 = 12'hB12,
421
- CSR_MHPMCOUNTER19 = 12'hB13,
422
- CSR_MHPMCOUNTER20 = 12'hB14,
423
- CSR_MHPMCOUNTER21 = 12'hB15,
424
- CSR_MHPMCOUNTER22 = 12'hB16,
425
- CSR_MHPMCOUNTER23 = 12'hB17,
426
- CSR_MHPMCOUNTER24 = 12'hB18,
427
- CSR_MHPMCOUNTER25 = 12'hB19,
428
- CSR_MHPMCOUNTER26 = 12'hB1A,
429
- CSR_MHPMCOUNTER27 = 12'hB1B,
430
- CSR_MHPMCOUNTER28 = 12'hB1C,
431
- CSR_MHPMCOUNTER29 = 12'hB1D,
432
- CSR_MHPMCOUNTER30 = 12'hB1E,
433
- CSR_MHPMCOUNTER31 = 12'hB1F,
434
- CSR_MCYCLEH = 12'hB80,
435
- CSR_MINSTRETH = 12'hB82,
436
- CSR_MHPMCOUNTER3H = 12'hB83,
437
- CSR_MHPMCOUNTER4H = 12'hB84,
438
- CSR_MHPMCOUNTER5H = 12'hB85,
439
- CSR_MHPMCOUNTER6H = 12'hB86,
440
- CSR_MHPMCOUNTER7H = 12'hB87,
441
- CSR_MHPMCOUNTER8H = 12'hB88,
442
- CSR_MHPMCOUNTER9H = 12'hB89,
443
- CSR_MHPMCOUNTER10H = 12'hB8A,
444
- CSR_MHPMCOUNTER11H = 12'hB8B,
445
- CSR_MHPMCOUNTER12H = 12'hB8C,
446
- CSR_MHPMCOUNTER13H = 12'hB8D,
447
- CSR_MHPMCOUNTER14H = 12'hB8E,
448
- CSR_MHPMCOUNTER15H = 12'hB8F,
449
- CSR_MHPMCOUNTER16H = 12'hB90,
450
- CSR_MHPMCOUNTER17H = 12'hB91,
451
- CSR_MHPMCOUNTER18H = 12'hB92,
452
- CSR_MHPMCOUNTER19H = 12'hB93,
453
- CSR_MHPMCOUNTER20H = 12'hB94,
454
- CSR_MHPMCOUNTER21H = 12'hB95,
455
- CSR_MHPMCOUNTER22H = 12'hB96,
456
- CSR_MHPMCOUNTER23H = 12'hB97,
457
- CSR_MHPMCOUNTER24H = 12'hB98,
458
- CSR_MHPMCOUNTER25H = 12'hB99,
459
- CSR_MHPMCOUNTER26H = 12'hB9A,
460
- CSR_MHPMCOUNTER27H = 12'hB9B,
461
- CSR_MHPMCOUNTER28H = 12'hB9C,
462
- CSR_MHPMCOUNTER29H = 12'hB9D,
463
- CSR_MHPMCOUNTER30H = 12'hB9E,
464
- CSR_MHPMCOUNTER31H = 12'hB9F,
465
- CSR_CPUCTRL = 12'h7C0,
466
- CSR_SECURESEED = 12'h7C1
467
- } csr_num_e;
468
- // CSR pmp-related offsets
469
- parameter logic [11:0] CSR_OFF_PMP_CFG = 12'h3A0; // pmp_cfg @ 12'h3a0 - 12'h3a3
470
- parameter logic [11:0] CSR_OFF_PMP_ADDR = 12'h3B0; // pmp_addr @ 12'h3b0 - 12'h3bf
471
- // CSR status bits
472
- parameter int unsigned CSR_MSTATUS_MIE_BIT = 3;
473
- parameter int unsigned CSR_MSTATUS_MPIE_BIT = 7;
474
- parameter int unsigned CSR_MSTATUS_MPP_BIT_LOW = 11;
475
- parameter int unsigned CSR_MSTATUS_MPP_BIT_HIGH = 12;
476
- parameter int unsigned CSR_MSTATUS_MPRV_BIT = 17;
477
- parameter int unsigned CSR_MSTATUS_TW_BIT = 21;
478
- // CSR machine ISA
479
- parameter logic [1:0] CSR_MISA_MXL = 2'd1; // M-XLEN: XLEN in M-Mode for RV32
480
- // CSR interrupt pending/enable bits
481
- parameter int unsigned CSR_MSIX_BIT = 3;
482
- parameter int unsigned CSR_MTIX_BIT = 7;
483
- parameter int unsigned CSR_MEIX_BIT = 11;
484
- parameter int unsigned CSR_MFIX_BIT_LOW = 16;
485
- parameter int unsigned CSR_MFIX_BIT_HIGH = 31;
486
- // CSR Machine Security Configuration bits
487
- parameter int unsigned CSR_MSECCFG_MML_BIT = 0;
488
- parameter int unsigned CSR_MSECCFG_MMWP_BIT = 1;
489
- parameter int unsigned CSR_MSECCFG_RLB_BIT = 2;
490
- // Machine Vendor ID - OpenHW JEDEC ID is '2 decimal (bank 13)'
491
- parameter MVENDORID_OFFSET = 7'h2; // Final byte without parity bit
492
- parameter MVENDORID_BANK = 25'hC; // Number of continuation codes
493
- // Machine Architecture ID (https://github.com/riscv/riscv-isa-manual/blob/master/marchid.md)
494
- parameter MARCHID = 32'd35;
495
- localparam logic [31:0] CSR_MVENDORID_VALUE = {MVENDORID_BANK, MVENDORID_OFFSET};
496
- localparam logic [31:0] CSR_MARCHID_VALUE = MARCHID;
497
- // Implementation ID
498
- // 0 indicates this field is not implemeted. cve2 implementors may wish to indicate an RTL/netlist
499
- // version here using their own unique encoding (e.g. 32 bits of the git hash of the implemented
500
- // commit).
501
- localparam logic [31:0] CSR_MIMPID_VALUE = 32'b0;
502
- // Machine Configuration Pointer
503
- // 0 indicates the configuration data structure does not eixst. cve2 implementors may wish to
504
- // alter this to point to their system specific configuration data structure.
505
- localparam logic [31:0] CSR_MCONFIGPTR_VALUE = 32'b0;
506
- // RVFI CSR element
507
- typedef struct packed {
508
- bit [63:0] rdata;
509
- bit [63:0] rmask;
510
- bit [63:0] wdata;
511
- bit [63:0] wmask;
512
- } rvfi_csr_elmt_t;
513
- // RVFI CSR structure
514
- typedef struct packed {
515
- rvfi_csr_elmt_t fflags;
516
- rvfi_csr_elmt_t frm;
517
- rvfi_csr_elmt_t fcsr;
518
- rvfi_csr_elmt_t ftran;
519
- rvfi_csr_elmt_t dcsr;
520
- rvfi_csr_elmt_t dpc;
521
- rvfi_csr_elmt_t dscratch0;
522
- rvfi_csr_elmt_t dscratch1;
523
- rvfi_csr_elmt_t sstatus;
524
- rvfi_csr_elmt_t sie;
525
- rvfi_csr_elmt_t sip;
526
- rvfi_csr_elmt_t stvec;
527
- rvfi_csr_elmt_t scounteren;
528
- rvfi_csr_elmt_t sscratch;
529
- rvfi_csr_elmt_t sepc;
530
- rvfi_csr_elmt_t scause;
531
- rvfi_csr_elmt_t stval;
532
- rvfi_csr_elmt_t satp;
533
- rvfi_csr_elmt_t mstatus;
534
- rvfi_csr_elmt_t mstatush;
535
- rvfi_csr_elmt_t misa;
536
- rvfi_csr_elmt_t medeleg;
537
- rvfi_csr_elmt_t mideleg;
538
- rvfi_csr_elmt_t mie;
539
- rvfi_csr_elmt_t mtvec;
540
- rvfi_csr_elmt_t mcounteren;
541
- rvfi_csr_elmt_t mscratch;
542
- rvfi_csr_elmt_t mepc;
543
- rvfi_csr_elmt_t mcause;
544
- rvfi_csr_elmt_t mtval;
545
- rvfi_csr_elmt_t mip;
546
- rvfi_csr_elmt_t menvcfg;
547
- rvfi_csr_elmt_t menvcfgh;
548
- rvfi_csr_elmt_t mvendorid;
549
- rvfi_csr_elmt_t marchid;
550
- rvfi_csr_elmt_t mhartid;
551
- rvfi_csr_elmt_t mcountinhibit;
552
- rvfi_csr_elmt_t mcycle;
553
- rvfi_csr_elmt_t mcycleh;
554
- rvfi_csr_elmt_t minstret;
555
- rvfi_csr_elmt_t minstreth;
556
- rvfi_csr_elmt_t cycle;
557
- rvfi_csr_elmt_t cycleh;
558
- rvfi_csr_elmt_t instret;
559
- rvfi_csr_elmt_t instreth;
560
- rvfi_csr_elmt_t dcache;
561
- rvfi_csr_elmt_t icache;
562
- rvfi_csr_elmt_t acc_cons;
563
- rvfi_csr_elmt_t pmpcfg0;
564
- rvfi_csr_elmt_t pmpcfg1;
565
- rvfi_csr_elmt_t pmpcfg2;
566
- rvfi_csr_elmt_t pmpcfg3;
567
- rvfi_csr_elmt_t pmpaddr0;
568
- rvfi_csr_elmt_t pmpaddr1;
569
- rvfi_csr_elmt_t pmpaddr2;
570
- rvfi_csr_elmt_t pmpaddr3;
571
- rvfi_csr_elmt_t pmpaddr4;
572
- rvfi_csr_elmt_t pmpaddr5;
573
- rvfi_csr_elmt_t pmpaddr6;
574
- rvfi_csr_elmt_t pmpaddr7;
575
- rvfi_csr_elmt_t pmpaddr8;
576
- rvfi_csr_elmt_t pmpaddr9;
577
- rvfi_csr_elmt_t pmpaddr10;
578
- rvfi_csr_elmt_t pmpaddr11;
579
- rvfi_csr_elmt_t pmpaddr12;
580
- rvfi_csr_elmt_t pmpaddr13;
581
- rvfi_csr_elmt_t pmpaddr14;
582
- rvfi_csr_elmt_t pmpaddr15;
583
- } rvfi_csr_t;
584
- // CV-X-IF
585
- parameter int unsigned X_NUM_RS = 3;
586
- parameter int unsigned X_ID_WIDTH = 4;
587
- parameter int unsigned X_RFR_WIDTH = 32;
588
- parameter int unsigned X_RFW_WIDTH = 32;
589
- parameter int unsigned X_HARTID_WIDTH = 32;
590
- parameter int unsigned X_DUAL_READ = 0;
591
- parameter int unsigned X_DUAL_WRITE = 0;
592
- parameter int unsigned X_INSTR_INFLIGHT = 2**X_ID_WIDTH;
593
- typedef logic [X_NUM_RS+X_DUAL_READ-1:0] readregflags_t;
594
- typedef logic [X_DUAL_WRITE:0] writeregflags_t;
595
- typedef logic [X_ID_WIDTH-1:0] id_t;
596
- typedef logic [X_HARTID_WIDTH-1:0] hartid_t;
597
- // Issue Interface
598
- typedef struct packed {
599
- logic [31:0] instr;
600
- hartid_t hartid;
601
- id_t id;
602
- } x_issue_req_t;
603
- typedef struct packed {
604
- logic accept;
605
- writeregflags_t writeback;
606
- readregflags_t register_read;
607
- } x_issue_resp_t;
608
- // Register Interface
609
- typedef struct packed {
610
- hartid_t hartid;
611
- id_t id;
612
- logic [X_NUM_RS-1:0][X_RFR_WIDTH-1:0] rs;
613
- readregflags_t rs_valid;
614
- } x_register_t;
615
- // Commit Interface
616
- typedef struct packed {
617
- hartid_t hartid;
618
- id_t id;
619
- logic commit_kill;
620
- } x_commit_t;
621
- // Result Interface
622
- typedef struct packed {
623
- hartid_t hartid;
624
- id_t id;
625
- logic [X_RFW_WIDTH-1:0] data;
626
- logic [4:0] rd;
627
- writeregflags_t we;
628
- } x_result_t;
629
- endpackage
630
- // Copyright (c) 2025 Eclipse Foundation
631
- // Copyright lowRISC contributors.
632
- // Copyright 2018 ETH Zurich and University of Bologna, see also CREDITS.md.
633
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
634
- // SPDX-License-Identifier: Apache-2.0
635
- /**
636
- * Fetch Fifo for 32 bit memory interface
637
- *
638
- * input port: send address and data to the FIFO
639
- * clear_i clears the FIFO for the following cycle, including any new request
640
- */
641
- // Copyright lowRISC contributors.
642
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
643
- // SPDX-License-Identifier: Apache-2.0
644
- // Macros and helper code for using assertions.
645
- // - Provides default clk and rst options to simplify code
646
- // - Provides boiler plate template for common assertions
647
- ///////////////////
648
- // Helper macros //
649
- ///////////////////
650
- // Default clk and reset signals used by assertion macros below.
651
- // Converts an arbitrary block of code into a Verilog string
652
- // ASSERT_ERROR logs an error message with either `uvm_error or with $error.
653
- //
654
- // This somewhat duplicates `DV_ERROR macro defined in hw/dv/sv/dv_utils/dv_macros.svh. The reason
655
- // for redefining it here is to avoid creating a dependency.
656
- // This macro is suitable for conditionally triggering lint errors, e.g., if a Sec parameter takes
657
- // on a non-default value. This may be required for pre-silicon/FPGA evaluation but we don't want
658
- // to allow this for tapeout.
659
- // The basic helper macros are actually defined in "implementation headers". The macros should do
660
- // the same thing in each case (except for the dummy flavour), but in a way that the respective
661
- // tools support.
662
- //
663
- // If the tool supports assertions in some form, we also define INC_ASSERT (which can be used to
664
- // hide signal definitions that are only used for assertions).
665
- //
666
- // The list of basic macros supported is:
667
- //
668
- // ASSERT_I: Immediate assertion. Note that immediate assertions are sensitive to simulation
669
- // glitches.
670
- //
671
- // ASSERT_INIT: Assertion in initial block. Can be used for things like parameter checking.
672
- //
673
- // ASSERT_INIT_NET: Assertion in initial block. Can be used for initial value of a net.
674
- //
675
- // ASSERT_FINAL: Assertion in final block. Can be used for things like queues being empty at end of
676
- // sim, all credits returned at end of sim, state machines in idle at end of sim.
677
- //
678
- // ASSERT: Assert a concurrent property directly. It can be called as a module (or
679
- // interface) body item.
680
- //
681
- // Note: We use (__rst !== '0) in the disable iff statements instead of (__rst ==
682
- // '1). This properly disables the assertion in cases when reset is X at the
683
- // beginning of a simulation. For that case, (reset == '1) does not disable the
684
- // assertion.
685
- //
686
- // ASSERT_NEVER: Assert a concurrent property NEVER happens
687
- //
688
- // ASSERT_KNOWN: Assert that signal has a known value (each bit is either '0' or '1') after reset.
689
- // It can be called as a module (or interface) body item.
690
- //
691
- // COVER: Cover a concurrent property
692
- //
693
- // ASSUME: Assume a concurrent property
694
- //
695
- // ASSUME_I: Assume an immediate property
696
- // Copyright lowRISC contributors.
697
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
698
- // SPDX-License-Identifier: Apache-2.0
699
- // Macro bodies included by prim_assert.sv for tools that don't support assertions. See
700
- // prim_assert.sv for documentation for each of the macros.
701
- //////////////////////////////
702
- // Complex assertion macros //
703
- //////////////////////////////
704
- // Assert that signal is an active-high pulse with pulse length of 1 clock cycle
705
- // Assert that a property is true only when an enable signal is set. It can be called as a module
706
- // (or interface) body item.
707
- // Assert that signal has a known value (each bit is either '0' or '1') after reset if enable is
708
- // set. It can be called as a module (or interface) body item.
709
- //////////////////////////////////
710
- // For formal verification only //
711
- //////////////////////////////////
712
- // Note that the existing set of ASSERT macros specified above shall be used for FPV,
713
- // thereby ensuring that the assertions are evaluated during DV simulations as well.
714
- // ASSUME_FPV
715
- // Assume a concurrent property during formal verification only.
716
- // ASSUME_I_FPV
717
- // Assume a concurrent property during formal verification only.
718
- // COVER_FPV
719
- // Cover a concurrent property during formal verification
720
- // Copyright lowRISC contributors.
721
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
722
- // SPDX-License-Identifier: Apache-2.0
723
- // // Macros and helper code for security countermeasures.
724
- // Helper macros
725
- // macros for security countermeasures
726
- // PRIM_ASSERT_SEC_CM_SVH
727
- // PRIM_ASSERT_SV
728
- module cve2_fetch_fifo #(
729
- parameter int unsigned NUM_REQS = 2
730
- ) (
731
- input logic clk_i,
732
- input logic rst_ni,
733
- // control signals
734
- input logic clear_i, // clears the contents of the FIFO
735
- output logic [NUM_REQS-1:0] busy_o,
736
- // input port
737
- input logic in_valid_i,
738
- input logic [31:0] in_addr_i,
739
- input logic [31:0] in_rdata_i,
740
- input logic in_err_i,
741
- // output port
742
- output logic out_valid_o,
743
- input logic out_ready_i,
744
- output logic [31:0] out_addr_o,
745
- output logic [31:0] out_rdata_o,
746
- output logic out_err_o,
747
- output logic out_err_plus2_o
748
- );
749
- localparam int unsigned DEPTH = NUM_REQS+1;
750
- // index 0 is used for output
751
- logic [DEPTH-1:0] [31:0] rdata_d, rdata_q;
752
- logic [DEPTH-1:0] err_d, err_q;
753
- logic [DEPTH-1:0] valid_d, valid_q;
754
- logic [DEPTH-1:0] lowest_free_entry;
755
- logic [DEPTH-1:0] valid_pushed, valid_popped;
756
- logic [DEPTH-1:0] entry_en;
757
- logic pop_fifo;
758
- logic [31:0] rdata, rdata_unaligned;
759
- logic err, err_unaligned, err_plus2;
760
- logic valid, valid_unaligned;
761
- logic aligned_is_compressed, unaligned_is_compressed;
762
- logic addr_incr_two;
763
- logic [31:1] instr_addr_next;
764
- logic [31:1] instr_addr_d, instr_addr_q;
765
- logic instr_addr_en;
766
- logic unused_addr_in;
767
- /////////////////
768
- // Output port //
769
- /////////////////
770
- assign rdata = valid_q[0] ? rdata_q[0] : in_rdata_i;
771
- assign err = valid_q[0] ? err_q[0] : in_err_i;
772
- assign valid = valid_q[0] | in_valid_i;
773
- // The FIFO contains word aligned memory fetches, but the instructions contained in each entry
774
- // might be half-word aligned (due to compressed instructions)
775
- // e.g.
776
- // | 31 16 | 15 0 |
777
- // FIFO entry 0 | Instr 1 [15:0] | Instr 0 [15:0] |
778
- // FIFO entry 1 | Instr 2 [15:0] | Instr 1 [31:16] |
779
- //
780
- // The FIFO also has a direct bypass path, so a complete instruction might be made up of data
781
- // from the FIFO and new incoming data.
782
- //
783
- // Construct the output data for an unaligned instruction
784
- assign rdata_unaligned = valid_q[1] ? {rdata_q[1][15:0], rdata[31:16]} :
785
- {in_rdata_i[15:0], rdata[31:16]};
786
- // If entry[1] is valid, an error can come from entry[0] or entry[1], unless the
787
- // instruction in entry[0] is compressed (entry[1] is a new instruction)
788
- // If entry[1] is not valid, and entry[0] is, an error can come from entry[0] or the incoming
789
- // data, unless the instruction in entry[0] is compressed
790
- // If entry[0] is not valid, the error must come from the incoming data
791
- assign err_unaligned = valid_q[1] ? ((err_q[1] & ~unaligned_is_compressed) | err_q[0]) :
792
- ((valid_q[0] & err_q[0]) |
793
- (in_err_i & (~valid_q[0] | ~unaligned_is_compressed)));
794
- // Record when an error is caused by the second half of an unaligned 32bit instruction.
795
- // Only needs to be correct when unaligned and if err_unaligned is set
796
- assign err_plus2 = valid_q[1] ? (err_q[1] & ~err_q[0]) :
797
- (in_err_i & valid_q[0] & ~err_q[0]);
798
- // An uncompressed unaligned instruction is only valid if both parts are available
799
- assign valid_unaligned = valid_q[1] ? 1'b1 :
800
- (valid_q[0] & in_valid_i);
801
- // If there is an error, rdata is unknown
802
- assign unaligned_is_compressed = (rdata[17:16] != 2'b11) & ~err;
803
- assign aligned_is_compressed = (rdata[ 1: 0] != 2'b11) & ~err;
804
- ////////////////////////////////////////
805
- // Instruction aligner (if unaligned) //
806
- ////////////////////////////////////////
807
- always_comb begin
808
- if (out_addr_o[1]) begin
809
- // unaligned case
810
- out_rdata_o = rdata_unaligned;
811
- out_err_o = err_unaligned;
812
- out_err_plus2_o = err_plus2;
813
- if (unaligned_is_compressed) begin
814
- out_valid_o = valid;
815
- end else begin
816
- out_valid_o = valid_unaligned;
817
- end
818
- end else begin
819
- // aligned case
820
- out_rdata_o = rdata;
821
- out_err_o = err;
822
- out_err_plus2_o = 1'b0;
823
- out_valid_o = valid;
824
- end
825
- end
826
- /////////////////////////
827
- // Instruction address //
828
- /////////////////////////
829
- // Update the address on branches and every time an instruction is driven
830
- assign instr_addr_en = clear_i | (out_ready_i & out_valid_o);
831
- // Increment the address by two every time a compressed instruction is popped
832
- assign addr_incr_two = instr_addr_q[1] ? unaligned_is_compressed :
833
- aligned_is_compressed;
834
- assign instr_addr_next = (instr_addr_q[31:1] +
835
- // Increment address by 4 or 2
836
- {29'd0,~addr_incr_two,addr_incr_two});
837
- assign instr_addr_d = clear_i ? in_addr_i[31:1] :
838
- instr_addr_next;
839
- always_ff @(posedge clk_i or negedge rst_ni) begin
840
- if (!rst_ni) begin
841
- instr_addr_q <= '0;
842
- end else if (instr_addr_en) begin
843
- instr_addr_q <= instr_addr_d;
844
- end
845
- end
846
- // Output PC of current instruction
847
- assign out_addr_o = {instr_addr_q, 1'b0};
848
- // The LSB of the address is unused, since all addresses are halfword aligned
849
- assign unused_addr_in = in_addr_i[0];
850
- /////////////////
851
- // FIFO status //
852
- /////////////////
853
- // Indicate the fill level of fifo-entries. This is used to determine when a new request can be
854
- // made on the bus. The prefetch buffer only needs to know about the upper entries which overlap
855
- // with NUM_REQS.
856
- assign busy_o = valid_q[DEPTH-1:DEPTH-NUM_REQS];
857
- /////////////////////
858
- // FIFO management //
859
- /////////////////////
860
- // Since an entry can contain unaligned instructions, popping an entry can leave the entry valid
861
- assign pop_fifo = out_ready_i & out_valid_o & (~aligned_is_compressed | out_addr_o[1]);
862
- for (genvar i = 0; i < (DEPTH - 1); i++) begin : g_fifo_next
863
- // Calculate lowest free entry (write pointer)
864
- if (i == 0) begin : g_ent0
865
- assign lowest_free_entry[i] = ~valid_q[i];
866
- end else begin : g_ent_others
867
- assign lowest_free_entry[i] = ~valid_q[i] & valid_q[i-1];
868
- end
869
- // An entry is set when an incoming request chooses the lowest available entry
870
- assign valid_pushed[i] = (in_valid_i & lowest_free_entry[i]) |
871
- valid_q[i];
872
- // Popping the FIFO shifts all entries down
873
- assign valid_popped[i] = pop_fifo ? valid_pushed[i+1] : valid_pushed[i];
874
- // All entries are wiped out on a clear
875
- assign valid_d[i] = valid_popped[i] & ~clear_i;
876
- // data flops are enabled if there is new data to shift into it, or
877
- assign entry_en[i] = (valid_pushed[i+1] & pop_fifo) |
878
- // a new request is incoming and this is the lowest free entry
879
- (in_valid_i & lowest_free_entry[i] & ~pop_fifo);
880
- // take the next entry or the incoming data
881
- assign rdata_d[i] = valid_q[i+1] ? rdata_q[i+1] : in_rdata_i;
882
- assign err_d [i] = valid_q[i+1] ? err_q [i+1] : in_err_i;
883
- end
884
- // The top entry is similar but with simpler muxing
885
- assign lowest_free_entry[DEPTH-1] = ~valid_q[DEPTH-1] & valid_q[DEPTH-2];
886
- assign valid_pushed [DEPTH-1] = valid_q[DEPTH-1] | (in_valid_i & lowest_free_entry[DEPTH-1]);
887
- assign valid_popped [DEPTH-1] = pop_fifo ? 1'b0 : valid_pushed[DEPTH-1];
888
- assign valid_d [DEPTH-1] = valid_popped[DEPTH-1] & ~clear_i;
889
- assign entry_en[DEPTH-1] = in_valid_i & lowest_free_entry[DEPTH-1];
890
- assign rdata_d [DEPTH-1] = in_rdata_i;
891
- assign err_d [DEPTH-1] = in_err_i;
892
- ////////////////////
893
- // FIFO registers //
894
- ////////////////////
895
- always_ff @(posedge clk_i or negedge rst_ni) begin
896
- if (!rst_ni) begin
897
- valid_q <= '0;
898
- end else begin
899
- valid_q <= valid_d;
900
- end
901
- end
902
- for (genvar i = 0; i < DEPTH; i++) begin : g_fifo_regs
903
- always_ff @(posedge clk_i or negedge rst_ni) begin
904
- if (!rst_ni) begin
905
- rdata_q[i] <= '0;
906
- err_q[i] <= '0;
907
- end else if (entry_en[i]) begin
908
- rdata_q[i] <= rdata_d[i];
909
- err_q[i] <= err_d[i];
910
- end
911
- end
912
- end
913
- ////////////////
914
- // Assertions //
915
- ////////////////
916
- // Must not push and pop simultaneously when FIFO full.
917
- // Must not push to FIFO when full.
918
- endmodule
919
- // Copyright (c) 2025 Eclipse Foundation
920
- // Copyright lowRISC contributors.
921
- // Copyright 2018 ETH Zurich and University of Bologna, see also CREDITS.md.
922
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
923
- // SPDX-License-Identifier: Apache-2.0
924
- /**
925
- * Prefetcher Buffer for 32 bit memory interface
926
- *
927
- * Prefetch Buffer that caches instructions. This cuts overly long critical
928
- * paths to the instruction cache.
929
- */
930
- module cve2_prefetch_buffer #(
931
- ) (
932
- input logic clk_i,
933
- input logic rst_ni,
934
- input logic req_i,
935
- input logic branch_i,
936
- input logic [31:0] addr_i,
937
- input logic ready_i,
938
- output logic valid_o,
939
- output logic [31:0] rdata_o,
940
- output logic [31:0] addr_o,
941
- output logic err_o,
942
- output logic err_plus2_o,
943
- // goes to instruction memory / instruction cache
944
- output logic instr_req_o,
945
- input logic instr_gnt_i,
946
- output logic [31:0] instr_addr_o,
947
- input logic [31:0] instr_rdata_i,
948
- input logic instr_err_i,
949
- input logic instr_rvalid_i,
950
- // Prefetch Buffer Status
951
- output logic busy_o
952
- );
953
- localparam int unsigned NUM_REQS = 2;
954
- logic valid_new_req, valid_req;
955
- logic valid_req_d, valid_req_q;
956
- logic discard_req_d, discard_req_q;
957
- logic [NUM_REQS-1:0] rdata_outstanding_n, rdata_outstanding_s, rdata_outstanding_q;
958
- logic [NUM_REQS-1:0] branch_discard_n, branch_discard_s, branch_discard_q;
959
- logic [NUM_REQS-1:0] rdata_outstanding_rev;
960
- logic [31:0] stored_addr_d, stored_addr_q;
961
- logic stored_addr_en;
962
- logic [31:0] fetch_addr_d, fetch_addr_q;
963
- logic fetch_addr_en;
964
- logic [31:0] instr_addr, instr_addr_w_aligned;
965
- logic fifo_valid;
966
- logic [31:0] fifo_addr;
967
- logic fifo_ready;
968
- logic fifo_clear;
969
- logic [NUM_REQS-1:0] fifo_busy;
970
- logic valid_raw;
971
- ////////////////////////////
972
- // Prefetch buffer status //
973
- ////////////////////////////
974
- assign busy_o = (|rdata_outstanding_q) | instr_req_o;
975
- //////////////////////////////////////////////
976
- // Fetch fifo - consumes addresses and data //
977
- //////////////////////////////////////////////
978
- // A branch will invalidate any previously fetched instructions.
979
- // Note that the FENCE.I instruction relies on this flushing behaviour on branch. If it is
980
- // altered the FENCE.I implementation may require changes.
981
- assign fifo_clear = branch_i;
982
- // Reversed version of rdata_outstanding_q which can be overlaid with fifo fill state
983
- for (genvar i = 0; i < NUM_REQS; i++) begin : gen_rd_rev
984
- assign rdata_outstanding_rev[i] = rdata_outstanding_q[NUM_REQS-1-i];
985
- end
986
- // The fifo is ready to accept a new request if it is not full - including space reserved for
987
- // requests already outstanding.
988
- // Overlay the fifo fill state with the outstanding requests to see if there is space.
989
- assign fifo_ready = ~&(fifo_busy | rdata_outstanding_rev);
990
- cve2_fetch_fifo #(
991
- .NUM_REQS (NUM_REQS)
992
- ) fifo_i (
993
- .clk_i ( clk_i ),
994
- .rst_ni ( rst_ni ),
995
- .clear_i ( fifo_clear ),
996
- .busy_o ( fifo_busy ),
997
- .in_valid_i ( fifo_valid ),
998
- .in_addr_i ( fifo_addr ),
999
- .in_rdata_i ( instr_rdata_i ),
1000
- .in_err_i ( instr_err_i ),
1001
- .out_valid_o ( valid_raw ),
1002
- .out_ready_i ( ready_i ),
1003
- .out_rdata_o ( rdata_o ),
1004
- .out_addr_o ( addr_o ),
1005
- .out_err_o ( err_o ),
1006
- .out_err_plus2_o ( err_plus2_o )
1007
- );
1008
- //////////////
1009
- // Requests //
1010
- //////////////
1011
- // Make a new request any time there is space in the FIFO, and space in the request queue
1012
- assign valid_new_req = req_i & (fifo_ready | branch_i) &
1013
- ~rdata_outstanding_q[NUM_REQS-1];
1014
- assign valid_req = valid_req_q | valid_new_req;
1015
- // Hold the request stable for requests that didn't get granted
1016
- assign valid_req_d = valid_req & ~instr_gnt_i;
1017
- // Record whether an outstanding bus request is cancelled by a branch
1018
- assign discard_req_d = valid_req_q & (branch_i | discard_req_q);
1019
- ////////////////
1020
- // Fetch addr //
1021
- ////////////////
1022
- // Two addresses are tracked in the prefetch buffer:
1023
- // 1. stored_addr_q - This is the address issued on the bus. It stays stable until
1024
- // the request is granted.
1025
- // 2. fetch_addr_q - This is our next address to fetch from. It is updated on branches to
1026
- // capture the new address, and then for each new request issued.
1027
- // A third address is tracked in the fetch FIFO itself:
1028
- // 3. instr_addr_q - This is the address at the head of the FIFO, efectively our oldest fetched
1029
- // address. This address is updated on branches, and does its own increment
1030
- // each time the FIFO is popped.
1031
- // 1. stored_addr_q
1032
- // Only update stored_addr_q for new ungranted requests
1033
- assign stored_addr_en = valid_new_req & ~valid_req_q & ~instr_gnt_i;
1034
- // Store whatever address was issued on the bus
1035
- assign stored_addr_d = instr_addr;
1036
- // CPU resets with a branch, so no need to reset these addresses
1037
- always_ff @(posedge clk_i or negedge rst_ni) begin
1038
- if (!rst_ni) begin
1039
- stored_addr_q <= '0;
1040
- end else if (stored_addr_en) begin
1041
- stored_addr_q <= stored_addr_d;
1042
- end
1043
- end
1044
- // 2. fetch_addr_q
1045
- // Update on a branch or as soon as a request is issued
1046
- assign fetch_addr_en = branch_i | (valid_new_req & ~valid_req_q);
1047
- assign fetch_addr_d = (branch_i ? addr_i :
1048
- {fetch_addr_q[31:2], 2'b00}) +
1049
- // Current address + 4
1050
- {{29{1'b0}},(valid_new_req & ~valid_req_q),2'b00};
1051
- always_ff @(posedge clk_i or negedge rst_ni) begin
1052
- if (!rst_ni) begin
1053
- fetch_addr_q <= '0;
1054
- end else if (fetch_addr_en) begin
1055
- fetch_addr_q <= fetch_addr_d;
1056
- end
1057
- end
1058
- // Address mux
1059
- assign instr_addr = valid_req_q ? stored_addr_q :
1060
- branch_i ? addr_i :
1061
- fetch_addr_q;
1062
- assign instr_addr_w_aligned = {instr_addr[31:2], 2'b00};
1063
- ///////////////////////////////
1064
- // Request outstanding queue //
1065
- ///////////////////////////////
1066
- for (genvar i = 0; i < NUM_REQS; i++) begin : g_outstanding_reqs
1067
- // Request 0 (always the oldest outstanding request)
1068
- if (i == 0) begin : g_req0
1069
- // A request becomes outstanding once granted, and is cleared once the rvalid is received.
1070
- // Outstanding requests shift down the queue towards entry 0.
1071
- assign rdata_outstanding_n[i] = (valid_req & instr_gnt_i) |
1072
- rdata_outstanding_q[i];
1073
- // If a branch is received at any point while a request is outstanding, it must be tracked
1074
- // to ensure we discard the data once received
1075
- assign branch_discard_n[i] = (valid_req & instr_gnt_i & discard_req_d) |
1076
- (branch_i & rdata_outstanding_q[i]) |
1077
- branch_discard_q[i];
1078
- end else begin : g_reqtop
1079
- // Entries > 0 consider the FIFO fill state to calculate their next state (by checking
1080
- // whether the previous entry is valid)
1081
- assign rdata_outstanding_n[i] = (valid_req & instr_gnt_i &
1082
- rdata_outstanding_q[i-1]) |
1083
- rdata_outstanding_q[i];
1084
- assign branch_discard_n[i] = (valid_req & instr_gnt_i & discard_req_d &
1085
- rdata_outstanding_q[i-1]) |
1086
- (branch_i & rdata_outstanding_q[i]) |
1087
- branch_discard_q[i];
1088
- end
1089
- end
1090
- // Shift the entries down on each instr_rvalid_i
1091
- assign rdata_outstanding_s = instr_rvalid_i ? {1'b0,rdata_outstanding_n[NUM_REQS-1:1]} :
1092
- rdata_outstanding_n;
1093
- assign branch_discard_s = instr_rvalid_i ? {1'b0,branch_discard_n[NUM_REQS-1:1]} :
1094
- branch_discard_n;
1095
- // Push a new entry to the FIFO once complete (and not cancelled by a branch)
1096
- assign fifo_valid = instr_rvalid_i & ~branch_discard_q[0];
1097
- assign fifo_addr = addr_i;
1098
- ///////////////
1099
- // Registers //
1100
- ///////////////
1101
- always_ff @(posedge clk_i or negedge rst_ni) begin
1102
- if (!rst_ni) begin
1103
- valid_req_q <= 1'b0;
1104
- discard_req_q <= 1'b0;
1105
- rdata_outstanding_q <= 'b0;
1106
- branch_discard_q <= 'b0;
1107
- end else begin
1108
- valid_req_q <= valid_req_d;
1109
- discard_req_q <= discard_req_d;
1110
- rdata_outstanding_q <= rdata_outstanding_s;
1111
- branch_discard_q <= branch_discard_s;
1112
- end
1113
- end
1114
- /////////////
1115
- // Outputs //
1116
- /////////////
1117
- assign instr_req_o = valid_req;
1118
- assign instr_addr_o = instr_addr_w_aligned;
1119
- assign valid_o = valid_raw;
1120
- endmodule
1121
- // Copyright (c) 2025 Eclipse Foundation
1122
- // Copyright lowRISC contributors.
1123
- // Copyright 2018 ETH Zurich and University of Bologna, see also CREDITS.md.
1124
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
1125
- // SPDX-License-Identifier: Apache-2.0
1126
- /**
1127
- * Compressed instruction decoder
1128
- *
1129
- * Decodes RISC-V compressed instructions into their RV32 equivalent.
1130
- * This module is fully combinatorial, clock and reset are used for
1131
- * assertions only.
1132
- */
1133
- // Copyright lowRISC contributors.
1134
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
1135
- // SPDX-License-Identifier: Apache-2.0
1136
- // Macros and helper code for using assertions.
1137
- // - Provides default clk and rst options to simplify code
1138
- // - Provides boiler plate template for common assertions
1139
- // PRIM_ASSERT_SV
1140
- module cve2_compressed_decoder (
1141
- input logic clk_i,
1142
- input logic rst_ni,
1143
- input logic valid_i,
1144
- input logic [31:0] instr_i,
1145
- output logic [31:0] instr_o,
1146
- output logic is_compressed_o,
1147
- output logic illegal_instr_o
1148
- );
1149
- import cve2_pkg::*;
1150
- // valid_i indicates if instr_i is valid and is used for assertions only.
1151
- // The following signal is used to avoid possible lint errors.
1152
- logic unused_valid;
1153
- assign unused_valid = valid_i;
1154
- ////////////////////////
1155
- // Compressed decoder //
1156
- ////////////////////////
1157
- always_comb begin
1158
- // By default, forward incoming instruction, mark it as legal.
1159
- instr_o = instr_i;
1160
- illegal_instr_o = 1'b0;
1161
- // Check if incoming instruction is compressed.
1162
- unique case (instr_i[1:0])
1163
- // C0
1164
- 2'b00: begin
1165
- unique case (instr_i[15:13])
1166
- 3'b000: begin
1167
- // c.addi4spn -> addi rd', x2, imm
1168
- instr_o = {2'b0, instr_i[10:7], instr_i[12:11], instr_i[5],
1169
- instr_i[6], 2'b00, 5'h02, 3'b000, 2'b01, instr_i[4:2], {OPCODE_OP_IMM}};
1170
- if (instr_i[12:5] == 8'b0) illegal_instr_o = 1'b1;
1171
- end
1172
- 3'b010: begin
1173
- // c.lw -> lw rd', imm(rs1')
1174
- instr_o = {5'b0, instr_i[5], instr_i[12:10], instr_i[6],
1175
- 2'b00, 2'b01, instr_i[9:7], 3'b010, 2'b01, instr_i[4:2], {OPCODE_LOAD}};
1176
- end
1177
- 3'b110: begin
1178
- // c.sw -> sw rs2', imm(rs1')
1179
- instr_o = {5'b0, instr_i[5], instr_i[12], 2'b01, instr_i[4:2],
1180
- 2'b01, instr_i[9:7], 3'b010, instr_i[11:10], instr_i[6],
1181
- 2'b00, {OPCODE_STORE}};
1182
- end
1183
- 3'b001,
1184
- 3'b011,
1185
- 3'b100,
1186
- 3'b101,
1187
- 3'b111: begin
1188
- illegal_instr_o = 1'b1;
1189
- end
1190
- default: begin
1191
- illegal_instr_o = 1'b1;
1192
- end
1193
- endcase
1194
- end
1195
- // C1
1196
- //
1197
- // Register address checks for RV32E are performed in the regular instruction decoder.
1198
- // If this check fails, an illegal instruction exception is triggered and the controller
1199
- // writes the actual faulting instruction to mtval.
1200
- 2'b01: begin
1201
- unique case (instr_i[15:13])
1202
- 3'b000: begin
1203
- // c.addi -> addi rd, rd, nzimm
1204
- // c.nop
1205
- instr_o = {{6 {instr_i[12]}}, instr_i[12], instr_i[6:2],
1206
- instr_i[11:7], 3'b0, instr_i[11:7], {OPCODE_OP_IMM}};
1207
- end
1208
- 3'b001, 3'b101: begin
1209
- // 001: c.jal -> jal x1, imm
1210
- // 101: c.j -> jal x0, imm
1211
- instr_o = {instr_i[12], instr_i[8], instr_i[10:9], instr_i[6],
1212
- instr_i[7], instr_i[2], instr_i[11], instr_i[5:3],
1213
- {9 {instr_i[12]}}, 4'b0, ~instr_i[15], {OPCODE_JAL}};
1214
- end
1215
- 3'b010: begin
1216
- // c.li -> addi rd, x0, nzimm
1217
- // (c.li hints are translated into an addi hint)
1218
- instr_o = {{6 {instr_i[12]}}, instr_i[12], instr_i[6:2], 5'b0,
1219
- 3'b0, instr_i[11:7], {OPCODE_OP_IMM}};
1220
- end
1221
- 3'b011: begin
1222
- // c.lui -> lui rd, imm
1223
- // (c.lui hints are translated into a lui hint)
1224
- instr_o = {{15 {instr_i[12]}}, instr_i[6:2], instr_i[11:7], {OPCODE_LUI}};
1225
- if (instr_i[11:7] == 5'h02) begin
1226
- // c.addi16sp -> addi x2, x2, nzimm
1227
- instr_o = {{3 {instr_i[12]}}, instr_i[4:3], instr_i[5], instr_i[2],
1228
- instr_i[6], 4'b0, 5'h02, 3'b000, 5'h02, {OPCODE_OP_IMM}};
1229
- end
1230
- if ({instr_i[12], instr_i[6:2]} == 6'b0) illegal_instr_o = 1'b1;
1231
- end
1232
- 3'b100: begin
1233
- unique case (instr_i[11:10])
1234
- 2'b00,
1235
- 2'b01: begin
1236
- // 00: c.srli -> srli rd, rd, shamt
1237
- // 01: c.srai -> srai rd, rd, shamt
1238
- // (c.srli/c.srai hints are translated into a srli/srai hint)
1239
- instr_o = {1'b0, instr_i[10], 5'b0, instr_i[6:2], 2'b01, instr_i[9:7],
1240
- 3'b101, 2'b01, instr_i[9:7], {OPCODE_OP_IMM}};
1241
- if (instr_i[12] == 1'b1) illegal_instr_o = 1'b1;
1242
- end
1243
- 2'b10: begin
1244
- // c.andi -> andi rd, rd, imm
1245
- instr_o = {{6 {instr_i[12]}}, instr_i[12], instr_i[6:2], 2'b01, instr_i[9:7],
1246
- 3'b111, 2'b01, instr_i[9:7], {OPCODE_OP_IMM}};
1247
- end
1248
- 2'b11: begin
1249
- unique case ({instr_i[12], instr_i[6:5]})
1250
- 3'b000: begin
1251
- // c.sub -> sub rd', rd', rs2'
1252
- instr_o = {2'b01, 5'b0, 2'b01, instr_i[4:2], 2'b01, instr_i[9:7],
1253
- 3'b000, 2'b01, instr_i[9:7], {OPCODE_OP}};
1254
- end
1255
- 3'b001: begin
1256
- // c.xor -> xor rd', rd', rs2'
1257
- instr_o = {7'b0, 2'b01, instr_i[4:2], 2'b01, instr_i[9:7], 3'b100,
1258
- 2'b01, instr_i[9:7], {OPCODE_OP}};
1259
- end
1260
- 3'b010: begin
1261
- // c.or -> or rd', rd', rs2'
1262
- instr_o = {7'b0, 2'b01, instr_i[4:2], 2'b01, instr_i[9:7], 3'b110,
1263
- 2'b01, instr_i[9:7], {OPCODE_OP}};
1264
- end
1265
- 3'b011: begin
1266
- // c.and -> and rd', rd', rs2'
1267
- instr_o = {7'b0, 2'b01, instr_i[4:2], 2'b01, instr_i[9:7], 3'b111,
1268
- 2'b01, instr_i[9:7], {OPCODE_OP}};
1269
- end
1270
- 3'b100,
1271
- 3'b101,
1272
- 3'b110,
1273
- 3'b111: begin
1274
- // 100: c.subw
1275
- // 101: c.addw
1276
- illegal_instr_o = 1'b1;
1277
- end
1278
- default: begin
1279
- illegal_instr_o = 1'b1;
1280
- end
1281
- endcase
1282
- end
1283
- default: begin
1284
- illegal_instr_o = 1'b1;
1285
- end
1286
- endcase
1287
- end
1288
- 3'b110, 3'b111: begin
1289
- // 0: c.beqz -> beq rs1', x0, imm
1290
- // 1: c.bnez -> bne rs1', x0, imm
1291
- instr_o = {{4 {instr_i[12]}}, instr_i[6:5], instr_i[2], 5'b0, 2'b01,
1292
- instr_i[9:7], 2'b00, instr_i[13], instr_i[11:10], instr_i[4:3],
1293
- instr_i[12], {OPCODE_BRANCH}};
1294
- end
1295
- default: begin
1296
- illegal_instr_o = 1'b1;
1297
- end
1298
- endcase
1299
- end
1300
- // C2
1301
- //
1302
- // Register address checks for RV32E are performed in the regular instruction decoder.
1303
- // If this check fails, an illegal instruction exception is triggered and the controller
1304
- // writes the actual faulting instruction to mtval.
1305
- 2'b10: begin
1306
- unique case (instr_i[15:13])
1307
- 3'b000: begin
1308
- // c.slli -> slli rd, rd, shamt
1309
- // (c.ssli hints are translated into a slli hint)
1310
- instr_o = {7'b0, instr_i[6:2], instr_i[11:7], 3'b001, instr_i[11:7], {OPCODE_OP_IMM}};
1311
- if (instr_i[12] == 1'b1) illegal_instr_o = 1'b1; // reserved for custom extensions
1312
- end
1313
- 3'b010: begin
1314
- // c.lwsp -> lw rd, imm(x2)
1315
- instr_o = {4'b0, instr_i[3:2], instr_i[12], instr_i[6:4], 2'b00, 5'h02,
1316
- 3'b010, instr_i[11:7], OPCODE_LOAD};
1317
- if (instr_i[11:7] == 5'b0) illegal_instr_o = 1'b1;
1318
- end
1319
- 3'b100: begin
1320
- if (instr_i[12] == 1'b0) begin
1321
- if (instr_i[6:2] != 5'b0) begin
1322
- // c.mv -> add rd/rs1, x0, rs2
1323
- // (c.mv hints are translated into an add hint)
1324
- instr_o = {7'b0, instr_i[6:2], 5'b0, 3'b0, instr_i[11:7], {OPCODE_OP}};
1325
- end else begin
1326
- // c.jr -> jalr x0, rd/rs1, 0
1327
- instr_o = {12'b0, instr_i[11:7], 3'b0, 5'b0, {OPCODE_JALR}};
1328
- if (instr_i[11:7] == 5'b0) illegal_instr_o = 1'b1;
1329
- end
1330
- end else begin
1331
- if (instr_i[6:2] != 5'b0) begin
1332
- // c.add -> add rd, rd, rs2
1333
- // (c.add hints are translated into an add hint)
1334
- instr_o = {7'b0, instr_i[6:2], instr_i[11:7], 3'b0, instr_i[11:7], {OPCODE_OP}};
1335
- end else begin
1336
- if (instr_i[11:7] == 5'b0) begin
1337
- // c.ebreak -> ebreak
1338
- instr_o = {32'h00_10_00_73};
1339
- end else begin
1340
- // c.jalr -> jalr x1, rs1, 0
1341
- instr_o = {12'b0, instr_i[11:7], 3'b000, 5'b00001, {OPCODE_JALR}};
1342
- end
1343
- end
1344
- end
1345
- end
1346
- 3'b110: begin
1347
- // c.swsp -> sw rs2, imm(x2)
1348
- instr_o = {4'b0, instr_i[8:7], instr_i[12], instr_i[6:2], 5'h02, 3'b010,
1349
- instr_i[11:9], 2'b00, {OPCODE_STORE}};
1350
- end
1351
- 3'b001,
1352
- 3'b011,
1353
- 3'b101,
1354
- 3'b111: begin
1355
- illegal_instr_o = 1'b1;
1356
- end
1357
- default: begin
1358
- illegal_instr_o = 1'b1;
1359
- end
1360
- endcase
1361
- end
1362
- // Incoming instruction is not compressed.
1363
- 2'b11:;
1364
- default: begin
1365
- illegal_instr_o = 1'b1;
1366
- end
1367
- endcase
1368
- end
1369
- assign is_compressed_o = (instr_i[1:0] != 2'b11);
1370
- ////////////////
1371
- // Assertions //
1372
- ////////////////
1373
- // The valid_i signal used to gate below assertions must be known.
1374
- // Selectors must be known/valid.
1375
- endmodule
1376
- // Copyright (c) 2025 Eclipse Foundation
1377
- // Copyright lowRISC contributors.
1378
- // Copyright 2018 ETH Zurich and University of Bologna, see also CREDITS.md.
1379
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
1380
- // SPDX-License-Identifier: Apache-2.0
1381
- /**
1382
- * Instruction Fetch Stage
1383
- *
1384
- * Instruction fetch unit: Selection of the next PC, and buffering (sampling) of
1385
- * the read instruction.
1386
- */
1387
- // Copyright lowRISC contributors.
1388
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
1389
- // SPDX-License-Identifier: Apache-2.0
1390
- // Macros and helper code for using assertions.
1391
- // - Provides default clk and rst options to simplify code
1392
- // - Provides boiler plate template for common assertions
1393
- // PRIM_ASSERT_SV
1394
- module cve2_if_stage import cve2_pkg::*; (
1395
- input logic clk_i,
1396
- input logic rst_ni,
1397
- input logic [31:0] boot_addr_i, // also used for mtvec
1398
- input logic req_i, // instruction request control
1399
- // instruction cache interface
1400
- output logic instr_req_o,
1401
- output logic [31:0] instr_addr_o,
1402
- input logic instr_gnt_i,
1403
- input logic instr_rvalid_i,
1404
- input logic [31:0] instr_rdata_i,
1405
- input logic instr_err_i,
1406
- // output of ID stage
1407
- output logic instr_valid_id_o, // instr in IF-ID is valid
1408
- output logic instr_new_id_o, // instr in IF-ID is new
1409
- output logic [31:0] instr_rdata_id_o, // instr for ID stage
1410
- output logic [31:0] instr_rdata_alu_id_o, // replicated instr for ID stage
1411
- // to reduce fan-out
1412
- output logic [15:0] instr_rdata_c_id_o, // compressed instr for ID stage
1413
- // (mtval), meaningful only if
1414
- // instr_is_compressed_id_o = 1'b1
1415
- output logic instr_is_compressed_id_o, // compressed decoder thinks this
1416
- // is a compressed instr
1417
- output logic instr_fetch_err_o, // bus error on fetch
1418
- output logic instr_fetch_err_plus2_o, // bus error misaligned
1419
- output logic illegal_c_insn_id_o, // compressed decoder thinks this
1420
- // is an invalid instr
1421
- output logic [31:0] pc_if_o,
1422
- output logic [31:0] pc_id_o,
1423
- input logic pmp_err_if_i,
1424
- input logic pmp_err_if_plus2_i,
1425
- // control signals
1426
- input logic instr_valid_clear_i, // clear instr valid bit in IF-ID
1427
- input logic pc_set_i, // set the PC to a new value
1428
- input pc_sel_e pc_mux_i, // selector for PC multiplexer
1429
- input exc_pc_sel_e exc_pc_mux_i, // selects ISR address
1430
- input exc_cause_e exc_cause, // selects ISR address for
1431
- // vectorized interrupt lines
1432
- // jump and branch target
1433
- input logic [31:0] branch_target_ex_i, // branch/jump target address
1434
- // CSRs
1435
- input logic [31:0] csr_mepc_i, // PC to restore after handling
1436
- // the interrupt/exception
1437
- input logic [31:0] csr_depc_i, // PC to restore after handling
1438
- // the debug request
1439
- input logic [31:0] csr_mtvec_i, // base PC to jump to on exception
1440
- output logic csr_mtvec_init_o, // tell CS regfile to init mtvec
1441
- // debug signals
1442
- input logic [31:0] dm_halt_addr_i, // default 32'h1A110800
1443
- input logic [31:0] dm_exception_addr_i, // default 32'h1A110808
1444
- // pipeline stall
1445
- input logic id_in_ready_i, // ID stage is ready for new instr
1446
- // misc signals
1447
- output logic if_busy_o // IF stage is busy fetching instr
1448
- );
1449
- logic instr_valid_id_d, instr_valid_id_q;
1450
- logic instr_new_id_d, instr_new_id_q;
1451
- // prefetch buffer related signals
1452
- logic prefetch_busy;
1453
- logic branch_req;
1454
- logic [31:0] fetch_addr_n;
1455
- logic unused_fetch_addr_n0;
1456
- logic fetch_valid;
1457
- logic fetch_ready;
1458
- logic [31:0] fetch_rdata;
1459
- logic [31:0] fetch_addr;
1460
- logic fetch_err;
1461
- logic fetch_err_plus2;
1462
- logic [31:0] instr_decompressed;
1463
- logic illegal_c_insn;
1464
- logic instr_is_compressed;
1465
- logic if_instr_pmp_err;
1466
- logic if_instr_err;
1467
- logic if_instr_err_plus2;
1468
- logic [31:0] exc_pc;
1469
- logic [6:0] irq_id;
1470
- logic unused_irq_bit;
1471
- logic if_id_pipe_reg_we; // IF-ID pipeline reg write enable
1472
- cve2_pkg::pc_sel_e pc_mux_internal;
1473
- logic [1:0] unused_boot_addr;
1474
- logic [7:0] unused_csr_mtvec;
1475
- assign unused_boot_addr = boot_addr_i[1:0];
1476
- assign unused_csr_mtvec = csr_mtvec_i[7:0];
1477
- // extract interrupt ID from exception cause
1478
- assign irq_id = {exc_cause};
1479
- assign unused_irq_bit = irq_id[6]; // MSB distinguishes interrupts from exceptions
1480
- // exception PC selection mux
1481
- always_comb begin : exc_pc_mux
1482
- unique case (exc_pc_mux_i)
1483
- EXC_PC_EXC: exc_pc = { csr_mtvec_i[31:8], 8'h00 };
1484
- EXC_PC_IRQ: exc_pc = { csr_mtvec_i[31:8], irq_id[5:0], 2'b00 };
1485
- EXC_PC_DBD: exc_pc = dm_halt_addr_i;
1486
- EXC_PC_DBG_EXC: exc_pc = dm_exception_addr_i;
1487
- default: exc_pc = { csr_mtvec_i[31:8], 8'h00 };
1488
- endcase
1489
- end
1490
- assign pc_mux_internal =
1491
- pc_mux_i;
1492
- // fetch address selection mux
1493
- always_comb begin : fetch_addr_mux
1494
- unique case (pc_mux_internal)
1495
- PC_BOOT: fetch_addr_n = { boot_addr_i[31:2], 2'b00 };
1496
- PC_JUMP: fetch_addr_n = branch_target_ex_i;
1497
- PC_EXC: fetch_addr_n = exc_pc; // set PC to exception handler
1498
- PC_ERET: fetch_addr_n = csr_mepc_i; // restore PC when returning from EXC
1499
- PC_DRET: fetch_addr_n = csr_depc_i;
1500
- default: fetch_addr_n = { boot_addr_i[31:2], 2'b00 };
1501
- endcase
1502
- end
1503
- // tell CS register file to initialize mtvec on boot
1504
- assign csr_mtvec_init_o = (pc_mux_i == PC_BOOT) & pc_set_i;
1505
- // prefetch buffer, caches a fixed number of instructions
1506
- cve2_prefetch_buffer #(
1507
- ) prefetch_buffer_i (
1508
- .clk_i ( clk_i ),
1509
- .rst_ni ( rst_ni ),
1510
- .req_i ( req_i ),
1511
- .branch_i ( branch_req ),
1512
- .addr_i ( {fetch_addr_n[31:1], 1'b0} ),
1513
- .ready_i ( fetch_ready ),
1514
- .valid_o ( fetch_valid ),
1515
- .rdata_o ( fetch_rdata ),
1516
- .addr_o ( fetch_addr ),
1517
- .err_o ( fetch_err ),
1518
- .err_plus2_o ( fetch_err_plus2 ),
1519
- .instr_req_o ( instr_req_o ),
1520
- .instr_addr_o ( instr_addr_o ),
1521
- .instr_gnt_i ( instr_gnt_i ),
1522
- .instr_rvalid_i ( instr_rvalid_i ),
1523
- .instr_rdata_i ( instr_rdata_i ),
1524
- .instr_err_i ( instr_err_i ),
1525
- .busy_o ( prefetch_busy )
1526
- );
1527
- assign unused_fetch_addr_n0 = fetch_addr_n[0];
1528
- assign branch_req = pc_set_i;
1529
- assign pc_if_o = fetch_addr;
1530
- assign if_busy_o = prefetch_busy;
1531
- // PMP errors
1532
- // An error can come from the instruction address, or the next instruction address for unaligned,
1533
- // uncompressed instructions.
1534
- assign if_instr_pmp_err = pmp_err_if_i |
1535
- (fetch_addr[2] & ~instr_is_compressed & pmp_err_if_plus2_i);
1536
- // Combine bus errors and pmp errors
1537
- assign if_instr_err = fetch_err | if_instr_pmp_err;
1538
- // Capture the second half of the address for errors on the second part of an instruction
1539
- assign if_instr_err_plus2 = ((fetch_addr[2] & ~instr_is_compressed & pmp_err_if_plus2_i) |
1540
- fetch_err_plus2) & ~pmp_err_if_i;
1541
- // compressed instruction decoding, or more precisely compressed instruction
1542
- // expander
1543
- //
1544
- // since it does not matter where we decompress instructions, we do it here
1545
- // to ease timing closure
1546
- cve2_compressed_decoder compressed_decoder_i (
1547
- .clk_i (clk_i),
1548
- .rst_ni (rst_ni),
1549
- .valid_i (fetch_valid & ~fetch_err),
1550
- .instr_i (fetch_rdata),
1551
- .instr_o (instr_decompressed),
1552
- .is_compressed_o(instr_is_compressed),
1553
- .illegal_instr_o(illegal_c_insn)
1554
- );
1555
- // The ID stage becomes valid as soon as any instruction is registered in the ID stage flops.
1556
- // Note that the current instruction is squashed by the incoming pc_set_i signal.
1557
- // Valid is held until it is explicitly cleared (due to an instruction completing or an exception)
1558
- assign instr_valid_id_d = (fetch_valid & id_in_ready_i & ~pc_set_i) |
1559
- (instr_valid_id_q & ~instr_valid_clear_i);
1560
- assign instr_new_id_d = fetch_valid & id_in_ready_i;
1561
- always_ff @(posedge clk_i or negedge rst_ni) begin
1562
- if (!rst_ni) begin
1563
- instr_valid_id_q <= 1'b0;
1564
- instr_new_id_q <= 1'b0;
1565
- end else begin
1566
- instr_valid_id_q <= instr_valid_id_d;
1567
- instr_new_id_q <= instr_new_id_d;
1568
- end
1569
- end
1570
- assign instr_valid_id_o = instr_valid_id_q;
1571
- // Signal when a new instruction enters the ID stage (only used for RVFI signalling).
1572
- assign instr_new_id_o = instr_new_id_q;
1573
- // IF-ID pipeline registers, frozen when the ID stage is stalled
1574
- assign if_id_pipe_reg_we = instr_new_id_d;
1575
- always_ff @(posedge clk_i or negedge rst_ni) begin
1576
- if (!rst_ni) begin
1577
- instr_rdata_id_o <= '0;
1578
- instr_rdata_alu_id_o <= '0;
1579
- instr_fetch_err_o <= '0;
1580
- instr_fetch_err_plus2_o <= '0;
1581
- instr_rdata_c_id_o <= '0;
1582
- instr_is_compressed_id_o <= '0;
1583
- illegal_c_insn_id_o <= '0;
1584
- pc_id_o <= '0;
1585
- end else if (if_id_pipe_reg_we) begin
1586
- instr_rdata_id_o <= instr_decompressed;
1587
- // To reduce fan-out and help timing from the instr_rdata_id flops they are replicated.
1588
- instr_rdata_alu_id_o <= instr_decompressed;
1589
- instr_fetch_err_o <= if_instr_err;
1590
- instr_fetch_err_plus2_o <= if_instr_err_plus2;
1591
- instr_rdata_c_id_o <= fetch_rdata[15:0]; //if_instr_rdata[15:0];
1592
- instr_is_compressed_id_o <= instr_is_compressed;
1593
- illegal_c_insn_id_o <= illegal_c_insn;
1594
- pc_id_o <= pc_if_o;
1595
- end
1596
- end
1597
- assign fetch_ready = id_in_ready_i;
1598
- ////////////////
1599
- // Assertions //
1600
- ////////////////
1601
- // Selectors must be known/valid.
1602
- // Boot address must be aligned to 4 bytes.
1603
- // Address must not contain X when request is sent.
1604
- // Address must be word aligned when request is sent.
1605
- endmodule
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p7/mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"conditional_statement": [[49325, 50498], [61387, 61582], [45093, 45357], [45370, 45434], [37762, 37888], [31076, 31168], [37224, 37295], [31297, 31493], [31389, 31493], [62272, 62837]], "blocking_assignment": [[42663, 42818], [49079, 49210], [44735, 44859], [43219, 43408], [45411, 45434], [47217, 47349], [27401, 27423], [57852, 57896], [57523, 57547]], "module_program_interface_instantiation": [[58435, 59548], [34716, 35504], [60533, 60848]], "always_construct": [[28218, 28405], [26997, 27498], [57291, 57691], [42285, 51111], [57768, 58255], [40306, 40741], [61881, 62843], [37707, 37894], [37110, 37301], [61332, 61588], [31238, 31503], [31021, 31174]], "case_statement": [[42551, 43659], [42485, 51105], [57807, 58249], [57326, 57685], [48635, 50957], [46291, 47740], [45485, 47865], [43964, 48330]], "ansi_port_declaration": [[23073, 23107], [23245, 23280], [23481, 23521], [23382, 23421], [52311, 52404], [32392, 32419], [32538, 32570], [32716, 32751]], "continuous_assign": [[57133, 57169], [60025, 60076], [30524, 30621], [29436, 29493], [24781, 24820], [30775, 30851], [39928, 40079], [27661, 27722], [24673, 24725]], "parameter_declaration": [[13622, 13688], [13787, 13814], [16993, 17037], [16708, 16752], [23031, 23066], [16802, 16847], [16755, 16799], [16946, 16990]], "nonblocking_assignment": [[28362, 28391], [62307, 62354], [62611, 62681], [62509, 62550], [40547, 40583], [31458, 31481], [37256, 37287], [31422, 31447], [40635, 40679], [62557, 62604], [62743, 62786], [40686, 40727], [62688, 62736], [37851, 37880], [40590, 40628], [61495, 61532], [62455, 62502], [61539, 61574], [31141, 31160], [62793, 62829]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p8/all_mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"module_program_interface_instantiation": [], "continuous_assign": [[9768, 9807], [9810, 9846], [13438, 13509], [16885, 17092], [21748, 21811], [21814, 21892], [21895, 21991], [22023, 22059], [22108, 22162], [22195, 22238], [22241, 22275], [22278, 22310], [22313, 22344], [22412, 22447], [22530, 22601], [22604, 22675], [22678, 22714]], "blocking_assignment": [[10195, 10213], [10235, 10253], [10275, 10293], [10315, 10333], [10355, 10373], [10535, 10604], [10626, 10644], [10666, 10684], [10706, 10724], [10746, 10764], [11018, 11036], [11058, 11076], [11098, 11116], [11138, 11156], [11178, 11196], [11311, 11329], [11455, 11473], [11493, 11511], [11531, 11549], [11569, 11587], [11607, 11625], [11693, 11711], [12003, 12035], [12051, 12104], [12120, 12173], [12189, 12242], [12258, 12290], [13798, 13832], [13848, 13898], [13914, 13965], [13981, 14032], [14048, 14082], [14323, 14368], [14402, 14461], [14549, 14594], [14628, 14687], [14775, 14821], [14855, 14915], [15003, 15063], [15097, 15170], [15208, 15253], [15445, 15492], [15526, 15583], [15671, 15719], [15753, 15812], [15900, 15949], [15983, 16043], [16131, 16180], [16214, 16274], [16312, 16359], [16530, 16559], [16579, 16608], [16628, 16657], [16677, 16706], [17126, 17154], [17159, 17186], [17191, 17218], [17223, 17265], [17270, 17302], [17307, 17339], [17344, 17371], [17376, 17403], [17408, 17435], [17440, 17467], [17472, 17499], [17554, 17571], [17611, 17631], [17642, 17672], [17683, 17703], [17714, 17739], [17750, 17774], [17819, 17846], [17859, 17886], [17899, 17945], [17958, 18029], [18067, 18142], [18213, 18231], [18607, 18634], [18645, 18672], [18683, 18710], [18721, 18759], [18854, 18872], [18931, 18954], [19127, 19154], [19220, 19255], [19313, 19339], [19406, 19447], [19523, 19576], [19653, 19687], [19842, 19880], [19893, 19920], [20037, 20075], [20084, 20107], [20161, 20188], [20258, 20291], [20302, 20329], [20340, 20367], [20585, 20608], [20778, 20805], [20881, 20904], [20990, 21016], [21074, 21100], [21147, 21164], [21216, 21233]], "nonblocking_assignment": [[12519, 12533], [12577, 12607], [12743, 12767], [12774, 12798], [12805, 12829], [12836, 12860], [12903, 12934], [12941, 12971], [12978, 13012], [13019, 13047], [13592, 13610], [13653, 13680], [21367, 21395], [21402, 21428], [21435, 21461], [21468, 21494], [21520, 21553], [21560, 21603], [21610, 21643], [21650, 21683]], "case_statement": [[9937, 11744], [10148, 10413], [10488, 10804], [10971, 11236], [11410, 11663], [11962, 12324], [13754, 14094], [14229, 15290], [15351, 16396], [16485, 16740], [17504, 21255]], "conditional_statement": [[10054, 10816], [10877, 11341], [12494, 12615], [12547, 12615], [12718, 13055], [12874, 13055], [13567, 13688], [13624, 13688], [14285, 14473], [14511, 14699], [14737, 14927], [14965, 15182], [15407, 15595], [15633, 15824], [15862, 16055], [16093, 16286], [17580, 18168], [17785, 18156], [18562, 18771], [19025, 19946], [19768, 19934], [20116, 20379], [20689, 21176], [21342, 21691]], "always_construct": [[9915, 11750], [11940, 12330], [12439, 12621], [12663, 13061], [13512, 13694], [13732, 14100], [14207, 15296], [15329, 16402], [16463, 16746], [17104, 21261], [21287, 21697]], "parameter_declaration": [], "ansi_port_declaration": [[6699, 6726], [6729, 6757], [6780, 6812], [6815, 6847], [6850, 6885], [6888, 6920], [6923, 6959], [6962, 6995], [6998, 7029], [7032, 7063], [7066, 7100], [7103, 7137], [7173, 7265], [7268, 7360], [7363, 7455], [7458, 7550], [7553, 7643], [7646, 7685], [7688, 7780], [7783, 7875], [7878, 7953], [8050, 8145], [8286, 8377], [8403, 8435], [8438, 8471], [8474, 8502], [8505, 8538], [8541, 8574]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p8/cve2_load_store_unit.sv DELETED
@@ -1,546 +0,0 @@
1
- // Copyright (c) 2025 Eclipse Foundation
2
- // Copyright lowRISC contributors.
3
- // Copyright 2018 ETH Zurich and University of Bologna, see also CREDITS.md.
4
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
5
- // SPDX-License-Identifier: Apache-2.0
6
- /**
7
- * Load Store Unit
8
- *
9
- * Load Store Unit, used to eliminate multiple access during processor stalls,
10
- * and to align bytes and halfwords.
11
- */
12
- // Copyright lowRISC contributors.
13
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
14
- // SPDX-License-Identifier: Apache-2.0
15
- // Macros and helper code for using assertions.
16
- // - Provides default clk and rst options to simplify code
17
- // - Provides boiler plate template for common assertions
18
- ///////////////////
19
- // Helper macros //
20
- ///////////////////
21
- // Default clk and reset signals used by assertion macros below.
22
- // Converts an arbitrary block of code into a Verilog string
23
- // ASSERT_ERROR logs an error message with either `uvm_error or with $error.
24
- //
25
- // This somewhat duplicates `DV_ERROR macro defined in hw/dv/sv/dv_utils/dv_macros.svh. The reason
26
- // for redefining it here is to avoid creating a dependency.
27
- // This macro is suitable for conditionally triggering lint errors, e.g., if a Sec parameter takes
28
- // on a non-default value. This may be required for pre-silicon/FPGA evaluation but we don't want
29
- // to allow this for tapeout.
30
- // The basic helper macros are actually defined in "implementation headers". The macros should do
31
- // the same thing in each case (except for the dummy flavour), but in a way that the respective
32
- // tools support.
33
- //
34
- // If the tool supports assertions in some form, we also define INC_ASSERT (which can be used to
35
- // hide signal definitions that are only used for assertions).
36
- //
37
- // The list of basic macros supported is:
38
- //
39
- // ASSERT_I: Immediate assertion. Note that immediate assertions are sensitive to simulation
40
- // glitches.
41
- //
42
- // ASSERT_INIT: Assertion in initial block. Can be used for things like parameter checking.
43
- //
44
- // ASSERT_INIT_NET: Assertion in initial block. Can be used for initial value of a net.
45
- //
46
- // ASSERT_FINAL: Assertion in final block. Can be used for things like queues being empty at end of
47
- // sim, all credits returned at end of sim, state machines in idle at end of sim.
48
- //
49
- // ASSERT: Assert a concurrent property directly. It can be called as a module (or
50
- // interface) body item.
51
- //
52
- // Note: We use (__rst !== '0) in the disable iff statements instead of (__rst ==
53
- // '1). This properly disables the assertion in cases when reset is X at the
54
- // beginning of a simulation. For that case, (reset == '1) does not disable the
55
- // assertion.
56
- //
57
- // ASSERT_NEVER: Assert a concurrent property NEVER happens
58
- //
59
- // ASSERT_KNOWN: Assert that signal has a known value (each bit is either '0' or '1') after reset.
60
- // It can be called as a module (or interface) body item.
61
- //
62
- // COVER: Cover a concurrent property
63
- //
64
- // ASSUME: Assume a concurrent property
65
- //
66
- // ASSUME_I: Assume an immediate property
67
- // Copyright lowRISC contributors.
68
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
69
- // SPDX-License-Identifier: Apache-2.0
70
- // Macro bodies included by prim_assert.sv for tools that don't support assertions. See
71
- // prim_assert.sv for documentation for each of the macros.
72
- //////////////////////////////
73
- // Complex assertion macros //
74
- //////////////////////////////
75
- // Assert that signal is an active-high pulse with pulse length of 1 clock cycle
76
- // Assert that a property is true only when an enable signal is set. It can be called as a module
77
- // (or interface) body item.
78
- // Assert that signal has a known value (each bit is either '0' or '1') after reset if enable is
79
- // set. It can be called as a module (or interface) body item.
80
- //////////////////////////////////
81
- // For formal verification only //
82
- //////////////////////////////////
83
- // Note that the existing set of ASSERT macros specified above shall be used for FPV,
84
- // thereby ensuring that the assertions are evaluated during DV simulations as well.
85
- // ASSUME_FPV
86
- // Assume a concurrent property during formal verification only.
87
- // ASSUME_I_FPV
88
- // Assume a concurrent property during formal verification only.
89
- // COVER_FPV
90
- // Cover a concurrent property during formal verification
91
- // Copyright lowRISC contributors.
92
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
93
- // SPDX-License-Identifier: Apache-2.0
94
- // // Macros and helper code for security countermeasures.
95
- // Helper macros
96
- // macros for security countermeasures
97
- // PRIM_ASSERT_SEC_CM_SVH
98
- // PRIM_ASSERT_SV
99
- // Copyright lowRISC contributors.
100
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
101
- // SPDX-License-Identifier: Apache-2.0
102
- // Include FCOV RTL by default. Disable it for synthesis and where explicitly requested (by defining
103
- // DV_FCOV_DISABLE).
104
- // Disable instantiations of FCOV coverpoints or covergroups.
105
- // Instantiates a covergroup in an interface or module.
106
- //
107
- // This macro assumes that a covergroup of the same name as the NAME_ arg is defined in the
108
- // interface or module. It just adds some extra signals and logic to control the creation of the
109
- // covergroup instance with ~bit en_<cg_name>~. This defaults to 0. It is ORed with the external
110
- // COND_ signal. The testbench can modify it at t = 0 based on the test being run.
111
- // NOTE: This is not meant to be invoked inside a class.
112
- //
113
- // NAME_ : Name of the covergroup.
114
- // COND_ : External condition / expr that controls the creation of the covergroup.
115
- // ARGS_ : Arguments to covergroup instance, if any. Args MUST BE wrapped in (..).
116
- // Creates a coverpoint for an expression where only the expression true case is of interest for
117
- // coverage (e.g. where the expression indicates an event has occured).
118
- // Creates a SVA cover that can be used in a covergroup.
119
- //
120
- // This macro creates an unnamed SVA cover from the property (or an expression) `PROP_` and an event
121
- // with the name `EV_NAME_`. When the SVA cover is hit, the event is triggered. A coverpoint can
122
- // cover the `triggered` property of the event.
123
- // Coverage support is not always available but it's useful to include extra fcov signals for
124
- // linting purposes. They need to be marked as unused to avoid warnings.
125
- // Define a signal and expression in the design for capture in functional coverage
126
- // Define a signal and expression in the design for capture in functional coverage depending on
127
- // design configuration. The input GEN_COND_ must be a constant or parameter.
128
- module cve2_load_store_unit
129
- (
130
- input logic clk_i,
131
- input logic rst_ni,
132
- // data interface
133
- output logic data_req_o,
134
- input logic data_gnt_i,
135
- input logic data_rvalid_i,
136
- input logic data_err_i,
137
- input logic data_pmp_err_i,
138
- output logic [31:0] data_addr_o,
139
- output logic data_we_o,
140
- output logic [3:0] data_be_o,
141
- output logic [31:0] data_wdata_o,
142
- input logic [31:0] data_rdata_i,
143
- // signals to/from ID/EX stage
144
- input logic lsu_we_i, // write enable -> from ID/EX
145
- input logic [1:0] lsu_type_i, // data type: word, half word, byte -> from ID/EX
146
- input logic [31:0] lsu_wdata_i, // data to write to memory -> from ID/EX
147
- input logic lsu_sign_ext_i, // sign extension -> from ID/EX
148
- output logic [31:0] lsu_rdata_o, // requested data -> to ID/EX
149
- output logic lsu_rdata_valid_o,
150
- input logic lsu_req_i, // data request -> from ID/EX
151
- input logic [31:0] adder_result_ex_i, // address computed in ALU -> from ID/EX
152
- output logic addr_incr_req_o, // request address increment for
153
- // misaligned accesses -> to ID/EX
154
- output logic [31:0] addr_last_o, // address of last transaction -> to controller
155
- // -> mtval
156
- // -> AGU for misaligned accesses
157
- output logic lsu_resp_valid_o, // LSU has response from transaction -> to ID/EX
158
- // exception signals
159
- output logic load_err_o,
160
- output logic store_err_o,
161
- output logic busy_o,
162
- output logic perf_load_o,
163
- output logic perf_store_o
164
- );
165
- logic [31:0] data_addr;
166
- logic [31:0] data_addr_w_aligned;
167
- logic [31:0] addr_last_q, addr_last_d;
168
- logic addr_update;
169
- logic ctrl_update;
170
- logic rdata_update;
171
- logic [31:8] rdata_q;
172
- logic [1:0] rdata_offset_q;
173
- logic [1:0] data_type_q;
174
- logic data_sign_ext_q;
175
- logic data_we_q;
176
- logic [1:0] data_offset; // mux control for data to be written to memory
177
- logic [3:0] data_be;
178
- logic [31:0] data_wdata;
179
- logic [31:0] data_rdata_ext;
180
- logic [31:0] rdata_w_ext; // word realignment for misaligned loads
181
- logic [31:0] rdata_h_ext; // sign extension for half words
182
- logic [31:0] rdata_b_ext; // sign extension for bytes
183
- logic split_misaligned_access;
184
- logic handle_misaligned_q, handle_misaligned_d; // high after receiving grant for first
185
- // part of a misaligned access
186
- logic pmp_err_q, pmp_err_d;
187
- logic lsu_err_q, lsu_err_d;
188
- logic data_or_pmp_err;
189
- typedef enum logic [2:0] {
190
- IDLE, WAIT_GNT_MIS, WAIT_RVALID_MIS, WAIT_GNT,
191
- WAIT_RVALID_MIS_GNTS_DONE
192
- } ls_fsm_e;
193
- ls_fsm_e ls_fsm_cs, ls_fsm_ns;
194
- assign data_addr = adder_result_ex_i;
195
- assign data_offset = data_addr[1:0];
196
- ///////////////////
197
- // BE generation //
198
- ///////////////////
199
- always_comb begin
200
- unique case (lsu_type_i) // Data type 00 Word, 01 Half word, 11,10 byte
201
- 2'b00: begin // Writing a word
202
- if (!handle_misaligned_q) begin // first part of potentially misaligned transaction
203
- unique case (data_offset)
204
- 2'b00: data_be = 4'b1111;
205
- 2'b01: data_be = 4'b1110;
206
- 2'b10: data_be = 4'b1100;
207
- 2'b11: data_be = 4'b1000;
208
- default: data_be = 4'b1111;
209
- endcase // case (data_offset)
210
- end else begin // second part of misaligned transaction
211
- unique case (data_offset)
212
- 2'b00: data_be = 4'b0000; // this is not used, but included for completeness
213
- 2'b01: data_be = 4'b0001;
214
- 2'b10: data_be = 4'b0011;
215
- 2'b11: data_be = 4'b0111;
216
- default: data_be = 4'b1111;
217
- endcase // case (data_offset)
218
- end
219
- end
220
- 2'b01: begin // Writing a half word
221
- if (!handle_misaligned_q) begin // first part of potentially misaligned transaction
222
- unique case (data_offset)
223
- 2'b00: data_be = 4'b0011;
224
- 2'b01: data_be = 4'b0110;
225
- 2'b10: data_be = 4'b1100;
226
- 2'b11: data_be = 4'b1000;
227
- default: data_be = 4'b1111;
228
- endcase // case (data_offset)
229
- end else begin // second part of misaligned transaction
230
- data_be = 4'b0001;
231
- end
232
- end
233
- 2'b10,
234
- 2'b11: begin // Writing a byte
235
- unique case (data_offset)
236
- 2'b00: data_be = 4'b0001;
237
- 2'b01: data_be = 4'b0010;
238
- 2'b10: data_be = 4'b0100;
239
- 2'b11: data_be = 4'b1000;
240
- default: data_be = 4'b1111;
241
- endcase // case (data_offset)
242
- end
243
- default: data_be = 4'b1111;
244
- endcase // case (lsu_type_i)
245
- end
246
- /////////////////////
247
- // WData alignment //
248
- /////////////////////
249
- // prepare data to be written to the memory
250
- // we handle misaligned accesses, half word and byte accesses here
251
- always_comb begin
252
- unique case (data_offset)
253
- 2'b00: data_wdata = lsu_wdata_i[31:0];
254
- 2'b01: data_wdata = {lsu_wdata_i[23:0], lsu_wdata_i[31:24]};
255
- 2'b10: data_wdata = {lsu_wdata_i[15:0], lsu_wdata_i[31:16]};
256
- 2'b11: data_wdata = {lsu_wdata_i[ 7:0], lsu_wdata_i[31: 8]};
257
- default: data_wdata = lsu_wdata_i[31:0];
258
- endcase // case (data_offset)
259
- end
260
- /////////////////////
261
- // RData alignment //
262
- /////////////////////
263
- // register for unaligned rdata
264
- always_ff @(posedge clk_i or negedge rst_ni) begin
265
- if (!rst_ni) begin
266
- rdata_q <= '0;
267
- end else if (rdata_update) begin
268
- rdata_q <= data_rdata_i[31:8];
269
- end
270
- end
271
- // registers for transaction control
272
- always_ff @(posedge clk_i or negedge rst_ni) begin
273
- if (!rst_ni) begin
274
- rdata_offset_q <= 2'h0;
275
- data_type_q <= 2'h0;
276
- data_sign_ext_q <= 1'b0;
277
- data_we_q <= 1'b0;
278
- end else if (ctrl_update) begin
279
- rdata_offset_q <= data_offset;
280
- data_type_q <= lsu_type_i;
281
- data_sign_ext_q <= lsu_sign_ext_i;
282
- data_we_q <= lsu_we_i;
283
- end
284
- end
285
- // Store last address for mtval + AGU for misaligned transactions. Do not update in case of
286
- // errors, mtval needs the (first) failing address. Where an aligned access or the first half of
287
- // a misaligned access sees an error provide the calculated access address. For the second half of
288
- // a misaligned access provide the word aligned address of the second half.
289
- assign addr_last_d = addr_incr_req_o ? data_addr_w_aligned : data_addr;
290
- always_ff @(posedge clk_i or negedge rst_ni) begin
291
- if (!rst_ni) begin
292
- addr_last_q <= '0;
293
- end else if (addr_update) begin
294
- addr_last_q <= addr_last_d;
295
- end
296
- end
297
- // take care of misaligned words
298
- always_comb begin
299
- unique case (rdata_offset_q)
300
- 2'b00: rdata_w_ext = data_rdata_i[31:0];
301
- 2'b01: rdata_w_ext = {data_rdata_i[ 7:0], rdata_q[31:8]};
302
- 2'b10: rdata_w_ext = {data_rdata_i[15:0], rdata_q[31:16]};
303
- 2'b11: rdata_w_ext = {data_rdata_i[23:0], rdata_q[31:24]};
304
- default: rdata_w_ext = data_rdata_i[31:0];
305
- endcase
306
- end
307
- ////////////////////
308
- // Sign extension //
309
- ////////////////////
310
- // sign extension for half words
311
- always_comb begin
312
- unique case (rdata_offset_q)
313
- 2'b00: begin
314
- if (!data_sign_ext_q) begin
315
- rdata_h_ext = {16'h0000, data_rdata_i[15:0]};
316
- end else begin
317
- rdata_h_ext = {{16{data_rdata_i[15]}}, data_rdata_i[15:0]};
318
- end
319
- end
320
- 2'b01: begin
321
- if (!data_sign_ext_q) begin
322
- rdata_h_ext = {16'h0000, data_rdata_i[23:8]};
323
- end else begin
324
- rdata_h_ext = {{16{data_rdata_i[23]}}, data_rdata_i[23:8]};
325
- end
326
- end
327
- 2'b10: begin
328
- if (!data_sign_ext_q) begin
329
- rdata_h_ext = {16'h0000, data_rdata_i[31:16]};
330
- end else begin
331
- rdata_h_ext = {{16{data_rdata_i[31]}}, data_rdata_i[31:16]};
332
- end
333
- end
334
- 2'b11: begin
335
- if (!data_sign_ext_q) begin
336
- rdata_h_ext = {16'h0000, data_rdata_i[7:0], rdata_q[31:24]};
337
- end else begin
338
- rdata_h_ext = {{16{data_rdata_i[7]}}, data_rdata_i[7:0], rdata_q[31:24]};
339
- end
340
- end
341
- default: rdata_h_ext = {16'h0000, data_rdata_i[15:0]};
342
- endcase // case (rdata_offset_q)
343
- end
344
- // sign extension for bytes
345
- always_comb begin
346
- unique case (rdata_offset_q)
347
- 2'b00: begin
348
- if (!data_sign_ext_q) begin
349
- rdata_b_ext = {24'h00_0000, data_rdata_i[7:0]};
350
- end else begin
351
- rdata_b_ext = {{24{data_rdata_i[7]}}, data_rdata_i[7:0]};
352
- end
353
- end
354
- 2'b01: begin
355
- if (!data_sign_ext_q) begin
356
- rdata_b_ext = {24'h00_0000, data_rdata_i[15:8]};
357
- end else begin
358
- rdata_b_ext = {{24{data_rdata_i[15]}}, data_rdata_i[15:8]};
359
- end
360
- end
361
- 2'b10: begin
362
- if (!data_sign_ext_q) begin
363
- rdata_b_ext = {24'h00_0000, data_rdata_i[23:16]};
364
- end else begin
365
- rdata_b_ext = {{24{data_rdata_i[23]}}, data_rdata_i[23:16]};
366
- end
367
- end
368
- 2'b11: begin
369
- if (!data_sign_ext_q) begin
370
- rdata_b_ext = {24'h00_0000, data_rdata_i[31:24]};
371
- end else begin
372
- rdata_b_ext = {{24{data_rdata_i[31]}}, data_rdata_i[31:24]};
373
- end
374
- end
375
- default: rdata_b_ext = {24'h00_0000, data_rdata_i[7:0]};
376
- endcase // case (rdata_offset_q)
377
- end
378
- // select word, half word or byte sign extended version
379
- always_comb begin
380
- unique case (data_type_q)
381
- 2'b00: data_rdata_ext = rdata_w_ext;
382
- 2'b01: data_rdata_ext = rdata_h_ext;
383
- 2'b10,2'b11: data_rdata_ext = rdata_b_ext;
384
- default: data_rdata_ext = rdata_w_ext;
385
- endcase // case (data_type_q)
386
- end
387
- /////////////
388
- // LSU FSM //
389
- /////////////
390
- // check for misaligned accesses that need to be split into two word-aligned accesses
391
- assign split_misaligned_access =
392
- ((lsu_type_i == 2'b00) && (data_offset != 2'b00)) || // misaligned word access
393
- ((lsu_type_i == 2'b01) && (data_offset == 2'b11)); // misaligned half-word access
394
- // FSM
395
- always_comb begin
396
- ls_fsm_ns = ls_fsm_cs;
397
- data_req_o = 1'b0;
398
- addr_incr_req_o = 1'b0;
399
- handle_misaligned_d = handle_misaligned_q;
400
- pmp_err_d = pmp_err_q;
401
- lsu_err_d = lsu_err_q;
402
- addr_update = 1'b0;
403
- ctrl_update = 1'b0;
404
- rdata_update = 1'b0;
405
- perf_load_o = 1'b0;
406
- perf_store_o = 1'b0;
407
- unique case (ls_fsm_cs)
408
- IDLE: begin
409
- pmp_err_d = 1'b0;
410
- if (lsu_req_i) begin
411
- data_req_o = 1'b1;
412
- pmp_err_d = data_pmp_err_i;
413
- lsu_err_d = 1'b0;
414
- perf_load_o = ~lsu_we_i;
415
- perf_store_o = lsu_we_i;
416
- if (data_gnt_i) begin
417
- ctrl_update = 1'b1;
418
- addr_update = 1'b1;
419
- handle_misaligned_d = split_misaligned_access;
420
- ls_fsm_ns = split_misaligned_access ? WAIT_RVALID_MIS : IDLE;
421
- end else begin
422
- ls_fsm_ns = split_misaligned_access ? WAIT_GNT_MIS : WAIT_GNT;
423
- end
424
- end
425
- end
426
- WAIT_GNT_MIS: begin
427
- data_req_o = 1'b1;
428
- // data_pmp_err_i is valid during the address phase of a request. An error will block the
429
- // external request and so a data_gnt_i might never be signalled. The registered version
430
- // pmp_err_q is only updated for new address phases and so can be used in WAIT_GNT* and
431
- // WAIT_RVALID* states
432
- if (data_gnt_i || pmp_err_q) begin
433
- addr_update = 1'b1;
434
- ctrl_update = 1'b1;
435
- handle_misaligned_d = 1'b1;
436
- ls_fsm_ns = WAIT_RVALID_MIS;
437
- end
438
- end
439
- WAIT_RVALID_MIS: begin
440
- // push out second request
441
- data_req_o = 1'b1;
442
- // tell ID/EX stage to update the address
443
- addr_incr_req_o = 1'b1;
444
- // first part rvalid is received, or gets a PMP error
445
- if (data_rvalid_i || pmp_err_q) begin
446
- // Update the PMP error for the second part
447
- pmp_err_d = data_pmp_err_i;
448
- // Record the error status of the first part
449
- lsu_err_d = data_err_i | pmp_err_q;
450
- // Capture the first rdata for loads
451
- rdata_update = ~data_we_q;
452
- // If already granted, wait for second rvalid
453
- ls_fsm_ns = data_gnt_i ? IDLE : WAIT_GNT;
454
- // Update the address for the second part, if no error
455
- addr_update = data_gnt_i & ~(data_err_i | pmp_err_q);
456
- // clear handle_misaligned if second request is granted
457
- handle_misaligned_d = ~data_gnt_i;
458
- end else begin
459
- // first part rvalid is NOT received
460
- if (data_gnt_i) begin
461
- // second grant is received
462
- ls_fsm_ns = WAIT_RVALID_MIS_GNTS_DONE;
463
- handle_misaligned_d = 1'b0;
464
- end
465
- end
466
- end
467
- WAIT_GNT: begin
468
- // tell ID/EX stage to update the address
469
- addr_incr_req_o = handle_misaligned_q;
470
- data_req_o = 1'b1;
471
- if (data_gnt_i || pmp_err_q) begin
472
- ctrl_update = 1'b1;
473
- // Update the address, unless there was an error
474
- addr_update = ~lsu_err_q;
475
- ls_fsm_ns = IDLE;
476
- handle_misaligned_d = 1'b0;
477
- end
478
- end
479
- WAIT_RVALID_MIS_GNTS_DONE: begin
480
- // tell ID/EX stage to update the address (to make sure the
481
- // second address can be captured correctly for mtval and PMP checking)
482
- addr_incr_req_o = 1'b1;
483
- // Wait for the first rvalid, second request is already granted
484
- if (data_rvalid_i) begin
485
- // Update the pmp error for the second part
486
- pmp_err_d = data_pmp_err_i;
487
- // The first part cannot see a PMP error in this state
488
- lsu_err_d = data_err_i;
489
- // Now we can update the address for the second part if no error
490
- addr_update = ~data_err_i;
491
- // Capture the first rdata for loads
492
- rdata_update = ~data_we_q;
493
- // Wait for second rvalid
494
- ls_fsm_ns = IDLE;
495
- end
496
- end
497
- default: begin
498
- ls_fsm_ns = IDLE;
499
- end
500
- endcase
501
- end
502
- // registers for FSM
503
- always_ff @(posedge clk_i or negedge rst_ni) begin
504
- if (!rst_ni) begin
505
- ls_fsm_cs <= IDLE;
506
- handle_misaligned_q <= '0;
507
- pmp_err_q <= '0;
508
- lsu_err_q <= '0;
509
- end else begin
510
- ls_fsm_cs <= ls_fsm_ns;
511
- handle_misaligned_q <= handle_misaligned_d;
512
- pmp_err_q <= pmp_err_d;
513
- lsu_err_q <= lsu_err_d;
514
- end
515
- end
516
- /////////////
517
- // Outputs //
518
- /////////////
519
- assign data_or_pmp_err = lsu_err_q | data_err_i | pmp_err_q;
520
- assign lsu_resp_valid_o = (data_rvalid_i | pmp_err_q) & (ls_fsm_cs == IDLE);
521
- assign lsu_rdata_valid_o = (ls_fsm_cs == IDLE) & data_rvalid_i & ~data_or_pmp_err & ~data_we_q;
522
- // output to register file
523
- assign lsu_rdata_o = data_rdata_ext;
524
- // output data address must be word aligned
525
- assign data_addr_w_aligned = {data_addr[31:2], 2'b00};
526
- // output to data interface
527
- assign data_addr_o = data_addr_w_aligned;
528
- assign data_wdata_o = data_wdata;
529
- assign data_we_o = lsu_we_i;
530
- assign data_be_o = data_be;
531
- // output to ID stage: mtval + AGU for misaligned transactions
532
- assign addr_last_o = addr_last_q;
533
- // Signal a load or store error depending on the transaction type outstanding
534
- assign load_err_o = data_or_pmp_err & ~data_we_q & lsu_resp_valid_o;
535
- assign store_err_o = data_or_pmp_err & data_we_q & lsu_resp_valid_o;
536
- assign busy_o = (ls_fsm_cs != IDLE);
537
- //////////
538
- // FCOV //
539
- //////////
540
- ////////////////
541
- // Assertions //
542
- ////////////////
543
- // Selectors must be known/valid.
544
- // Address must not contain X when request is sent.
545
- // Address must be word aligned when request is sent.
546
- endmodule
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p8/mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"conditional_statement": [[10054, 10816], [20116, 20379], [13567, 13688], [17580, 18168], [14737, 14927], [14285, 14473], [15633, 15824], [20689, 21176], [15862, 16055], [17785, 18156]], "blocking_assignment": [[10626, 10644], [11311, 11329], [20161, 20188], [19406, 19447], [17191, 17218], [18721, 18759], [10235, 10253], [19220, 19255], [14549, 14594], [17683, 17703]], "always_construct": [[14207, 15296], [12439, 12621], [9915, 11750], [15329, 16402], [12663, 13061], [13732, 14100], [17104, 21261], [21287, 21697], [11940, 12330], [16463, 16746], [13512, 13694]], "case_statement": [[13754, 14094], [10488, 10804], [9937, 11744], [14229, 15290], [10971, 11236], [11962, 12324], [16485, 16740], [17504, 21255], [10148, 10413], [15351, 16396], [11410, 11663]], "ansi_port_declaration": [[8050, 8145], [7878, 7953], [7363, 7455], [8438, 8471], [7066, 7100], [7688, 7780], [6998, 7029]], "continuous_assign": [[22195, 22238], [22241, 22275], [22313, 22344], [22604, 22675], [9810, 9846], [21895, 21991], [13438, 13509]], "nonblocking_assignment": [[12903, 12934], [12941, 12971], [21610, 21643], [21560, 21603], [13653, 13680], [13019, 13047], [12577, 12607], [12978, 13012], [21520, 21553], [21650, 21683]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p9/all_mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"module_program_interface_instantiation": [], "continuous_assign": [[25296, 25334], [25337, 25386], [25389, 25436], [25927, 25982], [26034, 26097], [26100, 26136], [26139, 26188], [26191, 26232], [26235, 26282], [26315, 26361], [26392, 26436], [26439, 26490], [26493, 26570], [27388, 27481], [27486, 27579], [27584, 27677], [27682, 27764], [27769, 27814], [27819, 27869], [27874, 27916], [27921, 27967], [27972, 28018], [28133, 28160], [28165, 28192], [28197, 28230], [28235, 28268], [28286, 28313], [28318, 28347], [28352, 28385], [28390, 28424], [28449, 28492], [28497, 28558], [30103, 30154], [30798, 30907], [30912, 30962], [30967, 31009], [33969, 34015], [34054, 34125], [34128, 34212], [34215, 34369], [34372, 34427], [34895, 34950], [34953, 35008], [35011, 35079], [35082, 35118], [39507, 39547]], "blocking_assignment": [[28634, 28656], [28663, 28683], [28690, 28717], [28724, 28750], [28757, 28798], [28805, 28837], [28844, 28876], [28936, 28991], [28998, 29021], [29028, 29048], [29055, 29072], [29184, 29204], [29217, 29235], [29248, 29268], [29306, 29323], [29399, 29421], [29432, 29454], [29465, 29492], [29503, 29530], [29541, 29561], [29572, 29586], [29597, 29614], [29625, 29657], [29668, 29688], [29699, 29717], [29728, 29745], [29791, 29811], [31038, 31066], [31073, 31101], [31108, 31128], [31135, 31155], [31162, 31192], [31199, 31222], [31229, 31257], [31264, 31284], [31291, 31311], [31394, 31419], [31430, 31455], [31466, 31483], [31494, 31511], [31522, 31537], [31548, 31568], [31579, 31599], [31665, 31690], [31701, 31727], [31738, 31755], [31766, 31808], [31898, 31941], [32000, 32056], [32120, 32140], [32165, 32185], [32251, 32277], [32288, 32313], [32324, 32366], [32377, 32394], [32453, 32499], [32512, 32571], [32584, 32604], [32688, 32708], [32721, 32741], [32779, 32809], [32822, 32845], [32858, 32878], [32988, 33014], [33025, 33051], [33062, 33104], [33115, 33157], [33168, 33206], [33217, 33272], [33357, 33380], [33391, 33411], [33491, 33511], [33522, 33542], [33588, 33608], [34769, 34814], [34840, 34878], [35143, 35183], [35188, 35222], [35227, 35260], [35265, 35295], [35300, 35334], [35339, 35375], [35380, 35415], [35420, 35455], [35460, 35484], [35489, 35513], [35518, 35551], [35904, 35924], [35977, 36033], [36182, 36215], [36529, 36561], [36614, 36670], [36723, 36758], [36767, 36802], [36811, 36836], [36897, 36918], [36950, 37002], [37011, 37038], [37047, 37071], [37106, 37140], [37149, 37183], [37245, 37293], [37325, 37378], [37387, 37414], [37423, 37448], [37483, 37518], [37527, 37562], [37602, 37680], [37689, 37727], [37736, 37798], [37827, 37903], [37912, 37996], [38221, 38260], [38386, 38432], [38473, 38550], [38559, 38644], [38653, 38681], [38728, 38752], [38806, 38880], [38914, 38988], [39064, 39099], [39108, 39157], [39325, 39346], [39355, 39373], [39382, 39401], [39441, 39462]], "nonblocking_assignment": [[25519, 25542], [25549, 25577], [25584, 25607], [25614, 25637], [25644, 25667], [25714, 25748], [25755, 25790], [25797, 25831], [25838, 25869], [25876, 25910], [29950, 29971], [30039, 30068], [33747, 33768], [33836, 33865]], "case_statement": [[29079, 29853], [31318, 33650], [35556, 39498]], "conditional_statement": [[25494, 25918], [25681, 25918], [29136, 29337], [29923, 30090], [30001, 30080], [31952, 32154], [32405, 32892], [33720, 33887], [33798, 33877], [34700, 34886], [35610, 36682], [38036, 38444], [38761, 39000]], "always_construct": [[25439, 25924], [28563, 29861], [29866, 30098], [31014, 33658], [33663, 33895], [34678, 34892], [35121, 39504]], "parameter_declaration": [[6471, 6520], [6523, 6571], [6594, 6628], [6631, 6665], [6668, 6702], [12379, 12461], [12464, 12546], [12570, 12622], [12625, 12677], [12680, 12733], [12736, 12789], [12792, 12845], [12848, 12901], [12925, 13002], [13044, 13089], [13092, 13137], [13140, 13186], [13189, 13235], [13238, 13284], [13332, 13380], [13383, 13431], [13434, 13482], [13551, 13619], [13622, 13688], [13787, 13814], [16708, 16752], [16755, 16799], [16802, 16847], [16850, 16895], [16898, 16943], [16946, 16990], [16993, 17037], [17040, 17096], [22941, 22996]], "ansi_port_declaration": [[23005, 23036], [23039, 23071], [23074, 23152], [23155, 23233], [23236, 23313], [23316, 23393], [23396, 23432], [23435, 23474], [23477, 23509], [23512, 23544], [23547, 23588], [23591, 23628], [23631, 23672], [23675, 23716], [23719, 23760], [23763, 23803], [23806, 23846], [23849, 23887], [23890, 23932], [23935, 23967]]}
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p9/cve2_multdiv_fast.sv DELETED
@@ -1,1151 +0,0 @@
1
- // Copyright (c) 2025 Eclipse Foundation
2
- // Copyright lowRISC contributors.
3
- // Copyright 2017 ETH Zurich and University of Bologna, see also CREDITS.md.
4
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
5
- // SPDX-License-Identifier: Apache-2.0
6
- /**
7
- * Package with constants used by CVE2
8
- */
9
- package cve2_pkg;
10
- ////////////////
11
- // IO Structs //
12
- ////////////////
13
- typedef struct packed {
14
- logic [31:0] current_pc;
15
- logic [31:0] next_pc;
16
- logic [31:0] last_data_addr;
17
- logic [31:0] exception_addr;
18
- } crash_dump_t;
19
- typedef struct packed {
20
- logic dummy_instr_id;
21
- logic [4:0] raddr_a;
22
- logic [4:0] waddr_a;
23
- logic we_a;
24
- logic [4:0] raddr_b;
25
- } core2rf_t;
26
- /////////////////////
27
- // Parameter Enums //
28
- /////////////////////
29
- typedef enum integer {
30
- RV32MNone = 0,
31
- RV32MSlow = 1,
32
- RV32MFast = 2,
33
- RV32MSingleCycle = 3
34
- } rv32m_e;
35
- typedef enum integer {
36
- RV32BNone = 0,
37
- RV32BBalanced = 1,
38
- RV32BOTEarlGrey = 2,
39
- RV32BFull = 3
40
- } rv32b_e;
41
- /////////////
42
- // Opcodes //
43
- /////////////
44
- typedef enum logic [6:0] {
45
- OPCODE_LOAD = 7'h03,
46
- OPCODE_MISC_MEM = 7'h0f,
47
- OPCODE_OP_IMM = 7'h13,
48
- OPCODE_AUIPC = 7'h17,
49
- OPCODE_STORE = 7'h23,
50
- OPCODE_OP = 7'h33,
51
- OPCODE_LUI = 7'h37,
52
- OPCODE_BRANCH = 7'h63,
53
- OPCODE_JALR = 7'h67,
54
- OPCODE_JAL = 7'h6f,
55
- OPCODE_SYSTEM = 7'h73
56
- } opcode_e;
57
- ////////////////////
58
- // ALU operations //
59
- ////////////////////
60
- typedef enum logic [6:0] {
61
- // Arithmetics
62
- ALU_ADD,
63
- ALU_SUB,
64
- // Logics
65
- ALU_XOR,
66
- ALU_OR,
67
- ALU_AND,
68
- // RV32B
69
- ALU_XNOR,
70
- ALU_ORN,
71
- ALU_ANDN,
72
- // Shifts
73
- ALU_SRA,
74
- ALU_SRL,
75
- ALU_SLL,
76
- // RV32B
77
- ALU_SRO,
78
- ALU_SLO,
79
- ALU_ROR,
80
- ALU_ROL,
81
- ALU_GREV,
82
- ALU_GORC,
83
- ALU_SHFL,
84
- ALU_UNSHFL,
85
- ALU_XPERM_N,
86
- ALU_XPERM_B,
87
- ALU_XPERM_H,
88
- // Address Calculations
89
- // RV32B
90
- ALU_SH1ADD,
91
- ALU_SH2ADD,
92
- ALU_SH3ADD,
93
- // Comparisons
94
- ALU_LT,
95
- ALU_LTU,
96
- ALU_GE,
97
- ALU_GEU,
98
- ALU_EQ,
99
- ALU_NE,
100
- // RV32B
101
- ALU_MIN,
102
- ALU_MINU,
103
- ALU_MAX,
104
- ALU_MAXU,
105
- // Pack
106
- // RV32B
107
- ALU_PACK,
108
- ALU_PACKU,
109
- ALU_PACKH,
110
- // Sign-Extend
111
- // RV32B
112
- ALU_SEXTB,
113
- ALU_SEXTH,
114
- // Bitcounting
115
- // RV32B
116
- ALU_CLZ,
117
- ALU_CTZ,
118
- ALU_CPOP,
119
- // Set lower than
120
- ALU_SLT,
121
- ALU_SLTU,
122
- // Ternary Bitmanip Operations
123
- // RV32B
124
- ALU_CMOV,
125
- ALU_CMIX,
126
- ALU_FSL,
127
- ALU_FSR,
128
- // Single-Bit Operations
129
- // RV32B
130
- ALU_BSET,
131
- ALU_BCLR,
132
- ALU_BINV,
133
- ALU_BEXT,
134
- // Bit Compress / Decompress
135
- // RV32B
136
- ALU_BCOMPRESS,
137
- ALU_BDECOMPRESS,
138
- // Bit Field Place
139
- // RV32B
140
- ALU_BFP,
141
- // Carry-less Multiply
142
- // RV32B
143
- ALU_CLMUL,
144
- ALU_CLMULR,
145
- ALU_CLMULH,
146
- // Cyclic Redundancy Check
147
- ALU_CRC32_B,
148
- ALU_CRC32C_B,
149
- ALU_CRC32_H,
150
- ALU_CRC32C_H,
151
- ALU_CRC32_W,
152
- ALU_CRC32C_W
153
- } alu_op_e;
154
- typedef enum logic [1:0] {
155
- // Multiplier/divider
156
- MD_OP_MULL,
157
- MD_OP_MULH,
158
- MD_OP_DIV,
159
- MD_OP_REM
160
- } md_op_e;
161
- //////////////////////////////////
162
- // Control and status registers //
163
- //////////////////////////////////
164
- // CSR operations
165
- typedef enum logic [1:0] {
166
- CSR_OP_READ,
167
- CSR_OP_WRITE,
168
- CSR_OP_SET,
169
- CSR_OP_CLEAR
170
- } csr_op_e;
171
- // Privileged mode
172
- typedef enum logic[1:0] {
173
- PRIV_LVL_M = 2'b11,
174
- PRIV_LVL_H = 2'b10,
175
- PRIV_LVL_S = 2'b01,
176
- PRIV_LVL_U = 2'b00
177
- } priv_lvl_e;
178
- // Constants for the dcsr.xdebugver fields
179
- typedef enum logic[3:0] {
180
- XDEBUGVER_NO = 4'd0, // no external debug support
181
- XDEBUGVER_STD = 4'd4, // external debug according to RISC-V debug spec
182
- XDEBUGVER_NONSTD = 4'd15 // debug not conforming to RISC-V debug spec
183
- } x_debug_ver_e;
184
- //////////////
185
- // WB stage //
186
- //////////////
187
- // Type of instruction present in writeback stage
188
- typedef enum logic[1:0] {
189
- WB_INSTR_LOAD, // Instruction is awaiting load data
190
- WB_INSTR_STORE, // Instruction is awaiting store response
191
- WB_INSTR_OTHER // Instruction doesn't fit into above categories
192
- } wb_instr_type_e;
193
- //////////////
194
- // ID stage //
195
- //////////////
196
- // Operand a selection
197
- typedef enum logic[1:0] {
198
- OP_A_REG_A,
199
- OP_A_FWD,
200
- OP_A_CURRPC,
201
- OP_A_IMM
202
- } op_a_sel_e;
203
- // Immediate a selection
204
- typedef enum logic {
205
- IMM_A_Z,
206
- IMM_A_ZERO
207
- } imm_a_sel_e;
208
- // Operand b selection
209
- typedef enum logic {
210
- OP_B_REG_B,
211
- OP_B_IMM
212
- } op_b_sel_e;
213
- // Immediate b selection
214
- typedef enum logic [2:0] {
215
- IMM_B_I,
216
- IMM_B_S,
217
- IMM_B_B,
218
- IMM_B_U,
219
- IMM_B_J,
220
- IMM_B_INCR_PC,
221
- IMM_B_INCR_ADDR
222
- } imm_b_sel_e;
223
- // Regfile write data selection
224
- typedef enum {
225
- RF_WD_EX,
226
- RF_WD_CSR,
227
- RF_WD_COPROC // Only used when XInterface = 1
228
- } rf_wd_sel_e;
229
- //////////////
230
- // IF stage //
231
- //////////////
232
- // PC mux selection
233
- typedef enum logic [2:0] {
234
- PC_BOOT,
235
- PC_JUMP,
236
- PC_EXC,
237
- PC_ERET,
238
- PC_DRET,
239
- PC_BP
240
- } pc_sel_e;
241
- // Exception PC mux selection
242
- typedef enum logic [1:0] {
243
- EXC_PC_EXC,
244
- EXC_PC_IRQ,
245
- EXC_PC_DBD,
246
- EXC_PC_DBG_EXC // Exception while in debug mode
247
- } exc_pc_sel_e;
248
- // Interrupt requests
249
- typedef struct packed {
250
- logic irq_software;
251
- logic irq_timer;
252
- logic irq_external;
253
- logic [15:0] irq_fast; // 16 fast interrupts
254
- } irqs_t;
255
- // Exception cause
256
- typedef enum logic [6:0] {
257
- EXC_CAUSE_IRQ_SOFTWARE_M = {1'b1, 6'd03},
258
- EXC_CAUSE_IRQ_TIMER_M = {1'b1, 6'd07},
259
- EXC_CAUSE_IRQ_EXTERNAL_M = {1'b1, 6'd11},
260
- // EXC_CAUSE_IRQ_FAST_0 = {1'b1, 6'd16},
261
- // EXC_CAUSE_IRQ_FAST_15 = {1'b1, 6'd31},
262
- EXC_CAUSE_IRQ_NM = {1'b1, 6'd32},
263
- EXC_CAUSE_INSN_ADDR_MISA = {1'b0, 6'd00},
264
- EXC_CAUSE_INSTR_ACCESS_FAULT = {1'b0, 6'd01},
265
- EXC_CAUSE_ILLEGAL_INSN = {1'b0, 6'd02},
266
- EXC_CAUSE_BREAKPOINT = {1'b0, 6'd03},
267
- EXC_CAUSE_LOAD_ACCESS_FAULT = {1'b0, 6'd05},
268
- EXC_CAUSE_STORE_ACCESS_FAULT = {1'b0, 6'd07},
269
- EXC_CAUSE_ECALL_UMODE = {1'b0, 6'd08},
270
- EXC_CAUSE_ECALL_MMODE = {1'b0, 6'd11}
271
- } exc_cause_e;
272
- // Debug cause
273
- typedef enum logic [2:0] {
274
- DBG_CAUSE_NONE = 3'h0,
275
- DBG_CAUSE_EBREAK = 3'h1,
276
- DBG_CAUSE_TRIGGER = 3'h2,
277
- DBG_CAUSE_HALTREQ = 3'h3,
278
- DBG_CAUSE_STEP = 3'h4
279
- } dbg_cause_e;
280
- // PMP constants
281
- parameter int unsigned PMP_MAX_REGIONS = 16;
282
- parameter int unsigned PMP_CFG_W = 8;
283
- // PMP acces type
284
- parameter int unsigned PMP_I = 0;
285
- parameter int unsigned PMP_I2 = 1;
286
- parameter int unsigned PMP_D = 2;
287
- typedef enum logic [1:0] {
288
- PMP_ACC_EXEC = 2'b00,
289
- PMP_ACC_WRITE = 2'b01,
290
- PMP_ACC_READ = 2'b10
291
- } pmp_req_e;
292
- // PMP cfg structures
293
- typedef enum logic [1:0] {
294
- PMP_MODE_OFF = 2'b00,
295
- PMP_MODE_TOR = 2'b01,
296
- PMP_MODE_NA4 = 2'b10,
297
- PMP_MODE_NAPOT = 2'b11
298
- } pmp_cfg_mode_e;
299
- typedef struct packed {
300
- logic lock;
301
- pmp_cfg_mode_e mode;
302
- logic exec;
303
- logic write;
304
- logic read;
305
- } pmp_cfg_t;
306
- // Machine Security Configuration (ePMP)
307
- typedef struct packed {
308
- logic rlb; // Rule Locking Bypass
309
- logic mmwp; // Machine Mode Whitelist Policy
310
- logic mml; // Machine Mode Lockdown
311
- } pmp_mseccfg_t;
312
- // CSRs
313
- typedef enum logic[11:0] {
314
- // Machine information
315
- CSR_MVENDORID = 12'hF11,
316
- CSR_MARCHID = 12'hF12,
317
- CSR_MIMPID = 12'hF13,
318
- CSR_MHARTID = 12'hF14,
319
- CSR_MCONFIGPTR = 12'hF15,
320
- // Machine trap setup
321
- CSR_MSTATUS = 12'h300,
322
- CSR_MISA = 12'h301,
323
- CSR_MIE = 12'h304,
324
- CSR_MTVEC = 12'h305,
325
- CSR_MCOUNTEREN= 12'h306,
326
- CSR_MSTATUSH = 12'h310,
327
- CSR_MENVCFG = 12'h30A,
328
- CSR_MENVCFGH = 12'h31A,
329
- // Machine trap handling
330
- CSR_MSCRATCH = 12'h340,
331
- CSR_MEPC = 12'h341,
332
- CSR_MCAUSE = 12'h342,
333
- CSR_MTVAL = 12'h343,
334
- CSR_MIP = 12'h344,
335
- // Physical memory protection
336
- CSR_PMPCFG0 = 12'h3A0,
337
- CSR_PMPCFG1 = 12'h3A1,
338
- CSR_PMPCFG2 = 12'h3A2,
339
- CSR_PMPCFG3 = 12'h3A3,
340
- CSR_PMPADDR0 = 12'h3B0,
341
- CSR_PMPADDR1 = 12'h3B1,
342
- CSR_PMPADDR2 = 12'h3B2,
343
- CSR_PMPADDR3 = 12'h3B3,
344
- CSR_PMPADDR4 = 12'h3B4,
345
- CSR_PMPADDR5 = 12'h3B5,
346
- CSR_PMPADDR6 = 12'h3B6,
347
- CSR_PMPADDR7 = 12'h3B7,
348
- CSR_PMPADDR8 = 12'h3B8,
349
- CSR_PMPADDR9 = 12'h3B9,
350
- CSR_PMPADDR10 = 12'h3BA,
351
- CSR_PMPADDR11 = 12'h3BB,
352
- CSR_PMPADDR12 = 12'h3BC,
353
- CSR_PMPADDR13 = 12'h3BD,
354
- CSR_PMPADDR14 = 12'h3BE,
355
- CSR_PMPADDR15 = 12'h3BF,
356
- // ePMP control
357
- CSR_MSECCFG = 12'h747,
358
- CSR_MSECCFGH = 12'h757,
359
- // Debug trigger
360
- CSR_TSELECT = 12'h7A0,
361
- CSR_TDATA1 = 12'h7A1,
362
- CSR_TDATA2 = 12'h7A2,
363
- CSR_TDATA3 = 12'h7A3,
364
- CSR_MCONTEXT = 12'h7A8,
365
- CSR_SCONTEXT = 12'h7AA,
366
- // Debug/trace
367
- CSR_DCSR = 12'h7b0,
368
- CSR_DPC = 12'h7b1,
369
- // Debug
370
- CSR_DSCRATCH0 = 12'h7b2, // optional
371
- CSR_DSCRATCH1 = 12'h7b3, // optional
372
- // Machine Counter/Timers
373
- CSR_MCOUNTINHIBIT = 12'h320,
374
- CSR_MHPMEVENT3 = 12'h323,
375
- CSR_MHPMEVENT4 = 12'h324,
376
- CSR_MHPMEVENT5 = 12'h325,
377
- CSR_MHPMEVENT6 = 12'h326,
378
- CSR_MHPMEVENT7 = 12'h327,
379
- CSR_MHPMEVENT8 = 12'h328,
380
- CSR_MHPMEVENT9 = 12'h329,
381
- CSR_MHPMEVENT10 = 12'h32A,
382
- CSR_MHPMEVENT11 = 12'h32B,
383
- CSR_MHPMEVENT12 = 12'h32C,
384
- CSR_MHPMEVENT13 = 12'h32D,
385
- CSR_MHPMEVENT14 = 12'h32E,
386
- CSR_MHPMEVENT15 = 12'h32F,
387
- CSR_MHPMEVENT16 = 12'h330,
388
- CSR_MHPMEVENT17 = 12'h331,
389
- CSR_MHPMEVENT18 = 12'h332,
390
- CSR_MHPMEVENT19 = 12'h333,
391
- CSR_MHPMEVENT20 = 12'h334,
392
- CSR_MHPMEVENT21 = 12'h335,
393
- CSR_MHPMEVENT22 = 12'h336,
394
- CSR_MHPMEVENT23 = 12'h337,
395
- CSR_MHPMEVENT24 = 12'h338,
396
- CSR_MHPMEVENT25 = 12'h339,
397
- CSR_MHPMEVENT26 = 12'h33A,
398
- CSR_MHPMEVENT27 = 12'h33B,
399
- CSR_MHPMEVENT28 = 12'h33C,
400
- CSR_MHPMEVENT29 = 12'h33D,
401
- CSR_MHPMEVENT30 = 12'h33E,
402
- CSR_MHPMEVENT31 = 12'h33F,
403
- CSR_MCYCLE = 12'hB00,
404
- CSR_MINSTRET = 12'hB02,
405
- CSR_MHPMCOUNTER3 = 12'hB03,
406
- CSR_MHPMCOUNTER4 = 12'hB04,
407
- CSR_MHPMCOUNTER5 = 12'hB05,
408
- CSR_MHPMCOUNTER6 = 12'hB06,
409
- CSR_MHPMCOUNTER7 = 12'hB07,
410
- CSR_MHPMCOUNTER8 = 12'hB08,
411
- CSR_MHPMCOUNTER9 = 12'hB09,
412
- CSR_MHPMCOUNTER10 = 12'hB0A,
413
- CSR_MHPMCOUNTER11 = 12'hB0B,
414
- CSR_MHPMCOUNTER12 = 12'hB0C,
415
- CSR_MHPMCOUNTER13 = 12'hB0D,
416
- CSR_MHPMCOUNTER14 = 12'hB0E,
417
- CSR_MHPMCOUNTER15 = 12'hB0F,
418
- CSR_MHPMCOUNTER16 = 12'hB10,
419
- CSR_MHPMCOUNTER17 = 12'hB11,
420
- CSR_MHPMCOUNTER18 = 12'hB12,
421
- CSR_MHPMCOUNTER19 = 12'hB13,
422
- CSR_MHPMCOUNTER20 = 12'hB14,
423
- CSR_MHPMCOUNTER21 = 12'hB15,
424
- CSR_MHPMCOUNTER22 = 12'hB16,
425
- CSR_MHPMCOUNTER23 = 12'hB17,
426
- CSR_MHPMCOUNTER24 = 12'hB18,
427
- CSR_MHPMCOUNTER25 = 12'hB19,
428
- CSR_MHPMCOUNTER26 = 12'hB1A,
429
- CSR_MHPMCOUNTER27 = 12'hB1B,
430
- CSR_MHPMCOUNTER28 = 12'hB1C,
431
- CSR_MHPMCOUNTER29 = 12'hB1D,
432
- CSR_MHPMCOUNTER30 = 12'hB1E,
433
- CSR_MHPMCOUNTER31 = 12'hB1F,
434
- CSR_MCYCLEH = 12'hB80,
435
- CSR_MINSTRETH = 12'hB82,
436
- CSR_MHPMCOUNTER3H = 12'hB83,
437
- CSR_MHPMCOUNTER4H = 12'hB84,
438
- CSR_MHPMCOUNTER5H = 12'hB85,
439
- CSR_MHPMCOUNTER6H = 12'hB86,
440
- CSR_MHPMCOUNTER7H = 12'hB87,
441
- CSR_MHPMCOUNTER8H = 12'hB88,
442
- CSR_MHPMCOUNTER9H = 12'hB89,
443
- CSR_MHPMCOUNTER10H = 12'hB8A,
444
- CSR_MHPMCOUNTER11H = 12'hB8B,
445
- CSR_MHPMCOUNTER12H = 12'hB8C,
446
- CSR_MHPMCOUNTER13H = 12'hB8D,
447
- CSR_MHPMCOUNTER14H = 12'hB8E,
448
- CSR_MHPMCOUNTER15H = 12'hB8F,
449
- CSR_MHPMCOUNTER16H = 12'hB90,
450
- CSR_MHPMCOUNTER17H = 12'hB91,
451
- CSR_MHPMCOUNTER18H = 12'hB92,
452
- CSR_MHPMCOUNTER19H = 12'hB93,
453
- CSR_MHPMCOUNTER20H = 12'hB94,
454
- CSR_MHPMCOUNTER21H = 12'hB95,
455
- CSR_MHPMCOUNTER22H = 12'hB96,
456
- CSR_MHPMCOUNTER23H = 12'hB97,
457
- CSR_MHPMCOUNTER24H = 12'hB98,
458
- CSR_MHPMCOUNTER25H = 12'hB99,
459
- CSR_MHPMCOUNTER26H = 12'hB9A,
460
- CSR_MHPMCOUNTER27H = 12'hB9B,
461
- CSR_MHPMCOUNTER28H = 12'hB9C,
462
- CSR_MHPMCOUNTER29H = 12'hB9D,
463
- CSR_MHPMCOUNTER30H = 12'hB9E,
464
- CSR_MHPMCOUNTER31H = 12'hB9F,
465
- CSR_CPUCTRL = 12'h7C0,
466
- CSR_SECURESEED = 12'h7C1
467
- } csr_num_e;
468
- // CSR pmp-related offsets
469
- parameter logic [11:0] CSR_OFF_PMP_CFG = 12'h3A0; // pmp_cfg @ 12'h3a0 - 12'h3a3
470
- parameter logic [11:0] CSR_OFF_PMP_ADDR = 12'h3B0; // pmp_addr @ 12'h3b0 - 12'h3bf
471
- // CSR status bits
472
- parameter int unsigned CSR_MSTATUS_MIE_BIT = 3;
473
- parameter int unsigned CSR_MSTATUS_MPIE_BIT = 7;
474
- parameter int unsigned CSR_MSTATUS_MPP_BIT_LOW = 11;
475
- parameter int unsigned CSR_MSTATUS_MPP_BIT_HIGH = 12;
476
- parameter int unsigned CSR_MSTATUS_MPRV_BIT = 17;
477
- parameter int unsigned CSR_MSTATUS_TW_BIT = 21;
478
- // CSR machine ISA
479
- parameter logic [1:0] CSR_MISA_MXL = 2'd1; // M-XLEN: XLEN in M-Mode for RV32
480
- // CSR interrupt pending/enable bits
481
- parameter int unsigned CSR_MSIX_BIT = 3;
482
- parameter int unsigned CSR_MTIX_BIT = 7;
483
- parameter int unsigned CSR_MEIX_BIT = 11;
484
- parameter int unsigned CSR_MFIX_BIT_LOW = 16;
485
- parameter int unsigned CSR_MFIX_BIT_HIGH = 31;
486
- // CSR Machine Security Configuration bits
487
- parameter int unsigned CSR_MSECCFG_MML_BIT = 0;
488
- parameter int unsigned CSR_MSECCFG_MMWP_BIT = 1;
489
- parameter int unsigned CSR_MSECCFG_RLB_BIT = 2;
490
- // Machine Vendor ID - OpenHW JEDEC ID is '2 decimal (bank 13)'
491
- parameter MVENDORID_OFFSET = 7'h2; // Final byte without parity bit
492
- parameter MVENDORID_BANK = 25'hC; // Number of continuation codes
493
- // Machine Architecture ID (https://github.com/riscv/riscv-isa-manual/blob/master/marchid.md)
494
- parameter MARCHID = 32'd35;
495
- localparam logic [31:0] CSR_MVENDORID_VALUE = {MVENDORID_BANK, MVENDORID_OFFSET};
496
- localparam logic [31:0] CSR_MARCHID_VALUE = MARCHID;
497
- // Implementation ID
498
- // 0 indicates this field is not implemeted. cve2 implementors may wish to indicate an RTL/netlist
499
- // version here using their own unique encoding (e.g. 32 bits of the git hash of the implemented
500
- // commit).
501
- localparam logic [31:0] CSR_MIMPID_VALUE = 32'b0;
502
- // Machine Configuration Pointer
503
- // 0 indicates the configuration data structure does not eixst. cve2 implementors may wish to
504
- // alter this to point to their system specific configuration data structure.
505
- localparam logic [31:0] CSR_MCONFIGPTR_VALUE = 32'b0;
506
- // RVFI CSR element
507
- typedef struct packed {
508
- bit [63:0] rdata;
509
- bit [63:0] rmask;
510
- bit [63:0] wdata;
511
- bit [63:0] wmask;
512
- } rvfi_csr_elmt_t;
513
- // RVFI CSR structure
514
- typedef struct packed {
515
- rvfi_csr_elmt_t fflags;
516
- rvfi_csr_elmt_t frm;
517
- rvfi_csr_elmt_t fcsr;
518
- rvfi_csr_elmt_t ftran;
519
- rvfi_csr_elmt_t dcsr;
520
- rvfi_csr_elmt_t dpc;
521
- rvfi_csr_elmt_t dscratch0;
522
- rvfi_csr_elmt_t dscratch1;
523
- rvfi_csr_elmt_t sstatus;
524
- rvfi_csr_elmt_t sie;
525
- rvfi_csr_elmt_t sip;
526
- rvfi_csr_elmt_t stvec;
527
- rvfi_csr_elmt_t scounteren;
528
- rvfi_csr_elmt_t sscratch;
529
- rvfi_csr_elmt_t sepc;
530
- rvfi_csr_elmt_t scause;
531
- rvfi_csr_elmt_t stval;
532
- rvfi_csr_elmt_t satp;
533
- rvfi_csr_elmt_t mstatus;
534
- rvfi_csr_elmt_t mstatush;
535
- rvfi_csr_elmt_t misa;
536
- rvfi_csr_elmt_t medeleg;
537
- rvfi_csr_elmt_t mideleg;
538
- rvfi_csr_elmt_t mie;
539
- rvfi_csr_elmt_t mtvec;
540
- rvfi_csr_elmt_t mcounteren;
541
- rvfi_csr_elmt_t mscratch;
542
- rvfi_csr_elmt_t mepc;
543
- rvfi_csr_elmt_t mcause;
544
- rvfi_csr_elmt_t mtval;
545
- rvfi_csr_elmt_t mip;
546
- rvfi_csr_elmt_t menvcfg;
547
- rvfi_csr_elmt_t menvcfgh;
548
- rvfi_csr_elmt_t mvendorid;
549
- rvfi_csr_elmt_t marchid;
550
- rvfi_csr_elmt_t mhartid;
551
- rvfi_csr_elmt_t mcountinhibit;
552
- rvfi_csr_elmt_t mcycle;
553
- rvfi_csr_elmt_t mcycleh;
554
- rvfi_csr_elmt_t minstret;
555
- rvfi_csr_elmt_t minstreth;
556
- rvfi_csr_elmt_t cycle;
557
- rvfi_csr_elmt_t cycleh;
558
- rvfi_csr_elmt_t instret;
559
- rvfi_csr_elmt_t instreth;
560
- rvfi_csr_elmt_t dcache;
561
- rvfi_csr_elmt_t icache;
562
- rvfi_csr_elmt_t acc_cons;
563
- rvfi_csr_elmt_t pmpcfg0;
564
- rvfi_csr_elmt_t pmpcfg1;
565
- rvfi_csr_elmt_t pmpcfg2;
566
- rvfi_csr_elmt_t pmpcfg3;
567
- rvfi_csr_elmt_t pmpaddr0;
568
- rvfi_csr_elmt_t pmpaddr1;
569
- rvfi_csr_elmt_t pmpaddr2;
570
- rvfi_csr_elmt_t pmpaddr3;
571
- rvfi_csr_elmt_t pmpaddr4;
572
- rvfi_csr_elmt_t pmpaddr5;
573
- rvfi_csr_elmt_t pmpaddr6;
574
- rvfi_csr_elmt_t pmpaddr7;
575
- rvfi_csr_elmt_t pmpaddr8;
576
- rvfi_csr_elmt_t pmpaddr9;
577
- rvfi_csr_elmt_t pmpaddr10;
578
- rvfi_csr_elmt_t pmpaddr11;
579
- rvfi_csr_elmt_t pmpaddr12;
580
- rvfi_csr_elmt_t pmpaddr13;
581
- rvfi_csr_elmt_t pmpaddr14;
582
- rvfi_csr_elmt_t pmpaddr15;
583
- } rvfi_csr_t;
584
- // CV-X-IF
585
- parameter int unsigned X_NUM_RS = 3;
586
- parameter int unsigned X_ID_WIDTH = 4;
587
- parameter int unsigned X_RFR_WIDTH = 32;
588
- parameter int unsigned X_RFW_WIDTH = 32;
589
- parameter int unsigned X_HARTID_WIDTH = 32;
590
- parameter int unsigned X_DUAL_READ = 0;
591
- parameter int unsigned X_DUAL_WRITE = 0;
592
- parameter int unsigned X_INSTR_INFLIGHT = 2**X_ID_WIDTH;
593
- typedef logic [X_NUM_RS+X_DUAL_READ-1:0] readregflags_t;
594
- typedef logic [X_DUAL_WRITE:0] writeregflags_t;
595
- typedef logic [X_ID_WIDTH-1:0] id_t;
596
- typedef logic [X_HARTID_WIDTH-1:0] hartid_t;
597
- // Issue Interface
598
- typedef struct packed {
599
- logic [31:0] instr;
600
- hartid_t hartid;
601
- id_t id;
602
- } x_issue_req_t;
603
- typedef struct packed {
604
- logic accept;
605
- writeregflags_t writeback;
606
- readregflags_t register_read;
607
- } x_issue_resp_t;
608
- // Register Interface
609
- typedef struct packed {
610
- hartid_t hartid;
611
- id_t id;
612
- logic [X_NUM_RS-1:0][X_RFR_WIDTH-1:0] rs;
613
- readregflags_t rs_valid;
614
- } x_register_t;
615
- // Commit Interface
616
- typedef struct packed {
617
- hartid_t hartid;
618
- id_t id;
619
- logic commit_kill;
620
- } x_commit_t;
621
- // Result Interface
622
- typedef struct packed {
623
- hartid_t hartid;
624
- id_t id;
625
- logic [X_RFW_WIDTH-1:0] data;
626
- logic [4:0] rd;
627
- writeregflags_t we;
628
- } x_result_t;
629
- endpackage
630
- // Copyright (c) 2025 Eclipse Foundation
631
- // Copyright lowRISC contributors.
632
- // Copyright 2018 ETH Zurich and University of Bologna, see also CREDITS.md.
633
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
634
- // SPDX-License-Identifier: Apache-2.0
635
- /**
636
- * Fast Multiplier and Division
637
- *
638
- * 16x16 kernel multiplier and Long Division
639
- */
640
- // Copyright lowRISC contributors.
641
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
642
- // SPDX-License-Identifier: Apache-2.0
643
- // Macros and helper code for using assertions.
644
- // - Provides default clk and rst options to simplify code
645
- // - Provides boiler plate template for common assertions
646
- ///////////////////
647
- // Helper macros //
648
- ///////////////////
649
- // Default clk and reset signals used by assertion macros below.
650
- // Converts an arbitrary block of code into a Verilog string
651
- // ASSERT_ERROR logs an error message with either `uvm_error or with $error.
652
- //
653
- // This somewhat duplicates `DV_ERROR macro defined in hw/dv/sv/dv_utils/dv_macros.svh. The reason
654
- // for redefining it here is to avoid creating a dependency.
655
- // This macro is suitable for conditionally triggering lint errors, e.g., if a Sec parameter takes
656
- // on a non-default value. This may be required for pre-silicon/FPGA evaluation but we don't want
657
- // to allow this for tapeout.
658
- // The basic helper macros are actually defined in "implementation headers". The macros should do
659
- // the same thing in each case (except for the dummy flavour), but in a way that the respective
660
- // tools support.
661
- //
662
- // If the tool supports assertions in some form, we also define INC_ASSERT (which can be used to
663
- // hide signal definitions that are only used for assertions).
664
- //
665
- // The list of basic macros supported is:
666
- //
667
- // ASSERT_I: Immediate assertion. Note that immediate assertions are sensitive to simulation
668
- // glitches.
669
- //
670
- // ASSERT_INIT: Assertion in initial block. Can be used for things like parameter checking.
671
- //
672
- // ASSERT_INIT_NET: Assertion in initial block. Can be used for initial value of a net.
673
- //
674
- // ASSERT_FINAL: Assertion in final block. Can be used for things like queues being empty at end of
675
- // sim, all credits returned at end of sim, state machines in idle at end of sim.
676
- //
677
- // ASSERT: Assert a concurrent property directly. It can be called as a module (or
678
- // interface) body item.
679
- //
680
- // Note: We use (__rst !== '0) in the disable iff statements instead of (__rst ==
681
- // '1). This properly disables the assertion in cases when reset is X at the
682
- // beginning of a simulation. For that case, (reset == '1) does not disable the
683
- // assertion.
684
- //
685
- // ASSERT_NEVER: Assert a concurrent property NEVER happens
686
- //
687
- // ASSERT_KNOWN: Assert that signal has a known value (each bit is either '0' or '1') after reset.
688
- // It can be called as a module (or interface) body item.
689
- //
690
- // COVER: Cover a concurrent property
691
- //
692
- // ASSUME: Assume a concurrent property
693
- //
694
- // ASSUME_I: Assume an immediate property
695
- // Copyright lowRISC contributors.
696
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
697
- // SPDX-License-Identifier: Apache-2.0
698
- // Macro bodies included by prim_assert.sv for tools that don't support assertions. See
699
- // prim_assert.sv for documentation for each of the macros.
700
- //////////////////////////////
701
- // Complex assertion macros //
702
- //////////////////////////////
703
- // Assert that signal is an active-high pulse with pulse length of 1 clock cycle
704
- // Assert that a property is true only when an enable signal is set. It can be called as a module
705
- // (or interface) body item.
706
- // Assert that signal has a known value (each bit is either '0' or '1') after reset if enable is
707
- // set. It can be called as a module (or interface) body item.
708
- //////////////////////////////////
709
- // For formal verification only //
710
- //////////////////////////////////
711
- // Note that the existing set of ASSERT macros specified above shall be used for FPV,
712
- // thereby ensuring that the assertions are evaluated during DV simulations as well.
713
- // ASSUME_FPV
714
- // Assume a concurrent property during formal verification only.
715
- // ASSUME_I_FPV
716
- // Assume a concurrent property during formal verification only.
717
- // COVER_FPV
718
- // Cover a concurrent property during formal verification
719
- // Copyright lowRISC contributors.
720
- // Licensed under the Apache License, Version 2.0, see LICENSE for details.
721
- // SPDX-License-Identifier: Apache-2.0
722
- // // Macros and helper code for security countermeasures.
723
- // Helper macros
724
- // macros for security countermeasures
725
- // PRIM_ASSERT_SEC_CM_SVH
726
- // PRIM_ASSERT_SV
727
- module cve2_multdiv_fast #(
728
- parameter cve2_pkg::rv32m_e RV32M = cve2_pkg::RV32MFast
729
- ) (
730
- input logic clk_i,
731
- input logic rst_ni,
732
- input logic mult_en_i, // dynamic enable signal, for FSM control
733
- input logic div_en_i, // dynamic enable signal, for FSM control
734
- input logic mult_sel_i, // static decoder output, for data muxes
735
- input logic div_sel_i, // static decoder output, for data muxes
736
- input cve2_pkg::md_op_e operator_i,
737
- input logic [1:0] signed_mode_i,
738
- input logic [31:0] op_a_i,
739
- input logic [31:0] op_b_i,
740
- input logic [33:0] alu_adder_ext_i,
741
- input logic [31:0] alu_adder_i,
742
- input logic equal_to_zero_i,
743
- output logic [32:0] alu_operand_a_o,
744
- output logic [32:0] alu_operand_b_o,
745
- input logic [33:0] imd_val_q_i[2],
746
- output logic [33:0] imd_val_d_o[2],
747
- output logic [1:0] imd_val_we_o,
748
- output logic [31:0] multdiv_result_o,
749
- output logic valid_o
750
- );
751
- import cve2_pkg::*;
752
- // Both multiplier variants
753
- logic signed [34:0] mac_res_signed;
754
- logic [34:0] mac_res_ext;
755
- logic [33:0] accum;
756
- logic sign_a, sign_b;
757
- logic mult_valid;
758
- logic signed_mult;
759
- // Results that become intermediate value depending on whether mul or div is being calculated
760
- logic [33:0] mac_res_d, op_remainder_d;
761
- // Raw output of MAC calculation
762
- logic [33:0] mac_res;
763
- // Divider signals
764
- logic div_sign_a, div_sign_b;
765
- logic is_greater_equal;
766
- logic div_change_sign, rem_change_sign;
767
- logic [31:0] one_shift;
768
- logic [31:0] op_denominator_q;
769
- logic [31:0] op_numerator_q;
770
- logic [31:0] op_quotient_q;
771
- logic [31:0] op_denominator_d;
772
- logic [31:0] op_numerator_d;
773
- logic [31:0] op_quotient_d;
774
- logic [31:0] next_remainder;
775
- logic [32:0] next_quotient;
776
- logic [31:0] res_adder_h;
777
- logic div_valid;
778
- logic [ 4:0] div_counter_q, div_counter_d;
779
- logic multdiv_en;
780
- logic mult_hold;
781
- logic div_hold;
782
- logic div_by_zero_d, div_by_zero_q;
783
- logic mult_en_internal;
784
- logic div_en_internal;
785
- typedef enum logic [2:0] {
786
- MD_IDLE, MD_ABS_A, MD_ABS_B, MD_COMP, MD_LAST, MD_CHANGE_SIGN, MD_FINISH
787
- } md_fsm_e;
788
- md_fsm_e md_state_q, md_state_d;
789
- logic unused_mult_sel_i;
790
- assign unused_mult_sel_i = mult_sel_i;
791
- assign mult_en_internal = mult_en_i & ~mult_hold;
792
- assign div_en_internal = div_en_i & ~div_hold;
793
- always_ff @(posedge clk_i or negedge rst_ni) begin
794
- if (!rst_ni) begin
795
- div_counter_q <= '0;
796
- md_state_q <= MD_IDLE;
797
- op_numerator_q <= '0;
798
- op_quotient_q <= '0;
799
- div_by_zero_q <= '0;
800
- end else if (div_en_internal) begin
801
- div_counter_q <= div_counter_d;
802
- op_numerator_q <= op_numerator_d;
803
- op_quotient_q <= op_quotient_d;
804
- md_state_q <= md_state_d;
805
- div_by_zero_q <= div_by_zero_d;
806
- end
807
- end
808
- assign multdiv_en = mult_en_internal | div_en_internal;
809
- // Intermediate value register shared with ALU
810
- assign imd_val_d_o[0] = div_sel_i ? op_remainder_d : mac_res_d;
811
- assign imd_val_we_o[0] = multdiv_en;
812
- assign imd_val_d_o[1] = {2'b0, op_denominator_d};
813
- assign imd_val_we_o[1] = div_en_internal;
814
- assign op_denominator_q = imd_val_q_i[1][31:0];
815
- logic [1:0] unused_imd_val;
816
- assign unused_imd_val = imd_val_q_i[1][33:32];
817
- logic unused_mac_res_ext;
818
- assign unused_mac_res_ext = mac_res_ext[34];
819
- assign signed_mult = (signed_mode_i != 2'b00);
820
- assign multdiv_result_o = div_sel_i ? imd_val_q_i[0][31:0] : mac_res_d[31:0];
821
- // The single cycle multiplier uses three 17 bit multipliers to compute MUL instructions in a
822
- // single cycle and MULH instructions in two cycles.
823
- if (RV32M == RV32MSingleCycle) begin : gen_mult_single_cycle
824
- typedef enum logic {
825
- MULL, MULH
826
- } mult_fsm_e;
827
- mult_fsm_e mult_state_q, mult_state_d;
828
- logic signed [33:0] mult1_res, mult2_res, mult3_res;
829
- logic [33:0] mult1_res_uns;
830
- logic [33:32] unused_mult1_res_uns;
831
- logic [15:0] mult1_op_a, mult1_op_b;
832
- logic [15:0] mult2_op_a, mult2_op_b;
833
- logic [15:0] mult3_op_a, mult3_op_b;
834
- logic mult1_sign_a, mult1_sign_b;
835
- logic mult2_sign_a, mult2_sign_b;
836
- logic mult3_sign_a, mult3_sign_b;
837
- logic [33:0] summand1, summand2, summand3;
838
- assign mult1_res = $signed({mult1_sign_a, mult1_op_a}) * $signed({mult1_sign_b, mult1_op_b});
839
- assign mult2_res = $signed({mult2_sign_a, mult2_op_a}) * $signed({mult2_sign_b, mult2_op_b});
840
- assign mult3_res = $signed({mult3_sign_a, mult3_op_a}) * $signed({mult3_sign_b, mult3_op_b});
841
- assign mac_res_signed = $signed(summand1) + $signed(summand2) + $signed(summand3);
842
- assign mult1_res_uns = $unsigned(mult1_res);
843
- assign mac_res_ext = $unsigned(mac_res_signed);
844
- assign mac_res = mac_res_ext[33:0];
845
- assign sign_a = signed_mode_i[0] & op_a_i[31];
846
- assign sign_b = signed_mode_i[1] & op_b_i[31];
847
- // The first two multipliers are only used in state 1 (MULL). We can assign them statically.
848
- // al*bl
849
- assign mult1_sign_a = 1'b0;
850
- assign mult1_sign_b = 1'b0;
851
- assign mult1_op_a = op_a_i[15:0];
852
- assign mult1_op_b = op_b_i[15:0];
853
- // al*bh
854
- assign mult2_sign_a = 1'b0;
855
- assign mult2_sign_b = sign_b;
856
- assign mult2_op_a = op_a_i[15:0];
857
- assign mult2_op_b = op_b_i[31:16];
858
- // used in MULH
859
- assign accum[17:0] = imd_val_q_i[0][33:16];
860
- assign accum[33:18] = {16{signed_mult & imd_val_q_i[0][33]}};
861
- always_comb begin
862
- // Default values == MULL
863
- // ah*bl
864
- mult3_sign_a = sign_a;
865
- mult3_sign_b = 1'b0;
866
- mult3_op_a = op_a_i[31:16];
867
- mult3_op_b = op_b_i[15:0];
868
- summand1 = {18'h0, mult1_res_uns[31:16]};
869
- summand2 = $unsigned(mult2_res);
870
- summand3 = $unsigned(mult3_res);
871
- // mac_res = A*B[47:16], mult1_res = A*B[15:0]
872
- mac_res_d = {2'b0, mac_res[15:0], mult1_res_uns[15:0]};
873
- mult_valid = mult_en_i;
874
- mult_state_d = MULL;
875
- mult_hold = 1'b0;
876
- unique case (mult_state_q)
877
- MULL: begin
878
- if (operator_i != MD_OP_MULL) begin
879
- mac_res_d = mac_res;
880
- mult_valid = 1'b0;
881
- mult_state_d = MULH;
882
- end else begin
883
- mult_hold = 1'b0;
884
- end
885
- end
886
- MULH: begin
887
- // ah*bh
888
- mult3_sign_a = sign_a;
889
- mult3_sign_b = sign_b;
890
- mult3_op_a = op_a_i[31:16];
891
- mult3_op_b = op_b_i[31:16];
892
- mac_res_d = mac_res;
893
- summand1 = '0;
894
- summand2 = accum;
895
- summand3 = $unsigned(mult3_res);
896
- mult_state_d = MULL;
897
- mult_valid = 1'b1;
898
- mult_hold = 1'b0;
899
- end
900
- default: begin
901
- mult_state_d = MULL;
902
- end
903
- endcase // mult_state_q
904
- end
905
- always_ff @(posedge clk_i or negedge rst_ni) begin
906
- if (!rst_ni) begin
907
- mult_state_q <= MULL;
908
- end else begin
909
- if (mult_en_internal) begin
910
- mult_state_q <= mult_state_d;
911
- end
912
- end
913
- end
914
- assign unused_mult1_res_uns = mult1_res_uns[33:32];
915
- // States must be knwon/valid.
916
- // The fast multiplier uses one 17 bit multiplier to compute MUL instructions in 3 cycles
917
- // and MULH instructions in 4 cycles.
918
- end else begin : gen_mult_fast
919
- logic [15:0] mult_op_a;
920
- logic [15:0] mult_op_b;
921
- typedef enum logic [1:0] {
922
- ALBL, ALBH, AHBL, AHBH
923
- } mult_fsm_e;
924
- mult_fsm_e mult_state_q, mult_state_d;
925
- // The 2 MSBs of mac_res_ext (mac_res_ext[34:33]) are always equal since:
926
- // 1. The 2 MSBs of the multiplicants are always equal, and
927
- // 2. The 16 MSBs of the addend (accum[33:18]) are always equal.
928
- // Thus, it is safe to ignore mac_res_ext[34].
929
- assign mac_res_signed =
930
- $signed({sign_a, mult_op_a}) * $signed({sign_b, mult_op_b}) + $signed(accum);
931
- assign mac_res_ext = $unsigned(mac_res_signed);
932
- assign mac_res = mac_res_ext[33:0];
933
- always_comb begin
934
- mult_op_a = op_a_i[15:0];
935
- mult_op_b = op_b_i[15:0];
936
- sign_a = 1'b0;
937
- sign_b = 1'b0;
938
- accum = imd_val_q_i[0];
939
- mac_res_d = mac_res;
940
- mult_state_d = mult_state_q;
941
- mult_valid = 1'b0;
942
- mult_hold = 1'b0;
943
- unique case (mult_state_q)
944
- ALBL: begin
945
- // al*bl
946
- mult_op_a = op_a_i[15:0];
947
- mult_op_b = op_b_i[15:0];
948
- sign_a = 1'b0;
949
- sign_b = 1'b0;
950
- accum = '0;
951
- mac_res_d = mac_res;
952
- mult_state_d = ALBH;
953
- end
954
- ALBH: begin
955
- // al*bh<<16
956
- mult_op_a = op_a_i[15:0];
957
- mult_op_b = op_b_i[31:16];
958
- sign_a = 1'b0;
959
- sign_b = signed_mode_i[1] & op_b_i[31];
960
- // result of AL*BL (in imd_val_q_i[0]) always unsigned with no carry
961
- accum = {18'b0, imd_val_q_i[0][31:16]};
962
- if (operator_i == MD_OP_MULL) begin
963
- mac_res_d = {2'b0, mac_res[15:0], imd_val_q_i[0][15:0]};
964
- end else begin
965
- // MD_OP_MULH
966
- mac_res_d = mac_res;
967
- end
968
- mult_state_d = AHBL;
969
- end
970
- AHBL: begin
971
- // ah*bl<<16
972
- mult_op_a = op_a_i[31:16];
973
- mult_op_b = op_b_i[15:0];
974
- sign_a = signed_mode_i[0] & op_a_i[31];
975
- sign_b = 1'b0;
976
- if (operator_i == MD_OP_MULL) begin
977
- accum = {18'b0, imd_val_q_i[0][31:16]};
978
- mac_res_d = {2'b0, mac_res[15:0], imd_val_q_i[0][15:0]};
979
- mult_valid = 1'b1;
980
- // Note no state transition will occur if mult_hold is set
981
- mult_state_d = ALBL;
982
- mult_hold = 1'b0;
983
- end else begin
984
- accum = imd_val_q_i[0];
985
- mac_res_d = mac_res;
986
- mult_state_d = AHBH;
987
- end
988
- end
989
- AHBH: begin
990
- // only MD_OP_MULH here
991
- // ah*bh
992
- mult_op_a = op_a_i[31:16];
993
- mult_op_b = op_b_i[31:16];
994
- sign_a = signed_mode_i[0] & op_a_i[31];
995
- sign_b = signed_mode_i[1] & op_b_i[31];
996
- accum[17: 0] = imd_val_q_i[0][33:16];
997
- accum[33:18] = {16{signed_mult & imd_val_q_i[0][33]}};
998
- // result of AH*BL is not signed only if signed_mode_i == 2'b00
999
- mac_res_d = mac_res;
1000
- mult_valid = 1'b1;
1001
- // Note no state transition will occur if mult_hold is set
1002
- mult_state_d = ALBL;
1003
- mult_hold = 1'b0;
1004
- end
1005
- default: begin
1006
- mult_state_d = ALBL;
1007
- end
1008
- endcase // mult_state_q
1009
- end
1010
- always_ff @(posedge clk_i or negedge rst_ni) begin
1011
- if (!rst_ni) begin
1012
- mult_state_q <= ALBL;
1013
- end else begin
1014
- if (mult_en_internal) begin
1015
- mult_state_q <= mult_state_d;
1016
- end
1017
- end
1018
- end
1019
- // States must be knwon/valid.
1020
- end // gen_mult_fast
1021
- // Divider
1022
- assign res_adder_h = alu_adder_ext_i[32:1];
1023
- logic [1:0] unused_alu_adder_ext;
1024
- assign unused_alu_adder_ext = {alu_adder_ext_i[33],alu_adder_ext_i[0]};
1025
- assign next_remainder = is_greater_equal ? res_adder_h[31:0] : imd_val_q_i[0][31:0];
1026
- assign next_quotient = is_greater_equal ? {1'b0, op_quotient_q} | {1'b0, one_shift} :
1027
- {1'b0, op_quotient_q};
1028
- assign one_shift = {31'b0, 1'b1} << div_counter_q;
1029
- // The adder in the ALU computes alu_operand_a_o + alu_operand_b_o which means
1030
- // Remainder - Divisor. If Remainder - Divisor >= 0, is_greater_equal is equal to 1,
1031
- // the next Remainder is Remainder - Divisor contained in res_adder_h and the
1032
- always_comb begin
1033
- if ((imd_val_q_i[0][31] ^ op_denominator_q[31]) == 1'b0) begin
1034
- is_greater_equal = (res_adder_h[31] == 1'b0);
1035
- end else begin
1036
- is_greater_equal = imd_val_q_i[0][31];
1037
- end
1038
- end
1039
- assign div_sign_a = op_a_i[31] & signed_mode_i[0];
1040
- assign div_sign_b = op_b_i[31] & signed_mode_i[1];
1041
- assign div_change_sign = (div_sign_a ^ div_sign_b) & ~div_by_zero_q;
1042
- assign rem_change_sign = div_sign_a;
1043
- always_comb begin
1044
- div_counter_d = div_counter_q - 5'h1;
1045
- op_remainder_d = imd_val_q_i[0];
1046
- op_quotient_d = op_quotient_q;
1047
- md_state_d = md_state_q;
1048
- op_numerator_d = op_numerator_q;
1049
- op_denominator_d = op_denominator_q;
1050
- alu_operand_a_o = {32'h0 , 1'b1};
1051
- alu_operand_b_o = {~op_b_i, 1'b1};
1052
- div_valid = 1'b0;
1053
- div_hold = 1'b0;
1054
- div_by_zero_d = div_by_zero_q;
1055
- unique case (md_state_q)
1056
- MD_IDLE: begin
1057
- if (operator_i == MD_OP_DIV) begin
1058
- // Check if the Denominator is 0
1059
- // quotient for division by 0 is specified to be -1
1060
- // Note with data-independent time option, the full divide operation will proceed as
1061
- // normal and will naturally return -1
1062
- op_remainder_d = '1;
1063
- // SEC_CM: CORE.DATA_REG_SW.SCA
1064
- md_state_d = equal_to_zero_i ? MD_FINISH : MD_ABS_A;
1065
- // Record that this is a div by zero to stop the sign change at the end of the
1066
- // division (in data_ind_timing mode).
1067
- div_by_zero_d = equal_to_zero_i;
1068
- end else begin
1069
- // Check if the Denominator is 0
1070
- // remainder for division by 0 is specified to be the numerator (operand a)
1071
- // Note with data-independent time option, the full divide operation will proceed as
1072
- // normal and will naturally return operand a
1073
- op_remainder_d = {2'b0, op_a_i};
1074
- // SEC_CM: CORE.DATA_REG_SW.SCA
1075
- md_state_d = equal_to_zero_i ? MD_FINISH : MD_ABS_A;
1076
- end
1077
- // 0 - B = 0 iff B == 0
1078
- alu_operand_a_o = {32'h0 , 1'b1};
1079
- alu_operand_b_o = {~op_b_i, 1'b1};
1080
- div_counter_d = 5'd31;
1081
- end
1082
- MD_ABS_A: begin
1083
- // quotient
1084
- op_quotient_d = '0;
1085
- // A abs value
1086
- op_numerator_d = div_sign_a ? alu_adder_i : op_a_i;
1087
- md_state_d = MD_ABS_B;
1088
- div_counter_d = 5'd31;
1089
- // ABS(A) = 0 - A
1090
- alu_operand_a_o = {32'h0 , 1'b1};
1091
- alu_operand_b_o = {~op_a_i, 1'b1};
1092
- end
1093
- MD_ABS_B: begin
1094
- // remainder
1095
- op_remainder_d = { 33'h0, op_numerator_q[31]};
1096
- // B abs value
1097
- op_denominator_d = div_sign_b ? alu_adder_i : op_b_i;
1098
- md_state_d = MD_COMP;
1099
- div_counter_d = 5'd31;
1100
- // ABS(B) = 0 - B
1101
- alu_operand_a_o = {32'h0 , 1'b1};
1102
- alu_operand_b_o = {~op_b_i, 1'b1};
1103
- end
1104
- MD_COMP: begin
1105
- op_remainder_d = {1'b0, next_remainder[31:0], op_numerator_q[div_counter_d]};
1106
- op_quotient_d = next_quotient[31:0];
1107
- md_state_d = (div_counter_q == 5'd1) ? MD_LAST : MD_COMP;
1108
- // Division
1109
- alu_operand_a_o = {imd_val_q_i[0][31:0], 1'b1}; // it contains the remainder
1110
- alu_operand_b_o = {~op_denominator_q[31:0], 1'b1}; // -denominator two's compliment
1111
- end
1112
- MD_LAST: begin
1113
- if (operator_i == MD_OP_DIV) begin
1114
- // this time we save the quotient in op_remainder_d (i.e. imd_val_q_i[0]) since
1115
- // we do not need anymore the remainder
1116
- op_remainder_d = {1'b0, next_quotient};
1117
- end else begin
1118
- // this time we do not save the quotient anymore since we need only the remainder
1119
- op_remainder_d = {2'b0, next_remainder[31:0]};
1120
- end
1121
- // Division
1122
- alu_operand_a_o = {imd_val_q_i[0][31:0], 1'b1}; // it contains the remainder
1123
- alu_operand_b_o = {~op_denominator_q[31:0], 1'b1}; // -denominator two's compliment
1124
- md_state_d = MD_CHANGE_SIGN;
1125
- end
1126
- MD_CHANGE_SIGN: begin
1127
- md_state_d = MD_FINISH;
1128
- if (operator_i == MD_OP_DIV) begin
1129
- op_remainder_d = (div_change_sign) ? {2'h0, alu_adder_i} : imd_val_q_i[0];
1130
- end else begin
1131
- op_remainder_d = (rem_change_sign) ? {2'h0, alu_adder_i} : imd_val_q_i[0];
1132
- end
1133
- // ABS(Quotient) = 0 - Quotient (or Remainder)
1134
- alu_operand_a_o = {32'h0 , 1'b1};
1135
- alu_operand_b_o = {~imd_val_q_i[0][31:0], 1'b1};
1136
- end
1137
- MD_FINISH: begin
1138
- // Hold result until ID stage is ready to accept it
1139
- // Note no state transition will occur if div_hold is set
1140
- md_state_d = MD_IDLE;
1141
- div_hold = 1'b0;
1142
- div_valid = 1'b1;
1143
- end
1144
- default: begin
1145
- md_state_d = MD_IDLE;
1146
- end
1147
- endcase // md_state_q
1148
- end
1149
- assign valid_o = mult_valid | div_valid;
1150
- // States must be knwon/valid.
1151
- endmodule // cve2_mult
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RuC-datasets/RuC-cve2_b72358c7-32k/p9/mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"conditional_statement": [[33798, 33877], [25681, 25918], [33720, 33887], [35610, 36682], [25494, 25918]], "blocking_assignment": [[31264, 31284], [31291, 31311], [35339, 35375], [36529, 36561], [35460, 35484], [35904, 35924], [31522, 31537], [35489, 35513]], "always_construct": [[33663, 33895], [31014, 33658], [25439, 25924], [35121, 39504]], "case_statement": [[35556, 39498], [31318, 33650]], "ansi_port_declaration": [[23935, 23967], [23806, 23846], [23316, 23393], [23074, 23152], [23675, 23716], [23849, 23887], [23719, 23760], [23396, 23432]], "continuous_assign": [[39507, 39547], [26191, 26232], [25927, 25982], [26034, 26097], [26493, 26570], [26139, 26188], [30798, 30907]], "parameter_declaration": [[16755, 16799], [16993, 17037], [13622, 13688], [16708, 16752], [16946, 16990], [16850, 16895], [16802, 16847], [13551, 13619], [13787, 13814]], "nonblocking_assignment": [[33836, 33865], [25838, 25869]]}
 
 
RuC-datasets/RuC-tt07-32k/BTFLV-tt07-subleq-fram-cpu/all_mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"module_program_interface_instantiation": [[1761, 2124], [2127, 2205], [2208, 2375]], "continuous_assign": [[509, 535], [538, 564], [566, 599], [601, 631], [633, 662], [664, 692], [694, 718], [720, 745], [747, 775], [778, 812], [814, 853], [855, 893], [7033, 7068], [7073, 7109], [7114, 7164], [7169, 7194]], "blocking_assignment": [[5332, 5350], [5390, 5412], [5429, 5451], [5468, 5511], [5528, 5550], [5567, 5589], [5606, 5649], [5666, 5688], [5705, 5727], [5744, 5787], [5804, 5827], [5844, 5867], [5884, 5929], [5946, 5969], [5986, 6009], [6026, 6071], [6088, 6133], [6150, 6172], [6189, 6232], [6249, 6271], [6288, 6306]], "nonblocking_assignment": [[2856, 2871], [2882, 2902], [2978, 3004], [3008, 3034], [3038, 3064], [3068, 3094], [3098, 3124], [3128, 3154], [3158, 3183], [3187, 3212], [3216, 3242], [3246, 3272], [3276, 3301], [3359, 3374], [3380, 3397], [3452, 3467], [3473, 3490], [3526, 3543], [3579, 3601], [3637, 3656], [3662, 3679], [3715, 3732], [3768, 3790], [3826, 3845], [3851, 3868], [3904, 3921], [3957, 3979], [4034, 4051], [4057, 4074], [4111, 4128], [4165, 4189], [4253, 4278], [4285, 4314], [4321, 4347], [4354, 4379], [4406, 4423], [4430, 4447], [4487, 4506], [4552, 4577], [4583, 4608], [4672, 4688], [4715, 4739], [4841, 4859], [4866, 4883], [4890, 4907], [4934, 4954], [4961, 4981], [4988, 5008], [5015, 5037], [5082, 5099], [5135, 5188], [5194, 5209], [5241, 5260], [6393, 6410], [6469, 6486], [6509, 6526], [7700, 7716], [7729, 7745], [7824, 7840], [7857, 7877], [7921, 7944], [8069, 8086], [8099, 8116], [8129, 8146], [8159, 8176], [8189, 8206], [8219, 8236], [8331, 8341], [8419, 8433], [8458, 8482], [8562, 8576], [8601, 8615], [8640, 8654], [8679, 8693], [8856, 8894], [8919, 8940], [8979, 9010], [9070, 9087], [9112, 9139], [9164, 9181], [9206, 9223], [9392, 9430], [9455, 9476], [9515, 9546], [9606, 9623], [9648, 9665], [9690, 9707], [9732, 9749], [9899, 9930], [9990, 10007], [10032, 10049], [10209, 10229], [10268, 10307], [10346, 10377], [10513, 10541], [10669, 10696], [10753, 10770], [10795, 10812], [10837, 10854], [10879, 10896], [10921, 10943], [11055, 11067], [11156, 11167], [11279, 11291], [11422, 11434], [11506, 11544], [11569, 11590], [11629, 11660], [11720, 11737], [11762, 11779], [11804, 11821], [11846, 11863], [11974, 11986], [12007, 12019], [12145, 12176], [12236, 12253], [12278, 12295], [12320, 12348], [12461, 12473], [12545, 12584], [12609, 12630], [12669, 12700], [12760, 12777], [12802, 12829], [12854, 12871], [12896, 12914], [13096, 13134], [13159, 13180], [13219, 13250], [13310, 13327], [13352, 13369], [13394, 13412], [13481, 13509], [13577, 13605], [13839, 13881], [13949, 13991], [14044, 14064], [14103, 14134], [14194, 14211], [14236, 14253], [14278, 14295], [14320, 14338], [14363, 14385], [14504, 14516], [14537, 14550], [14677, 14708], [14768, 14785], [14810, 14828], [14853, 14880], [15009, 15021], [15093, 15131], [15156, 15177], [15216, 15247], [15307, 15324], [15349, 15366], [15391, 15408], [15433, 15451], [15563, 15575], [15664, 15675], [15787, 15799], [15954, 15985], [16045, 16062], [16087, 16104], [16129, 16146], [17585, 17603], [17616, 17634], [17647, 17665], [17678, 17706], [17719, 17737], [17750, 17771], [17784, 17805], [17903, 17925], [17946, 17968], [17989, 18011], [18032, 18054], [18075, 18098], [18119, 18141], [18162, 18188], [18209, 18231], [18252, 18274], [18295, 18318], [18339, 18361], [18382, 18403], [18534, 18567], [18627, 18645], [18670, 18692], [18787, 18805], [18826, 18853], [18874, 18899], [19033, 19064], [19124, 19141], [19229, 19260], [19344, 19355], [19392, 19414], [19451, 19473], [19510, 19532], [19569, 19591], [19628, 19650], [19687, 19709], [19746, 19768], [19805, 19827], [19864, 19875], [19979, 19996], [20086, 20119], [20152, 20194], [20270, 20288], [20321, 20342], [21111, 21132], [21145, 21166], [21179, 21200], [21213, 21231], [21244, 21262], [21275, 21293], [21382, 21403], [21420, 21441], [21458, 21482], [21499, 21517], [21534, 21552], [21569, 21590], [21713, 21746], [21798, 21816], [21888, 21916], [21941, 21971], [21996, 22027], [22109, 22129], [22154, 22185], [22245, 22266], [22291, 22312], [22337, 22355]], "case_statement": [[3322, 5280], [5361, 6317], [8272, 16210], [17841, 20466], [19289, 19911]], "conditional_statement": [[2841, 2902], [2957, 5286], [4226, 4456], [4462, 4515], [4645, 4748], [4814, 5046], [5314, 6317], [6372, 6539], [6431, 6533], [7670, 7972], [7781, 7960], [8039, 16222], [8362, 8717], [8512, 8717], [8805, 9247], [8965, 9010], [9340, 9773], [9501, 9546], [9848, 10073], [10158, 10967], [10254, 10307], [10332, 10377], [10437, 10728], [11088, 11319], [11455, 11887], [11615, 11660], [12094, 12372], [12494, 12938], [12655, 12700], [13044, 13657], [13205, 13250], [13437, 13633], [13744, 14409], [13795, 14019], [14089, 14134], [14626, 14904], [15042, 15475], [15202, 15247], [15596, 15827], [15903, 16170], [17555, 20478], [18473, 18716], [18973, 20426], [19166, 20402], [20025, 20374], [21081, 22427], [21329, 22415], [21612, 22415], [21652, 22399], [21837, 22379], [22057, 22379]], "always_construct": [[2794, 2907], [2910, 5291], [5294, 6322], [6325, 6544], [7617, 7980], [7986, 16230], [17502, 20486], [21028, 22435]], "parameter_declaration": [[7484, 7512], [7517, 7545], [7550, 7578], [7583, 7611], [16694, 16736], [16741, 16788], [16793, 16849], [16854, 16926], [16931, 16972]], "ansi_port_declaration": [[52, 98], [100, 147], [149, 194], [196, 242], [244, 323], [325, 412], [414, 449], [451, 503], [6590, 6622], [6627, 6659], [6664, 6696], [6701, 6733], [6738, 6770], [6775, 6807], [6812, 6844], [6849, 6881], [6886, 6918], [6923, 6955], [6960, 6992], [6997, 7024], [16269, 16291], [16296, 16318], [16323, 16341], [20529, 20560], [20565, 20596], [20601, 20632], [20637, 20668], [20673, 20704], [20709, 20738]]}
 
 
RuC-datasets/RuC-tt07-32k/BTFLV-tt07-subleq-fram-cpu/mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"conditional_statement": [[15596, 15827], [20025, 20374], [9848, 10073], [22057, 22379], [8805, 9247], [5314, 6317]], "blocking_assignment": [[5884, 5929], [6150, 6172], [6288, 6306], [5429, 5451], [5606, 5649]], "module_program_interface_instantiation": [[1761, 2124], [2127, 2205], [2208, 2375]], "always_construct": [[7986, 16230], [5294, 6322], [2910, 5291]], "case_statement": [[17841, 20466], [8272, 16210], [3322, 5280], [5361, 6317], [19289, 19911]], "ansi_port_declaration": [[414, 449], [20709, 20738], [6812, 6844], [6738, 6770]], "continuous_assign": [[7033, 7068], [747, 775], [7073, 7109], [720, 745]], "parameter_declaration": [[16931, 16972], [7517, 7545], [7583, 7611], [7550, 7578], [7484, 7512], [16854, 16926], [16793, 16849]], "nonblocking_assignment": [[4890, 4907], [6393, 6410], [18032, 18054], [5082, 5099], [8331, 8341], [17946, 17968], [11156, 11167], [4988, 5008]]}
 
 
RuC-datasets/RuC-tt07-32k/BTFLV-tt07-subleq-fram-cpu/tt_um_btflv_subleq.v DELETED
@@ -1,717 +0,0 @@
1
- `default_nettype none
2
-
3
- module tt_um_btflv_subleq (
4
- input wire [7:0] ui_in , // Dedicated inputs
5
- output wire [7:0] uo_out , // Dedicated outputs
6
- input wire [7:0] uio_in , // IOs: Input path
7
- output wire [7:0] uio_out, // IOs: Output path
8
- output wire [7:0] uio_oe , // IOs: Enable path (active high: 0=input, 1=output)
9
- input wire ena , // always 1 when the design is powered, so you can ignore it
10
- input wire clk , // clock
11
- input wire rst_n // reset_n - low to reset
12
- );
13
-
14
- assign in_miso = ui_in[0];
15
-
16
- assign uio_out = data;
17
- assign uio_oe = 8'b11111111;
18
- assign uo_out[0] = out_mosi;
19
- assign uo_out[1] = out_sck;
20
- assign uo_out[2] = out_cs;
21
- assign uo_out[3] = tx;
22
- assign uo_out[4] = ctx;
23
- assign uo_out[7:5] = 3'b111;
24
-
25
- assign char_out = data_a[7:0];
26
- assign char_valid = char_output_flag;
27
- assign result = data_b - data_a;
28
-
29
- reg signed [15:0] ir_a, ir_b, ir_c;
30
- reg signed [15:0] data_a, data_b;
31
- reg [ 5:0] state, next_state;
32
- reg [ 7:0] data ;
33
- reg [15:0] pc ;
34
- reg char_output_flag;
35
- reg halted_reg ;
36
- reg signed [15:0] data_to_ram ;
37
- reg ram_we ;
38
- reg [15:0] ram_addr ;
39
- reg tx_start ;
40
- reg ramstart ;
41
-
42
- wire ramdone ;
43
- wire [ 7:0] char_out ;
44
- wire char_valid ;
45
- wire [15:0] data_from_ram;
46
- wire tx_busy ;
47
- wire ctx ;
48
- wire tx ;
49
- wire signed [15:0] result ;
50
- wire in_miso ;
51
- wire out_mosi ;
52
- wire out_sck ;
53
- wire out_cs ;
54
-
55
- SPI_FRAM_Interface ram (
56
- .clk (clk ),
57
- .rst_n (rst_n ),
58
- .addr (ram_addr ),
59
- .spi_miso(in_miso ),
60
- .spi_mosi(out_mosi ),
61
- .spi_sck (out_sck ),
62
- .spi_cs (out_cs ),
63
- .data_in (data_to_ram ),
64
- .we (ram_we ),
65
- .start (ramstart ),
66
- .done (ramdone ),
67
- .data_out(data_from_ram)
68
- );
69
-
70
- UART_Credits CreditsTX (
71
- .clk (clk ),
72
- .rst_n(rst_n),
73
- .tx (ctx )
74
- );
75
-
76
- UART_Transmitter uart_tx (
77
- .clk (clk ),
78
- .rst_n (rst_n ),
79
- .tx_start(tx_start),
80
- .tx_data (char_out),
81
- .tx (tx ),
82
- .tx_busy (tx_busy )
83
- );
84
-
85
- localparam START = 6'd0,
86
- FETCH_A0 = 6'd1,
87
- FETCH_A1 = 6'd2,
88
- FETCH_A2 = 6'd3,
89
- FETCH_B0 = 6'd4,
90
- FETCH_B1 = 6'd5,
91
- FETCH_B2 = 6'd6,
92
- FETCH_C0 = 6'd7,
93
- FETCH_C1 = 6'd8,
94
- FETCH_C2 = 6'd9,
95
- DECODE_A0 = 6'd10,
96
- DECODE_A1 = 6'd11,
97
- DECODE_A2 = 6'd12,
98
- DECODE_B0 = 6'd13,
99
- DECODE_B1 = 6'd14,
100
- DECODE_B2 = 6'd15,
101
- WRITE_B0 = 6'd16,
102
- WRITE_B1 = 6'd17,
103
- WRITE_B2 = 6'd18,
104
- HALT = 6'd19;
105
-
106
-
107
-
108
- always @(posedge clk or negedge rst_n) begin
109
- if (!rst_n)
110
- state <= START;
111
- else
112
- state <= next_state;
113
- end
114
-
115
- always @(posedge clk or negedge rst_n) begin
116
- if (!rst_n) begin
117
- pc <= 15'd0;
118
- ir_a <= 16'b0;
119
- ir_b <= 16'b0;
120
- ir_c <= 16'b0;
121
- data_a <= 16'b0;
122
- data_b <= 16'b0;
123
- char_output_flag <= 1'b0;
124
- halted_reg <= 1'b0;
125
- data_to_ram <= 16'b0;
126
- ram_addr <= 15'b0;
127
- ram_we <= 1'b0;
128
- end else begin
129
- case (state)
130
-
131
- START : begin
132
- ram_addr <= pc;
133
- ramstart <= 1'b1;
134
- end
135
-
136
- // Fetch A B C
137
- FETCH_A0 : begin
138
- ram_addr <= pc;
139
- ramstart <= 1'b1;
140
- end
141
-
142
- FETCH_A1 : begin
143
- ramstart <= 1'b0;
144
- end
145
-
146
- FETCH_A2 : begin
147
- ir_a <= data_from_ram;
148
- end
149
-
150
- FETCH_B0 : begin
151
- ram_addr <= pc + 1;
152
- ramstart <= 1'b1;
153
- end
154
-
155
- FETCH_B1 : begin
156
- ramstart <= 1'b0;
157
- end
158
-
159
- FETCH_B2 : begin
160
- ir_b <= data_from_ram;
161
- end
162
-
163
- FETCH_C0 : begin
164
- ram_addr <= pc + 2;
165
- ramstart <= 1'b1;
166
- end
167
-
168
- FETCH_C1 : begin
169
- ramstart <= 1'b0;
170
- end
171
-
172
- FETCH_C2 : begin
173
- ir_c <= data_from_ram;
174
- end
175
-
176
- // Decode A B
177
- DECODE_A0 : begin
178
- ram_addr <= ir_a;
179
- ramstart <= 1'b1;
180
- end
181
-
182
- DECODE_A1 : begin
183
- ramstart <= 1'b0;
184
- end
185
-
186
- DECODE_A2 : begin
187
- data_a <= data_from_ram;
188
- end
189
-
190
- DECODE_B0 : begin
191
- if(ir_b == -1) begin
192
- char_output_flag <= 1'b1;
193
- data <= char_out;
194
- ram_addr <= 16'b0;
195
- ramstart <= 1'b1;
196
- end else begin
197
- ram_addr <= ir_b;
198
- ramstart <= 1'b1;
199
- end
200
- if(ir_c < 0) begin
201
- halted_reg <= 1'b1;
202
- end
203
- end
204
-
205
- DECODE_B1 : begin
206
- ramstart <= 1'b0;
207
- char_output_flag <= 1'b0;
208
- end
209
-
210
- DECODE_B2 : begin
211
- if(ir_b == -1) begin
212
- data_b <= 16'b0;
213
- end else begin
214
- data_b <= data_from_ram;
215
- end
216
- end
217
-
218
- // Write B-A to address B
219
- WRITE_B0 : begin
220
- if(ir_b == -1) begin
221
- ram_addr <= 16'b0;
222
- ramstart <= 1'b1;
223
- ram_we <= 1'b0;
224
- end else begin
225
- ram_addr <= ir_b;
226
- ramstart <= 1'b1;
227
- ram_we <= 1'b1;
228
- data_to_ram <= result;
229
- end
230
- end
231
-
232
- WRITE_B1 : begin
233
- ramstart <= 1'b0;
234
- end
235
-
236
- WRITE_B2 : begin
237
- pc <= (result > 0 || ir_b == -1) ? pc + 3 : ir_c;
238
- ram_we <= 1'b0;
239
- end
240
-
241
- HALT : begin
242
- halted_reg <= 1'b1;
243
- end
244
-
245
- endcase
246
- end
247
- end
248
-
249
- always @(*) begin
250
- if(halted_reg)
251
- next_state = HALT;
252
- else
253
- case (state)
254
- START : next_state = FETCH_A0;
255
- FETCH_A0 : next_state = FETCH_A1;
256
- FETCH_A1 : next_state = ramdone ? FETCH_A2 : FETCH_A1;
257
- FETCH_A2 : next_state = FETCH_B0;
258
- FETCH_B0 : next_state = FETCH_B1;
259
- FETCH_B1 : next_state = ramdone ? FETCH_B2 : FETCH_B1;
260
- FETCH_B2 : next_state = FETCH_C0;
261
- FETCH_C0 : next_state = FETCH_C1;
262
- FETCH_C1 : next_state = ramdone ? FETCH_C2 : FETCH_C1;
263
- FETCH_C2 : next_state = DECODE_A0;
264
- DECODE_A0 : next_state = DECODE_A1;
265
- DECODE_A1 : next_state = ramdone ? DECODE_A2 : DECODE_A1;
266
- DECODE_A2 : next_state = DECODE_B0;
267
- DECODE_B0 : next_state = DECODE_B1;
268
- DECODE_B1 : next_state = ramdone ? DECODE_B2 : DECODE_B1;
269
- DECODE_B2 : next_state = !tx_busy ? WRITE_B0 : DECODE_B2;
270
- WRITE_B0 : next_state = WRITE_B1;
271
- WRITE_B1 : next_state = ramdone ? WRITE_B2 : WRITE_B1;
272
- WRITE_B2 : next_state = FETCH_A0;
273
- HALT : next_state = HALT;
274
- endcase
275
- end
276
-
277
- always @(posedge clk or negedge rst_n) begin
278
- if (!rst_n) begin
279
- tx_start <= 1'b0;
280
- end else begin
281
- if (char_valid && !tx_busy) begin
282
- tx_start <= 1'b1;
283
- end else begin
284
- tx_start <= 1'b0;
285
- end
286
- end
287
- end
288
-
289
- endmodule
290
-
291
-
292
- module SPI_FRAM_Interface (
293
- input wire clk ,
294
- input wire rst_n ,
295
- input spi_miso,
296
- output reg spi_mosi,
297
- output reg spi_sck ,
298
- output reg spi_cs ,
299
- input wire [15:0] addr ,
300
- input wire [15:0] data_in ,
301
- input wire we ,
302
- input wire start ,
303
- output reg [15:0] data_out,
304
- output reg done
305
- );
306
-
307
- assign write_data_l = data_in[7:0];
308
- assign write_data_h = data_in[15:8];
309
- assign address = (addr[14:0] << 1) + !hbyte;
310
- assign write_enable = we;
311
-
312
- reg [7:0] temp_data ;
313
- reg [4:0] state ;
314
- reg [4:0] bit_counter;
315
- reg [5:0] spi_clk ;
316
- reg clk_out ;
317
- reg hbyte ;
318
-
319
- wire [ 7:0] write_data_l;
320
- wire [ 7:0] write_data_h;
321
- wire write_enable;
322
- wire [15:0] address ;
323
-
324
- parameter CMD_READ = 8'h03;
325
- parameter CMD_WRITE = 8'h02;
326
- parameter CMD_WREN = 8'h06;
327
- parameter CMD_WRDI = 8'h04;
328
-
329
- always @(posedge clk or negedge rst_n) begin
330
- if (!rst_n) begin
331
- spi_clk <= 6'd0;
332
- clk_out <= 1'b0;
333
- end else begin
334
- if (spi_clk == 6'd7) begin
335
- spi_clk <= 6'd0;
336
- clk_out <= ~clk_out;
337
- end else begin
338
- spi_clk <= spi_clk + 1;
339
- end
340
- end
341
- end
342
-
343
- always @(posedge clk or negedge rst_n) begin
344
- if (!rst_n) begin
345
- spi_cs <= 1;
346
- spi_sck <= 0;
347
- spi_mosi <= 0;
348
- state <= 0;
349
- bit_counter <= 0;
350
- hbyte <= 0;
351
- end else begin
352
- case (state)
353
- 0 : begin
354
- done <= 0;
355
- if (start && write_enable) begin
356
- state <= 6;
357
- spi_mosi <= CMD_WREN[7];
358
- end else if (start || hbyte) begin
359
- state <= 1;
360
- spi_cs <= 0;
361
- spi_mosi <= 0;
362
- spi_sck <= 0;
363
- end
364
- end
365
- 1 : begin // Send read command
366
- if (bit_counter < 8) begin
367
- spi_mosi <= CMD_READ[7 - bit_counter];
368
- spi_sck <= ~spi_sck;
369
- if (!spi_sck) bit_counter <= bit_counter + 1;
370
- end else begin
371
- bit_counter <= 0;
372
- spi_mosi <= address[15];
373
- spi_sck <= 0;
374
- state <= 2;
375
- end
376
- end
377
- 2 : begin // Send address (16 bits)
378
- if (bit_counter < 16) begin
379
- spi_mosi <= address[15 - bit_counter];
380
- spi_sck <= ~spi_sck;
381
- if (!spi_sck) bit_counter <= bit_counter + 1;
382
- end else begin
383
- bit_counter <= 0;
384
- spi_mosi <= 0;
385
- spi_sck <= 0;
386
- state <= 3;
387
- end
388
- end
389
- 3 : begin // Wait
390
- if (bit_counter < 8) begin
391
- bit_counter <= bit_counter + 1;
392
- end else begin
393
- bit_counter <= 0;
394
- state <= 4;
395
- end
396
- end
397
- 4 : begin // Read data byte
398
- if (bit_counter < 8) begin
399
- spi_sck <= ~spi_sck;
400
- if (~spi_sck) temp_data[7 - bit_counter] <= spi_miso;
401
- if (!spi_sck) bit_counter <= bit_counter + 1;
402
- end else begin
403
- if(hbyte)
404
- begin
405
- data_out[15:8] <= temp_data;
406
- end
407
- else
408
- begin
409
- data_out[7:0] <= temp_data;
410
- end
411
- bit_counter <= 0;
412
- spi_mosi <= 0;
413
- spi_sck <= 0;
414
- state <= 5;
415
- hbyte <= ~hbyte;
416
- end
417
- end
418
- 5 : begin // End communication
419
- spi_cs <= 1;
420
- if(hbyte)
421
- begin
422
- state <= 0;
423
- end
424
- else
425
- begin
426
- state <= 16;
427
- end
428
- end
429
- 6 : begin // Send Write Enable (WREN) command
430
- spi_cs <= 0;
431
- if (bit_counter < 8) begin
432
- spi_mosi <= CMD_WREN[7 - bit_counter];
433
- spi_sck <= ~spi_sck;
434
- if (!spi_sck) bit_counter <= bit_counter + 1;
435
- end else begin
436
- bit_counter <= 0;
437
- spi_mosi <= 0;
438
- spi_sck <= 0;
439
- state <= 7;
440
- end
441
- end
442
- 7 : begin // End WREN command
443
- spi_cs <= 1;
444
- state <= 8;
445
- end
446
- 8 : begin // Wait
447
- if (bit_counter < 8) begin
448
- bit_counter <= bit_counter + 1;
449
- end else begin
450
- bit_counter <= 0;
451
- state <= 9;
452
- spi_mosi <= CMD_WRITE[7];
453
- end
454
- end
455
- 9 : begin // Send write command
456
- spi_cs <= 0;
457
- if (bit_counter < 8) begin
458
- spi_mosi <= CMD_WRITE[7 - bit_counter];
459
- spi_sck <= ~spi_sck;
460
- if (!spi_sck) bit_counter <= bit_counter + 1;
461
- end else begin
462
- bit_counter <= 0;
463
- spi_mosi <= address[15];
464
- spi_sck <= 0;
465
- state <= 10;
466
- end
467
- end
468
- 10 : begin // Send address (16 bits) for writing
469
- if (bit_counter < 16) begin
470
- spi_mosi <= address[15 - bit_counter];
471
- spi_sck <= ~spi_sck;
472
- if (!spi_sck) bit_counter <= bit_counter + 1;
473
- end else begin
474
- bit_counter <= 0;
475
- spi_sck <= 0;
476
- state <= 11;
477
- if(hbyte) begin
478
- spi_mosi <= write_data_h[7];
479
- end else begin
480
- spi_mosi <= write_data_l[7];
481
- end
482
- end
483
- end
484
- 11 : begin // Write data byte
485
- if (bit_counter < 8) begin
486
- if(hbyte) begin
487
- spi_mosi <= write_data_h[7 - bit_counter];
488
- end else begin
489
- spi_mosi <= write_data_l[7 - bit_counter];
490
- end
491
- spi_sck <= ~spi_sck;
492
- if (!spi_sck) bit_counter <= bit_counter + 1;
493
- end else begin
494
- bit_counter <= 0;
495
- spi_mosi <= 0;
496
- spi_sck <= 0;
497
- state <= 12;
498
- hbyte <= ~hbyte;
499
- end
500
- end
501
- 12 : begin // End write communication
502
- spi_cs <= 1;
503
- state <= 13;
504
- end
505
- 13 : begin // Wait
506
- if (bit_counter < 8) begin
507
- bit_counter <= bit_counter + 1;
508
- end else begin
509
- bit_counter <= 0;
510
- state <= 14;
511
- spi_mosi <= CMD_WRDI[7];
512
- end
513
- end
514
- 14 : begin // Send Write Disable (WRDI) command
515
- spi_cs <= 0;
516
- if (bit_counter < 8) begin
517
- spi_mosi <= CMD_WRDI[7 - bit_counter];
518
- spi_sck <= ~spi_sck;
519
- if (!spi_sck) bit_counter <= bit_counter + 1;
520
- end else begin
521
- bit_counter <= 0;
522
- spi_mosi <= 0;
523
- spi_sck <= 0;
524
- state <= 15;
525
- end
526
- end
527
- 15 : begin // End WRDI command
528
- spi_cs <= 1;
529
- if(hbyte)
530
- begin
531
- state <= 6;
532
- end
533
- else
534
- begin
535
- state <= 16;
536
- end
537
- end
538
- 16 : begin // Wait
539
- if (bit_counter < 8) begin
540
- bit_counter <= bit_counter + 1;
541
- end else begin
542
- bit_counter <= 0;
543
- state <= 0;
544
- done <= 1;
545
- end
546
- end
547
- endcase
548
- end
549
- end
550
- endmodule
551
-
552
-
553
- module UART_Credits (
554
- input wire clk ,
555
- input wire rst_n,
556
- output reg tx
557
- );
558
-
559
- reg [ 1:0] state = INIT ;
560
- reg [31:0] clk_counter = 0 ;
561
- reg [ 3:0] bit_counter = 0 ;
562
- reg [ 3:0] char_counter = 0 ;
563
- reg [ 7:0] tx_shift_reg = 8'b11111111;
564
- reg [31:0] idle_counter = 0 ;
565
- reg [ 7:0] MESSAGE [0:10] ;
566
-
567
- parameter CLK_FREQ = 10000000; // 10 MHz
568
- parameter BAUD_RATE = 115200 ; // 115200 baud
569
- parameter BIT_PERIOD = 87 ; // CLK_FREQ / BAUD_RATE
570
- parameter BIT_COUNT = 10 ; // 1 start bit, 8 data bits, 1 stop bit
571
- parameter IDLE_COUNT = 8700 ; // Delay
572
-
573
- localparam [7:0] CHAR_P = 8'd80 ;
574
- localparam [7:0] CHAR_h = 8'd104;
575
- localparam [7:0] CHAR_i = 8'd105;
576
- localparam [7:0] CHAR_l = 8'd108;
577
- localparam [7:0] CHAR_i2 = 8'd105;
578
- localparam [7:0] CHAR_p = 8'd112;
579
- localparam [7:0] CHAR_space = 8'd32 ;
580
- localparam [7:0] CHAR_M = 8'd77 ;
581
- localparam [7:0] CHAR_o = 8'd111;
582
- localparam [7:0] CHAR_h2 = 8'd104;
583
- localparam [7:0] CHAR_r = 8'd114;
584
-
585
- localparam INIT = 0, IDLE = 1, START = 2, TRANSMIT = 3;
586
-
587
- always @(posedge clk or negedge rst_n) begin
588
- if (!rst_n) begin
589
- clk_counter <= 0;
590
- bit_counter <= 0;
591
- char_counter <= 0;
592
- tx_shift_reg <= 8'b11111111;
593
- idle_counter <= 0;
594
- tx <= 1'b1;
595
- state <= INIT;
596
- end else begin
597
- case (state)
598
- INIT : begin
599
- MESSAGE[0] <= CHAR_P;
600
- MESSAGE[1] <= CHAR_h;
601
- MESSAGE[2] <= CHAR_i;
602
- MESSAGE[3] <= CHAR_l;
603
- MESSAGE[4] <= CHAR_i2;
604
- MESSAGE[5] <= CHAR_p;
605
- MESSAGE[6] <= CHAR_space;
606
- MESSAGE[7] <= CHAR_M;
607
- MESSAGE[8] <= CHAR_o;
608
- MESSAGE[9] <= CHAR_h2;
609
- MESSAGE[10] <= CHAR_r;
610
- state <= START;
611
- end
612
- IDLE : begin
613
- if (idle_counter < IDLE_COUNT) begin
614
- idle_counter <= idle_counter + 1;
615
- end else begin
616
- idle_counter <= 0;
617
- state <= START;
618
- end
619
- end
620
- START : begin
621
- char_counter <= 0;
622
- tx_shift_reg <= MESSAGE[0];
623
- state <= TRANSMIT;
624
- end
625
- TRANSMIT : begin
626
- if (clk_counter < BIT_PERIOD) begin
627
- clk_counter <= clk_counter + 1;
628
- end else begin
629
- clk_counter <= 0;
630
- if (bit_counter < BIT_COUNT) begin
631
- bit_counter <= bit_counter + 1;
632
- case (bit_counter)
633
- 0 : tx <= 1'b0;
634
- 1 : tx <= tx_shift_reg[0];
635
- 2 : tx <= tx_shift_reg[1];
636
- 3 : tx <= tx_shift_reg[2];
637
- 4 : tx <= tx_shift_reg[3];
638
- 5 : tx <= tx_shift_reg[4];
639
- 6 : tx <= tx_shift_reg[5];
640
- 7 : tx <= tx_shift_reg[6];
641
- 8 : tx <= tx_shift_reg[7];
642
- 9 : tx <= 1'b1;
643
- endcase
644
- end else begin
645
- bit_counter <= 0;
646
- if (char_counter < 10) begin
647
- char_counter <= char_counter + 1;
648
- tx_shift_reg <= MESSAGE[char_counter + 1];
649
- end else begin
650
- char_counter <= 0;
651
- state <= IDLE;
652
- end
653
- end
654
- end
655
- end
656
- endcase
657
- end
658
- end
659
- endmodule
660
-
661
-
662
- module UART_Transmitter (
663
- input wire clk ,
664
- input wire rst_n ,
665
- input wire tx_start,
666
- input wire [7:0] tx_data ,
667
- output reg tx ,
668
- output reg tx_busy
669
- );
670
-
671
- reg [15:0] baud_counter;
672
- reg [ 3:0] bit_counter ;
673
- reg [ 7:0] shift_reg ;
674
- reg transmitting;
675
-
676
- localparam CLK_FREQ = 10000000; // 10 MHz
677
- localparam BAUD_RATE = 115200 ; // 115200 baud
678
- localparam BIT_PERIOD = 87 ; // CLK_FREQ / BAUD_RATE
679
-
680
- always @(posedge clk or negedge rst_n) begin
681
- if (!rst_n) begin
682
- tx <= 1'b1;
683
- tx_busy <= 1'b0;
684
- transmitting <= 1'b0;
685
- baud_counter <= 0;
686
- bit_counter <= 0;
687
- shift_reg <= 0;
688
- end else begin
689
- if (tx_start && !transmitting) begin
690
- transmitting <= 1'b1;
691
- tx_busy <= 1'b1;
692
- shift_reg <= tx_data;
693
- bit_counter <= 0;
694
- baud_counter <= 0;
695
- tx <= 1'b0;
696
- end else if (transmitting) begin
697
- if (baud_counter < BIT_PERIOD - 1) begin
698
- baud_counter <= baud_counter + 1;
699
- end else begin
700
- baud_counter <= 0;
701
- if (bit_counter < 8) begin
702
- tx <= shift_reg[0];
703
- shift_reg <= shift_reg >> 1;
704
- bit_counter <= bit_counter + 1;
705
- end else if (bit_counter == 8) begin
706
- tx <= 1'b1;
707
- bit_counter <= bit_counter + 1;
708
- end else begin
709
- tx_busy <= 1'b0;
710
- transmitting <= 1'b0;
711
- bit_counter <= 0;
712
- end
713
- end
714
- end
715
- end
716
- end
717
- endmodule
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RuC-datasets/RuC-tt07-32k/JamesTimothyMeech-TT07-LFSR/all_mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"module_program_interface_instantiation": [[742, 1033], [1308, 1395], [1397, 1495], [2615, 2706]], "continuous_assign": [[639, 667], [672, 701], [706, 736], [1715, 1738], [2709, 2734]], "blocking_assignment": [[1911, 1919], [1928, 1937], [2134, 2186], [3270, 3286]], "nonblocking_assignment": [[2854, 2877], [2890, 2914], [2927, 2952], [2965, 2990], [3019, 3046], [3057, 3083], [3109, 3119], [3232, 3254], [3335, 3352], [3365, 3407]], "case_statement": [[2825, 3129]], "conditional_statement": [[1898, 1937], [2762, 3134], [3162, 3259], [3314, 3407]], "always_construct": [[1848, 1942], [2077, 2186], [2737, 3134], [3137, 3259], [3289, 3407]], "parameter_declaration": [], "ansi_port_declaration": [[126, 173], [178, 226], [231, 277], [282, 329], [334, 414], [419, 507], [512, 548], [553, 606], [1085, 1121], [1090, 1121], [1097, 1121], [1104, 1121], [1110, 1121], [1767, 1790], [1772, 1790], [1779, 1790], [1786, 1790], [1973, 2005], [1978, 2005], [1987, 2005], [1996, 2005], [2244, 2344], [2251, 2344], [2260, 2344], [2270, 2344], [2280, 2344], [2289, 2344], [2300, 2344], [2311, 2344], [2323, 2344], [2334, 2344]]}
 
 
RuC-datasets/RuC-tt07-32k/JamesTimothyMeech-TT07-LFSR/mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"conditional_statement": [[2762, 3134], [1898, 1937], [3314, 3407], [3162, 3259]], "blocking_assignment": [[1911, 1919], [3270, 3286], [1928, 1937], [2134, 2186]], "module_program_interface_instantiation": [[742, 1033], [2615, 2706], [1308, 1395]], "always_construct": [[3289, 3407], [2737, 3134], [3137, 3259], [2077, 2186]], "case_statement": [[2825, 3129]], "ansi_port_declaration": [[553, 606], [1779, 1790], [1104, 1121]], "continuous_assign": [[672, 701], [706, 736], [639, 667]], "nonblocking_assignment": [[3365, 3407], [3109, 3119], [2927, 2952]]}
 
 
RuC-datasets/RuC-tt07-32k/JamesTimothyMeech-TT07-LFSR/tt_um_lfsr.v DELETED
@@ -1,135 +0,0 @@
1
- /*
2
- * Copyright (c) 2024 Your Name
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
-
6
- `default_nettype none
7
-
8
- module tt_um_lfsr (
9
- input wire [7:0] ui_in, // Dedicated inputs
10
- output wire [7:0] uo_out, // Dedicated outputs
11
- input wire [7:0] uio_in, // IOs: Input path
12
- output wire [7:0] uio_out, // IOs: Output path
13
- output wire [7:0] uio_oe, // IOs: Enable path (active high: 0=input, 1=output)
14
- input wire ena, // always 1 when the design is powered, so you can ignore it
15
- input wire clk, // clock
16
- input wire rst_n // reset_n - low to reset
17
- );
18
-
19
- wire rst = ! rst_n;
20
- assign uio_oe = 8'b00000000;
21
- assign uio_out = 8'b00000000;
22
- assign uo_out[7:3] = 5'b00000;
23
-
24
- wb_lfsr wb_lfsr(
25
- .i_clk(clk),
26
- .i_reset(rst),
27
- .i_wb_cyc(uio_in[0]),
28
- .i_wb_stb(uio_in[1]),
29
- .i_wb_we(uio_in[2]),
30
- .i_wb_addr(uio_in[5:3]),
31
- .i_wb_data(ui_in),
32
- .o_wb_stall(uo_out[0]),
33
- .o_wb_data(uo_out[1]),
34
- .o_wb_ack(uo_out[2])
35
- );
36
-
37
- endmodule
38
-
39
-
40
- module linear_feedback_shift_register(out, clock, reset, seed, load_seed);
41
- output reg out;
42
- input [31:0] seed;
43
- input load_seed;
44
- input reset;
45
- input clock;
46
- wire [31:0] flip_flop_outputs;
47
- wire [31:0] flip_flop_inputs;
48
- wire feedback1, feedback2, feedback3;
49
- flip_flop flip_flop_instance[31:0] (flip_flop_outputs, clock, reset, flip_flop_inputs);
50
- one_bit_mux muxes[31:0] (flip_flop_inputs, load_seed, seed, {flip_flop_outputs[30:0], feedback3});
51
- xor feedback_gate_one(feedback1, flip_flop_outputs[6], flip_flop_outputs[31]);
52
- xor feedback_gate_two(feedback2, feedback1, flip_flop_outputs[5]);
53
- xor feedback_gate_three(feedback3, feedback2, flip_flop_outputs[1]);
54
- assign out = feedback3;
55
- endmodule
56
-
57
- module flip_flop(out, clock, reset, in);
58
- input clock;
59
- input reset;
60
- input in;
61
- output reg out;
62
- always @(posedge clock or posedge reset)
63
- begin
64
-
65
- if (reset)
66
- out = 0;
67
- else
68
- out = in;
69
- end
70
- endmodule
71
-
72
- module one_bit_mux(out, control, input_a, input_b);
73
- output reg out;
74
- input control, input_a, input_b;
75
- wire not_control;
76
- always @(control or not_control or input_a or input_b)
77
- out = (control & input_a) | (not_control & input_b);
78
- not (not_control, control);
79
- endmodule
80
-
81
-
82
- module wb_lfsr(i_clk, i_reset, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data, o_wb_stall, o_wb_data, o_wb_ack);
83
- input i_clk;
84
- input i_reset;
85
- input i_wb_cyc;
86
- input i_wb_stb;
87
- input i_wb_we;
88
- input [2:0] i_wb_addr;
89
- input[7:0] i_wb_data;
90
-
91
- output reg o_wb_stall;
92
- output reg o_wb_ack;
93
- output reg o_wb_data;
94
-
95
- reg [31:0] seed;
96
- reg lfsr_reset;
97
- reg load_seed;
98
- wire lfsr_out;
99
-
100
- linear_feedback_shift_register FLSR_instance(lfsr_out, i_clk, lfsr_reset, seed, load_seed);
101
-
102
- assign o_wb_stall = 1'b0;
103
-
104
- always @(posedge i_clk)
105
- if ((i_wb_stb)&&(i_wb_we)&&(!o_wb_stall)&&(i_wb_cyc))
106
- begin
107
- case (i_wb_addr)
108
- 3'b000 : seed[7:0] <= i_wb_data;
109
- 3'b001 : seed[15:8] <= i_wb_data;
110
- 3'b010 : seed[23:16] <= i_wb_data;
111
- 3'b011 : seed[31:24] <= i_wb_data;
112
- 3'b100 :
113
- begin
114
- lfsr_reset <= i_wb_data[0];
115
- load_seed <= i_wb_data[1];
116
- end
117
- default: seed <= 0;
118
- endcase
119
- end
120
-
121
- always @(posedge i_clk)
122
- if ((i_wb_stb)&&(!i_wb_we)&&(!o_wb_stall)&&(i_wb_cyc))
123
- begin
124
- o_wb_data <= lfsr_out;
125
- end
126
-
127
- initial o_wb_ack = 1'b0;
128
-
129
- always @(posedge i_clk)
130
- if (i_reset) begin
131
- o_wb_ack <= 1'b0;
132
- end else
133
- o_wb_ack <= ((i_wb_stb) && (!o_wb_stall));
134
-
135
- endmodule
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RuC-datasets/RuC-tt07-32k/Kevomlml-tt07_chipusm_neural_network/all_mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"module_program_interface_instantiation": [[11218, 11347], [11349, 11821], [11823, 12088], [12090, 12355], [12357, 12622], [12624, 12889], [12891, 13368]], "continuous_assign": [[10822, 10840], [10841, 10864]], "blocking_assignment": [[475, 502], [594, 623], [720, 748], [844, 873], [951, 997], [1078, 1103], [1622, 1692], [1697, 1721], [1746, 1764], [1782, 1794]], "nonblocking_assignment": [[369, 400], [418, 446], [1192, 1215], [1233, 1256], [2623, 2633], [2638, 2648], [2653, 2663], [2668, 2678], [2683, 2692], [2714, 2724], [2729, 2739], [2744, 2754], [2759, 2769], [2774, 2783], [2805, 2815], [2820, 2830], [2835, 2845], [2850, 2860], [2865, 2874], [2896, 2906], [2911, 2921], [2926, 2936], [2941, 2951], [2956, 2965], [3085, 3094], [3119, 3128], [3153, 3162], [3187, 3196], [3221, 3228], [3289, 3298], [3323, 3332], [3357, 3366], [3391, 3400], [3425, 3432], [3493, 3502], [3527, 3536], [3561, 3570], [3595, 3604], [3629, 3636], [3697, 3706], [3731, 3740], [3765, 3774], [3799, 3808], [3833, 3840], [3960, 3969], [3994, 4003], [4028, 4037], [4062, 4070], [4130, 4138], [4199, 4208], [4233, 4242], [4267, 4276], [4301, 4309], [4369, 4377], [4438, 4447], [4472, 4481], [4506, 4515], [4540, 4548], [4608, 4616], [4677, 4686], [4711, 4720], [4745, 4754], [4779, 4787], [4847, 4859], [4983, 4992], [5017, 5026], [5051, 5060], [5085, 5094], [5119, 5126], [5187, 5196], [5221, 5230], [5255, 5264], [5289, 5298], [5323, 5330], [5391, 5400], [5425, 5434], [5459, 5468], [5493, 5502], [5527, 5534], [5595, 5604], [5629, 5638], [5663, 5672], [5697, 5706], [5731, 5738], [5858, 5867], [5892, 5901], [5926, 5935], [5960, 5969], [5994, 6001], [6062, 6071], [6096, 6105], [6130, 6139], [6164, 6173], [6198, 6205], [6266, 6275], [6300, 6309], [6334, 6343], [6368, 6377], [6402, 6409], [6470, 6479], [6504, 6513], [6538, 6547], [6572, 6581], [6606, 6613], [8116, 8145], [8154, 8183], [8192, 8221], [8230, 8259], [8268, 8299], [8464, 8536], [8565, 8596], [8625, 8656], [8685, 8716], [8745, 8778], [8866, 8897], [8926, 8957], [8986, 9017], [9046, 9077], [9106, 9141], [9228, 9260], [9289, 9321], [9350, 9382], [9411, 9446], [9611, 9642], [9671, 9702], [9731, 9762], [9791, 9822], [9851, 9886]], "case_statement": [[507, 1135], [3015, 6697], [8336, 9931]], "conditional_statement": [[350, 446], [551, 651], [677, 776], [801, 1025], [907, 1025], [1043, 1123], [1173, 1256], [1726, 1794], [2602, 6705], [8088, 9939]], "always_construct": [[318, 451], [453, 1139], [1141, 1261], [1596, 1798], [2570, 6709], [8056, 10560]], "parameter_declaration": [[139, 171], [172, 206], [207, 240]], "ansi_port_declaration": [[21, 36], [41, 58], [63, 82], [87, 107], [112, 134], [1297, 1313], [1318, 1334], [1339, 1355], [1360, 1376], [1382, 1408], [1413, 1433], [1438, 1458], [1463, 1483], [1488, 1505], [1510, 1532], [1538, 1558], [1844, 1859], [1864, 1881], [1886, 1911], [1916, 1937], [1971, 1991], [1996, 2017], [2022, 2043], [2048, 2069], [2074, 2095], [2128, 2148], [2153, 2174], [2179, 2200], [2205, 2226], [2231, 2252], [2285, 2305], [2310, 2331], [2336, 2357], [2362, 2383], [2388, 2409], [2442, 2462], [2467, 2488], [2493, 2514], [2519, 2540], [2545, 2565], [6761, 6776], [6771, 6776], [6781, 6801], [6806, 6903], [7067, 7159], [7164, 7255], [7260, 7351], [7356, 7447], [7511, 7590], [7595, 7674], [7679, 7758], [7763, 7842], [8016, 8048], [10608, 10623], [10628, 10645], [10650, 10674], [10679, 10702], [10712, 10737], [10742, 10767], [10772, 10798], [10804, 10818]]}
 
 
RuC-datasets/RuC-tt07-32k/Kevomlml-tt07_chipusm_neural_network/mask_idx.json DELETED
@@ -1 +0,0 @@
1
- {"conditional_statement": [[1726, 1794], [350, 446], [2602, 6705]], "blocking_assignment": [[1622, 1692], [475, 502], [951, 997], [594, 623], [1746, 1764]], "module_program_interface_instantiation": [[12090, 12355], [11823, 12088], [11218, 11347]], "always_construct": [[2570, 6709], [1141, 1261], [8056, 10560], [453, 1139]], "case_statement": [[507, 1135], [3015, 6697], [8336, 9931]], "ansi_port_declaration": [[1864, 1881], [10804, 10818], [6771, 6776]], "continuous_assign": [[10841, 10864], [10822, 10840]], "parameter_declaration": [[172, 206], [207, 240], [139, 171]], "nonblocking_assignment": [[4779, 4787], [2668, 2678], [2911, 2921], [2744, 2754], [2926, 2936]]}
 
 
RuC-datasets/RuC-tt07-32k/Kevomlml-tt07_chipusm_neural_network/tt_um_neural_network.v DELETED
@@ -1,498 +0,0 @@
1
- module machine (
2
- input wire clk,
3
- input wire reset,
4
- input wire changes,
5
- input wire finished,
6
- output reg [1:0] state
7
- );
8
-
9
- parameter state_data_IN = 2'b00;
10
- parameter state_data_BUFF = 2'b01;
11
- parameter state_data_OUT = 2'b10;
12
-
13
-
14
- //Definir current_state y next_state
15
- reg [1:0] current_state, next_state;
16
-
17
- always@(posedge clk) begin
18
- if (reset)
19
- current_state <= state_data_IN;
20
- else
21
- current_state <= next_state;
22
- end
23
-
24
- always @(*) begin
25
- next_state = current_state;
26
- case (current_state)
27
- state_data_IN: if (changes) begin
28
- next_state = state_data_BUFF;
29
- end
30
- state_data_BUFF: if (changes) begin
31
- next_state = state_data_OUT;
32
- end
33
- state_data_OUT: if (changes) begin
34
- next_state = state_data_BUFF;
35
- end else if (finished) begin
36
- next_state = state_data_IN; //show the results
37
- end
38
- default: if (changes) begin
39
- next_state=current_state;
40
- end
41
- endcase
42
- end
43
-
44
- always@(posedge clk) begin
45
- if (reset)
46
- state <= state_data_IN;
47
- else
48
- state <= current_state;
49
- end
50
- endmodule
51
-
52
-
53
- module perceptron(
54
- input [7:0] in0,
55
- input [7:0] in1,
56
- input [7:0] in2,
57
- input [7:0] in3,
58
-
59
- input [7:0] weight0, //aaa
60
- input [7:0] weight1,
61
- input [7:0] weight2,
62
- input [7:0] weight3,
63
- input [7:0] bias,
64
- input [7:0] threshold,
65
-
66
- output reg [7:0] out
67
- );
68
-
69
- reg [7:0] sum_p;
70
- reg [7:0] res;
71
-
72
- always@(*)
73
- begin
74
-
75
- sum_p=(in0<<weight0)+(in1<<weight1)+(in2<weight2)+(in3<<weight3)+bias;
76
- res = sum_p - threshold;
77
- if (res[7])
78
- out = 8'b00000000;
79
- else
80
- out = sum_p;
81
- end
82
-
83
- endmodule
84
-
85
-
86
- module register_parameters(
87
- input wire clk,
88
- input wire reset,
89
- input wire [7:0] data_in,
90
- input [1:0] selector,
91
-
92
- //output reg [7:0] th3,
93
- output reg [7:0] b3,
94
- output reg [7:0] w33,
95
- output reg [7:0] w32,
96
- output reg [7:0] w31,
97
- output reg [7:0] w30,
98
- //output reg [7:0] th2,
99
- output reg [7:0] b2,
100
- output reg [7:0] w23,
101
- output reg [7:0] w22,
102
- output reg [7:0] w21,
103
- output reg [7:0] w20,
104
- //output reg [7:0] th1,
105
- output reg [7:0] b1,
106
- output reg [7:0] w13,
107
- output reg [7:0] w12,
108
- output reg [7:0] w11,
109
- output reg [7:0] w10,
110
- //output reg [7:0] th0,
111
- output reg [7:0] b0,
112
- output reg [7:0] w03,
113
- output reg [7:0] w02,
114
- output reg [7:0] w01,
115
- output reg [7:0] w00
116
- );
117
-
118
- always @(posedge clk)
119
- begin
120
- if (reset) begin
121
- w00<=8'd0;
122
- w01<=8'd0;
123
- w02<=8'd0;
124
- w03<=8'd0;
125
- b0<=8'd0;
126
- //th0<=8'd0;
127
- w10<=8'd0;
128
- w11<=8'd0;
129
- w12<=8'd0;
130
- w13<=8'd0;
131
- b1<=8'd0;
132
- //th1<=8'd0;
133
- w20<=8'd0;
134
- w21<=8'd0;
135
- w22<=8'd0;
136
- w23<=8'd0;
137
- b2<=8'd0;
138
- //th2<=8'd0;
139
- w30<=8'd0;
140
- w31<=8'd0;
141
- w32<=8'd0;
142
- w33<=8'd0;
143
- b3<=8'd0;
144
- //th3<=8'd0;
145
- end
146
-
147
- else begin
148
- case(selector)
149
- 2'b00 : begin
150
- w00<=w00;
151
- w01<=w01;
152
- w02<=w02;
153
- w03<=w03;
154
- b0<=b0;
155
- //th0<=th0;
156
- w10<=w11;
157
- w11<=w11;
158
- w12<=w12;
159
- w13<=w13;
160
- b1<=b1;
161
- //th1<=th1;
162
- w20<=w21;
163
- w21<=w21;
164
- w22<=w22;
165
- w23<=w23;
166
- b2<=b2;
167
- //th2<=th2;
168
- w30<=w31;
169
- w31<=w31;
170
- w32<=w32;
171
- w33<=w33;
172
- b3<=b3;
173
- //th3<=th3;
174
- end
175
- 2'b01 : begin
176
- w00<=w01;
177
- w01<=w02;
178
- w02<=w03;
179
- w03<=b0;
180
- //b0<=th0;
181
- b0<=w10;
182
- //th0<=w10;
183
- w10<=w11;
184
- w11<=w12;
185
- w12<=w13;
186
- w13<=b1;
187
- //b1<=th1;
188
- b1<=w20;
189
- //th1<=w20;
190
- w20<=w21;
191
- w21<=w22;
192
- w22<=w23;
193
- w23<=b2;
194
- //b2<=th2;
195
- b2<=w30;
196
- //th2<=w30;
197
- w30<=w31;
198
- w31<=w32;
199
- w32<=w33;
200
- w33<=b3;
201
- //b3<=th3;
202
- b3<=data_in;
203
- //th3<=data_in;
204
- end
205
- 2'b10 : begin
206
- w00<=w00;
207
- w01<=w01;
208
- w02<=w02;
209
- w03<=w03;
210
- b0<=b0;
211
- //th0<=th0;
212
- w10<=w11;
213
- w11<=w11;
214
- w12<=w12;
215
- w13<=w13;
216
- b1<=b1;
217
- //th1<=th1;
218
- w20<=w21;
219
- w21<=w21;
220
- w22<=w22;
221
- w23<=w23;
222
- b2<=b2;
223
- //th2<=th2;
224
- w30<=w31;
225
- w31<=w31;
226
- w32<=w32;
227
- w33<=w33;
228
- b3<=b3;
229
- //th3<=th3;
230
- end
231
- default : begin
232
- w00<=w00;
233
- w01<=w01;
234
- w02<=w02;
235
- w03<=w03;
236
- b0<=b0;
237
- //th0<=th0;
238
- w10<=w11;
239
- w11<=w11;
240
- w12<=w12;
241
- w13<=w13;
242
- b1<=b1;
243
- //th1<=th1;
244
- w20<=w21;
245
- w21<=w21;
246
- w22<=w22;
247
- w23<=w23;
248
- b2<=b2;
249
- //th2<=th2;
250
- w30<=w31;
251
- w31<=w31;
252
- w32<=w32;
253
- w33<=w33;
254
- b3<=b3;
255
- //th3<=th3;
256
- end
257
- endcase
258
- end
259
- end
260
-
261
- endmodule
262
-
263
-
264
- module shift_register_inputs(
265
- input clk,rstn,
266
- input [7:0] data_in,
267
- input [1:0] selector, // From the state machine. Determines where do the neuron inputs come From
268
- //input [1:0] selector_output,
269
-
270
- // The outputs of the neurons0..3 are inputs to the shift register, so it can use them as inputs to the next layer
271
- input [7:0] neuron0_output, // The output of the neuron0, is an input to the shift register
272
- input [7:0] neuron1_output, // The output of the neuron1, is an input to the shift register
273
- input [7:0] neuron2_output, // The output of the neuron2, is an input to the shift register
274
- input [7:0] neuron3_output, // The output of the neuron3, is an input to the shift register
275
-
276
- // These 4 outputs are the inputs0..3 to each neuron.
277
- output reg [7:0] neuron_input0, // Input 0 for all neurons on the current layer
278
- output reg [7:0] neuron_input1, // Input 1 for all neurons on the current layer
279
- output reg [7:0] neuron_input2, // Input 2 for all neurons on the current layer
280
- output reg [7:0] neuron_input3, // Input 3 for all neurons on the current layer
281
-
282
- // Once all layers have passed, when we feed 4 new inputs to the network, the outputs of the network
283
- // will appear here, from neuron3_output to neuron0_output
284
- output reg [7:0] network_outputs
285
- );
286
-
287
-
288
-
289
-
290
- always@(posedge clk)
291
- begin
292
-
293
- if(rstn)
294
- begin
295
- neuron_input0 <= 8'b00000000;
296
- neuron_input1 <= 8'b00000000;
297
- neuron_input2 <= 8'b00000000;
298
- neuron_input3 <= 8'b00000000;
299
- network_outputs <= 8'b00000000;
300
- end
301
-
302
- else
303
- begin
304
- case(selector)
305
- 2'b00 : begin // Receives new data
306
- neuron_input0 <= data_in; // and pases it thorugh the neurons.
307
- neuron_input1 <= neuron_input0;
308
- neuron_input2 <= neuron_input1;
309
- neuron_input3 <= neuron_input2;
310
- network_outputs <= neuron_input3;
311
-
312
- end
313
- 2'b01 : begin
314
- neuron_input0 <= neuron_input0;
315
- neuron_input1 <= neuron_input1;
316
- neuron_input2 <= neuron_input2;
317
- neuron_input3 <= neuron_input3;
318
- network_outputs <= network_outputs;
319
- end
320
- 2'b10 : begin
321
- neuron_input0 <= neuron0_output;
322
- neuron_input1 <= neuron1_output;
323
- neuron_input2 <= neuron2_output;
324
- network_outputs <= network_outputs;
325
- end
326
- default : begin // The default state keeps everything as it was
327
- neuron_input0 <= neuron_input0;
328
- neuron_input1 <= neuron_input1;
329
- neuron_input2 <= neuron_input2;
330
- neuron_input3 <= neuron_input3;
331
- network_outputs <= network_outputs;
332
- end
333
-
334
- endcase
335
- end
336
- /*
337
- begin
338
- case(selector_output)
339
- 2'b00 : begin
340
- network_outputs <= neuron_input0;
341
- end
342
- 2'b01 : begin
343
- network_outputs <= neuron_input1;
344
- end
345
- 2'b10 : begin
346
- network_outputs <= neuron_input2;
347
- end
348
- 2'b11 : begin
349
- network_outputs <= neuron_input3;
350
- end
351
- default: begin
352
- network_outputs <= network_outputs;
353
- end
354
- endcase
355
- end
356
- */
357
- end
358
-
359
- endmodule
360
-
361
-
362
- module tt_um_neural_network (
363
- input wire clk,
364
- input wire rst_n,
365
- input wire [7:0] uio_in,
366
- input wire [7:0] ui_in,
367
-
368
- output wire [7:0] uo_out,
369
- output wire [7:0] uio_oe,
370
- output wire [7:0] uio_out,
371
-
372
- input wire ena
373
- );
374
- assign uio_oe = 0;
375
- assign uio_out = 0;
376
- // Señales internas
377
- wire [1:0] state;
378
- wire [7:0] neuron_input0, neuron_input1, neuron_input2, neuron_input3;
379
- wire [7:0] neuron0_output, neuron1_output, neuron2_output, neuron3_output;
380
- wire [7:0] w00, w01, w02, w03, b0;
381
- wire [7:0] w10, w11, w12, w13, b1;
382
- wire [7:0] w20, w21, w22, w23, b2;
383
- wire [7:0] w30, w31, w32, w33, b3;
384
-
385
- // Instanciando los módulos
386
- machine machine_inst (
387
- .clk(clk),
388
- .reset(~rst_n),
389
- .changes(uio_in[1]),
390
- .state(state),
391
- .finished(uio_in[0])
392
- );
393
-
394
- shift_register_inputs shift_reg_inst (
395
- .clk(clk),
396
- .rstn(~rst_n),
397
- .data_in(ui_in),
398
- .selector(state),
399
- //.selector_output(uio_in[1:0]),
400
- .neuron0_output(neuron0_output),
401
- .neuron1_output(neuron1_output),
402
- .neuron2_output(neuron2_output),
403
- .neuron3_output(neuron3_output),
404
- .neuron_input0(neuron_input0),
405
- .neuron_input1(neuron_input1),
406
- .neuron_input2(neuron_input2),
407
- .neuron_input3(neuron_input3),
408
- .network_outputs(uo_out)
409
- );
410
-
411
- perceptron perceptron0 (
412
- .in0(neuron_input0),
413
- .in1(neuron_input1),
414
- .in2(neuron_input2),
415
- .in3(neuron_input3),
416
- .weight0(w00),
417
- .weight1(w01),
418
- .weight2(w02),
419
- .weight3(w03),
420
- .bias(b0),
421
- .threshold(8'd0),
422
- .out(neuron0_output)
423
- );
424
-
425
- perceptron perceptron1 (
426
- .in0(neuron_input0),
427
- .in1(neuron_input1),
428
- .in2(neuron_input2),
429
- .in3(neuron_input3),
430
- .weight0(w10),
431
- .weight1(w11),
432
- .weight2(w12),
433
- .weight3(w13),
434
- .bias(b1),
435
- .threshold(8'd0),
436
- .out(neuron1_output)
437
- );
438
-
439
- perceptron perceptron2 (
440
- .in0(neuron_input0),
441
- .in1(neuron_input1),
442
- .in2(neuron_input2),
443
- .in3(neuron_input3),
444
- .weight0(w20),
445
- .weight1(w21),
446
- .weight2(w22),
447
- .weight3(w23),
448
- .bias(b2),
449
- .threshold(8'd0),
450
- .out(neuron2_output)
451
- );
452
-
453
- perceptron perceptron3 (
454
- .in0(neuron_input0),
455
- .in1(neuron_input1),
456
- .in2(neuron_input2),
457
- .in3(neuron_input3),
458
- .weight0(w30),
459
- .weight1(w31),
460
- .weight2(w32),
461
- .weight3(w33),
462
- .bias(b3),
463
- .threshold(8'd0),
464
- .out(neuron3_output)
465
- );
466
-
467
- register_parameters reg_params_inst (
468
- .clk(clk),
469
- .reset(~rst_n),
470
- .data_in(ui_in),
471
- .selector(state),
472
- //.th3(th3),
473
- .b3(b3),
474
- .w33(w33),
475
- .w32(w32),
476
- .w31(w31),
477
- .w30(w30),
478
- //.th2(th2),
479
- .b2(b2),
480
- .w23(w23),
481
- .w22(w22),
482
- .w21(w21),
483
- .w20(w20),
484
- //.th1(th1),
485
- .b1(b1),
486
- .w13(w13),
487
- .w12(w12),
488
- .w11(w11),
489
- .w10(w10),
490
- //.th0(th0),
491
- .b0(b0),
492
- .w03(w03),
493
- .w02(w02),
494
- .w01(w01),
495
- .w00(w00)
496
- );
497
-
498
- endmodule