Skip to content

Commit 5bc774e

Browse files
authored
Merge pull request #115 from riscv-software-src/manual_appendices
Add profile info to instructions in manual
2 parents e1e595b + ea9171f commit 5bc774e

File tree

7 files changed

+63
-12
lines changed

7 files changed

+63
-12
lines changed

arch/csr/mstatus.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ mstatus:
6161
Since the CPU does not support big endian, this is hardwired to 0.
6262
6363
[when,"M_MODE_ENDIANESS == big"]
64-
Since the CPU does not support litte endian, this is hardwired to 1.
64+
Since the CPU does not support little endian, this is hardwired to 1.
6565
type(): |
6666
return (M_MODE_ENDIANESS == "dynamic") ? CsrFieldType::RW : CsrFieldType::RO;
6767
68-
# if endianess is mutable, MBE comes out of reset in little-endian mode
68+
# if endianness is mutable, MBE comes out of reset in little-endian mode
6969
reset_value(): |
7070
return (M_MODE_ENDIANESS == "big") ? 1 : 0;
7171

backends/manual/tasks.rake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,19 @@ end
189189
rule %r{#{MANUAL_GEN_DIR}/.*/.*/antora/modules/csrs/pages/.*.adoc} => [
190190
__FILE__,
191191
"#{$root}/.stamps/arch-gen-_64.stamp",
192+
"#{$root}/.stamps/arch-gen-_32.stamp",
192193
($root / "backends" / "manual" / "templates" / "csr.adoc.erb").to_s
193194
] do |t|
194195
csr_name = File.basename(t.name, ".adoc")
195196

196197
arch_def = arch_def_for("_64")
198+
arch_def_32 = arch_def_for("_32")
199+
197200
csr = arch_def.csr(csr_name)
198201
raise "Can't find csr '#{csr_name}'" if csr.nil?
199202

203+
csr_32 = arch_def_32.csr(csr_name)
204+
200205
csr_template_path = $root / "backends" / "manual" / "templates" / "csr.adoc.erb"
201206
erb = ERB.new(csr_template_path.read, trim_mode: "-")
202207
erb.filename = csr_template_path.to_s

backends/manual/templates/csr.adoc.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ h| CSR Address | <%= "0x#{csr.address.to_s(16)}" %>
1515
<%- if csr.priv_mode == 'VS' -%>
1616
h| Virtual CSR Address | <%= "0x#{csr.virtual_address.to_s(16)}" %>
1717
<%- end -%>
18-
<%- if csr.dynamic_length?(arch_def) -%>
18+
<%- if csr.dynamic_length?(arch_def) || csr.data["length"] == "MXLEN" -%>
1919
h| Length
2020
a|
2121

2222
[when,"<%= csr.length_cond32 %>"]
2323
--
24-
<%= csr.length_pretty(arch_def, 32) %>
24+
<%= csr_32.length_pretty(arch_def_32, 32) %>
2525
--
2626

2727
[when,"<%= csr.length_cond64 %>"]
@@ -36,7 +36,7 @@ h| Privilege Mode | <%= csr.priv_mode %>
3636
|===
3737

3838
== Format
39-
<%- unless csr.dynamic_length?(arch_def) || csr.fields.any? { |f| f.dynamic_location?(arch_def) } -%>
39+
<%- unless csr.dynamic_length?(arch_def) || csr.fields.any? { |f| f.dynamic_location?(arch_def) } || csr.data["length"] == "MXLEN" -%>
4040
<%# CSR has a known static length, so there is only one format to display -%>
4141
.<%= csr.name %> format
4242
[wavedrom, ,svg,subs='attributes',width="100%"]
@@ -52,7 +52,7 @@ This CSR format changes dynamically.
5252
--
5353
[wavedrom, ,svg,subs='attributes',width="100%"]
5454
....
55-
<%= JSON.dump csr.wavedrom_desc(arch_def, 32) %>
55+
<%= JSON.dump csr_32.wavedrom_desc(arch_def_32, 32) %>
5656
....
5757
--
5858

backends/manual/templates/func.adoc.erb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,30 @@
1010

1111
<%= f.description %>
1212

13+
[cols="1,2"]
1314
|===
14-
h| Return Type l| <%= f.return_type_list_str.join(', ') %>
15-
h| Arguments l| <%= f.arguments_list_str.join (', ') %>
15+
h| Return Type
16+
a|
17+
[source,idl]
18+
----
19+
<%= f.return_type_list_str.join(', ') %>
20+
----
21+
22+
h| Arguments
23+
a|
24+
<%- if f.arguments_list_str.empty? -%>
25+
None
26+
<%- else -%>
27+
[source,idl]
28+
----
29+
<%= f.arguments_list_str.join (', ') %>
30+
----
31+
<%- end -%>
1632
|===
1733

1834
<%- unless f.builtin? -%>
1935
<%- body_ast = f.body -%>
20-
[subs="specialchars,macros"]
36+
[source,idl,subs="specialchars,macros"]
2137
----
2238
<%= body_ast.gen_adoc %>
2339
----

backends/manual/templates/instruction.adoc.erb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@ This instruction is defined by:
99

1010
<%= inst.defined_by.to_asciidoc %>
1111

12+
This instruction is included in the following profiles:
13+
14+
<%- arch_def.profiles.each do |profile| -%>
15+
<%-
16+
in_profile_mandatory = profile.mandatory_extension_requirements.any? do |ext_req|
17+
ext_versions = ext_req.satisfying_versions(arch_def)
18+
ext_versions.any? { |ext_ver| inst.defined_by?(ext_ver) }
19+
end
20+
in_profile_optional = profile.optional_extension_requirements.any? do |ext_req|
21+
ext_versions = ext_req.satisfying_versions(arch_def)
22+
ext_versions.any? { |ext_ver| inst.defined_by?(ext_ver) }
23+
end
24+
if in_profile_mandatory
25+
-%>
26+
* <%= profile.marketing_name %> (Mandatory)
27+
<%- elsif in_profile_optional -%>
28+
* <%= profile.marketing_name %> (Optional)
29+
<%- end -%>
30+
<%- end -%>
31+
1232
== Encoding
1333

1434
<%- if inst.multi_encoding? -%>
@@ -74,7 +94,7 @@ This instruction must have data-independent timing when extension `Zkt` is enabl
7494
====
7595
RV32::
7696
+
77-
[source.idl]
97+
[source,idl]
7898
----
7999
<%- inst.decode_variables(32).each do |d| -%>
80100
<%= d.sext? ? 'signed ' : '' %>Bits<<%= d.size %>> <%= d.name %> = <%= d.extract %>;

lib/arch_obj_models/extension.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,16 @@ def initialize(name, *requirements, note: nil, req_id: nil, presence: nil)
364364
@presence = presence
365365
end
366366

367+
# @return [Array<ExtensionVersion>] The list of extension versions that satisfy this requirement
368+
def satisfying_versions(archdef)
369+
ext = archdef.extension(@name)
370+
return [] if ext.nil?
371+
372+
ext.versions.select { |v| @requirement.satisfied_by?(Gem::Version.new(v["version"])) }.map do |v|
373+
ExtensionVersion.new(@name, v["version"])
374+
end
375+
end
376+
367377
# @overload
368378
# @param extension_version [ExtensionVersion] A specific extension version
369379
# @return [Boolean] whether or not the extension_version meets this requirement

lib/arch_obj_models/manual.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def instructions
170170
@instructions << inst
171171
end
172172
end
173-
@instructions
173+
@instructions = @instructions.uniq(&:name)
174174
end
175175

176176
# @return [Array<Csr>] All csrs defined in this version
@@ -184,6 +184,6 @@ def csrs
184184
@csrs << csr
185185
end
186186
end
187-
@csrs
187+
@csrs = @csrs.uniq(&:name)
188188
end
189189
end

0 commit comments

Comments
 (0)