Skip to content

Commit 815394f

Browse files
authored
Added XLEN as a length type for CSRs (#534)
* Added XLEN as a length type for CSRs * More updates to Ruby CSR object + description for CSR schema * More fixes for Ruby CSR object * More fixes to Ruby CSR object --------- Signed-off-by: Katherine Hsu <67767297+neverlandiz@users.noreply.github.com>
1 parent d2cf938 commit 815394f

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

arch/csr/schema.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ Length::
5959

6060
|===
6161
| *key* | length
62-
| *value type* | one of [32, 64, "MXLEN", "SXLEN", "VSXLEN"]
63-
| *description* | Length, in bits, of the CSR. Can either be a 32, 64 or MXLEN, SXLEN, VSXLEN to indicate that is is equal to the effective XLEN for a given mode
62+
| *value type* | one of [32, 64, "MXLEN", "SXLEN", "VSXLEN", "XLEN"]
63+
| *description* | Length, in bits, of the CSR. Can either be a 32, 64 or MXLEN, SXLEN, VSXLEN, XLEN to indicate that is is equal to the effective XLEN for a given mode
6464
|===
6565

6666
Indirect::

lib/arch_obj_models/csr.rb

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ def dynamic_length?
112112
when "VSXLEN"
113113
# dynamic if either we don't know VSXLEN or VSXLEN is explicitly mutable
114114
[nil, 3264].include?(cfg_arch.param_values["VSXLEN"])
115+
when "XLEN"
116+
# must always have M-mode
117+
# SXLEN condition applies if S-mode is possible
118+
# VSXLEN condition applies if VS-mode is possible
119+
(cfg_arch.mxlen.nil?) || \
120+
(cfg_arch.possible_extensions.map(&:name).include?("S") && \
121+
[nil, 3264].include(cfg_arch.param_values["SXLEN"])) || \
122+
(cfg_arch.possible_extensions.map(&:name).include?("H") && \
123+
[nil, 3264].include?(cfg_arch.param_values["VSXLEN"]))
115124
else
116125
raise "Unexpected length"
117126
end
@@ -121,7 +130,7 @@ def dynamic_length?
121130
# @return [Integer] Smallest length of the CSR in any mode
122131
def min_length
123132
case @data["length"]
124-
when "MXLEN", "SXLEN", "VSXLEN"
133+
when "MXLEN", "SXLEN", "VSXLEN", "XLEN"
125134
@cfg_arch.possible_xlens.min
126135
when Integer
127136
@data["length"]
@@ -173,6 +182,8 @@ def length(effective_xlen = nil)
173182
# don't know VSXLEN
174183
effective_xlen
175184
end
185+
when "XLEN"
186+
effective_xlen
176187
when Integer
177188
@data["length"]
178189
else
@@ -207,6 +218,42 @@ def max_length
207218
else
208219
64
209220
end
221+
when "XLEN"
222+
if cfg_arch.possible_extensions.map(&:name).include?("M")
223+
cfg_arch.mxlen || 64
224+
elsif cfg_arch.possible_extensions.map(&:name).include?("S")
225+
if cfg_arch.param_values.key?("SXLEN")
226+
if cfg_arch.param_values["SXLEN"] == 3264
227+
64
228+
else
229+
cfg_arch.param_values["SXLEN"]
230+
end
231+
else
232+
# SXLEN can never be greater than MXLEN
233+
cfg_arch.mxlen || 64
234+
end
235+
elsif cfg_arch.possible_extensions.map(&:name).include?("H")
236+
if cfg_arch.param_values.key?("VSXLEN")
237+
if cfg_arch.param_values["VSXLEN"] == 3264
238+
64
239+
else
240+
cfg_arch.param_values["VSXLEN"]
241+
end
242+
else
243+
# VSXLEN can never be greater than MXLEN or SXLEN
244+
if cfg_arch.param_values.key?("SXLEN")
245+
if cfg_arch.param_values["SXLEN"] == 3264
246+
64
247+
else
248+
cfg_arch.param_values["SXLEN"]
249+
end
250+
else
251+
cfg_arch.mxlen || 64
252+
end
253+
end
254+
else
255+
raise "Unexpected"
256+
end
210257
when Integer
211258
@data["length"]
212259
else
@@ -223,6 +270,8 @@ def length_cond32
223270
"CSR[mstatus].SXL == 0"
224271
when "VSXLEN"
225272
"CSR[hstatus].VSXL == 0"
273+
when "XLEN"
274+
"(priv_mode() == PrivilegeMode::M && CSR[misa].MXL == 0) || (priv_mode() == PrivilegeMode::S && CSR[mstatus].SXL == 0) || (priv_mode() == PrivilegeMode::VS && CSR[hstatus].VSXL == 0)"
226275
else
227276
raise "Unexpected length #{@data['length']} for #{name}"
228277
end
@@ -237,6 +286,8 @@ def length_cond64
237286
"CSR[mstatus].SXL == 1"
238287
when "VSXLEN"
239288
"CSR[hstatus].VSXL == 1"
289+
when "XLEN"
290+
"(priv_mode() == PrivilegeMode::M && CSR[misa].MXL == 1) || (priv_mode() == PrivilegeMode::S && CSR[mstatus].SXL == 1) || (priv_mode() == PrivilegeMode::VS && CSR[hstatus].VSXL == 1)"
240291
else
241292
raise "Unexpected length"
242293
end
@@ -254,6 +305,8 @@ def length_pretty(effective_xlen=nil)
254305
"CSR[mstatus].SXL == %%"
255306
when "VSXLEN"
256307
"CSR[hstatus].VSXL == %%"
308+
when "XLEN"
309+
"(priv_mode() == PrivilegeMode::M && CSR[misa].MXL == %%) || (priv_mode() == PrivilegeMode::S && CSR[mstatus].SXL == %%) || (priv_mode() == PrivilegeMode::VS && CSR[hstatus].VSXL == %%)"
257310
else
258311
raise "Unexpected length '#{@data['length']}'"
259312
end

schemas/csr_schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@
245245
"enum": ["M", "S", "U", "VS"]
246246
},
247247
"length": {
248-
"description": "Length, in bits, of the CSR. Can either be a 32, 64 or MXLEN, SXLEN, VSXLEN to indicate that is is dependent on the effective XLEN for a given mode",
249-
"enum": [32, 64, "MXLEN", "SXLEN", "VSXLEN"]
248+
"description": "Length, in bits, of the CSR. Can either be a 32, 64 or MXLEN, SXLEN, VSXLEN to indicate that it is dependent on the effective XLEN for a given mode. XLEN here refers to the effective XLEN in the current execution mode.",
249+
"enum": [32, 64, "MXLEN", "SXLEN", "VSXLEN", "XLEN"]
250250
},
251251
"requires": {
252252
"type": "string",

0 commit comments

Comments
 (0)