Skip to content

Commit

Permalink
Merge pull request #115 from riscv-software-src/manual_appendices
Browse files Browse the repository at this point in the history
Add profile info to instructions in manual
  • Loading branch information
dhower-qc authored Oct 17, 2024
2 parents e1e595b + ea9171f commit 5bc774e
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 12 deletions.
4 changes: 2 additions & 2 deletions arch/csr/mstatus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ mstatus:
Since the CPU does not support big endian, this is hardwired to 0.
[when,"M_MODE_ENDIANESS == big"]
Since the CPU does not support litte endian, this is hardwired to 1.
Since the CPU does not support little endian, this is hardwired to 1.
type(): |
return (M_MODE_ENDIANESS == "dynamic") ? CsrFieldType::RW : CsrFieldType::RO;
# if endianess is mutable, MBE comes out of reset in little-endian mode
# if endianness is mutable, MBE comes out of reset in little-endian mode
reset_value(): |
return (M_MODE_ENDIANESS == "big") ? 1 : 0;
Expand Down
5 changes: 5 additions & 0 deletions backends/manual/tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,19 @@ end
rule %r{#{MANUAL_GEN_DIR}/.*/.*/antora/modules/csrs/pages/.*.adoc} => [
__FILE__,
"#{$root}/.stamps/arch-gen-_64.stamp",
"#{$root}/.stamps/arch-gen-_32.stamp",
($root / "backends" / "manual" / "templates" / "csr.adoc.erb").to_s
] do |t|
csr_name = File.basename(t.name, ".adoc")

arch_def = arch_def_for("_64")
arch_def_32 = arch_def_for("_32")

csr = arch_def.csr(csr_name)
raise "Can't find csr '#{csr_name}'" if csr.nil?

csr_32 = arch_def_32.csr(csr_name)

csr_template_path = $root / "backends" / "manual" / "templates" / "csr.adoc.erb"
erb = ERB.new(csr_template_path.read, trim_mode: "-")
erb.filename = csr_template_path.to_s
Expand Down
8 changes: 4 additions & 4 deletions backends/manual/templates/csr.adoc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ h| CSR Address | <%= "0x#{csr.address.to_s(16)}" %>
<%- if csr.priv_mode == 'VS' -%>
h| Virtual CSR Address | <%= "0x#{csr.virtual_address.to_s(16)}" %>
<%- end -%>
<%- if csr.dynamic_length?(arch_def) -%>
<%- if csr.dynamic_length?(arch_def) || csr.data["length"] == "MXLEN" -%>
h| Length
a|

[when,"<%= csr.length_cond32 %>"]
--
<%= csr.length_pretty(arch_def, 32) %>
<%= csr_32.length_pretty(arch_def_32, 32) %>
--

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

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

Expand Down
22 changes: 19 additions & 3 deletions backends/manual/templates/func.adoc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,30 @@

<%= f.description %>

[cols="1,2"]
|===
h| Return Type l| <%= f.return_type_list_str.join(', ') %>
h| Arguments l| <%= f.arguments_list_str.join (', ') %>
h| Return Type
a|
[source,idl]
----
<%= f.return_type_list_str.join(', ') %>
----

h| Arguments
a|
<%- if f.arguments_list_str.empty? -%>
None
<%- else -%>
[source,idl]
----
<%= f.arguments_list_str.join (', ') %>
----
<%- end -%>
|===

<%- unless f.builtin? -%>
<%- body_ast = f.body -%>
[subs="specialchars,macros"]
[source,idl,subs="specialchars,macros"]
----
<%= body_ast.gen_adoc %>
----
Expand Down
22 changes: 21 additions & 1 deletion backends/manual/templates/instruction.adoc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ This instruction is defined by:

<%= inst.defined_by.to_asciidoc %>

This instruction is included in the following profiles:

<%- arch_def.profiles.each do |profile| -%>
<%-
in_profile_mandatory = profile.mandatory_extension_requirements.any? do |ext_req|
ext_versions = ext_req.satisfying_versions(arch_def)
ext_versions.any? { |ext_ver| inst.defined_by?(ext_ver) }
end
in_profile_optional = profile.optional_extension_requirements.any? do |ext_req|
ext_versions = ext_req.satisfying_versions(arch_def)
ext_versions.any? { |ext_ver| inst.defined_by?(ext_ver) }
end
if in_profile_mandatory
-%>
* <%= profile.marketing_name %> (Mandatory)
<%- elsif in_profile_optional -%>
* <%= profile.marketing_name %> (Optional)
<%- end -%>
<%- end -%>

== Encoding

<%- if inst.multi_encoding? -%>
Expand Down Expand Up @@ -74,7 +94,7 @@ This instruction must have data-independent timing when extension `Zkt` is enabl
====
RV32::
+
[source.idl]
[source,idl]
----
<%- inst.decode_variables(32).each do |d| -%>
<%= d.sext? ? 'signed ' : '' %>Bits<<%= d.size %>> <%= d.name %> = <%= d.extract %>;
Expand Down
10 changes: 10 additions & 0 deletions lib/arch_obj_models/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,16 @@ def initialize(name, *requirements, note: nil, req_id: nil, presence: nil)
@presence = presence
end

# @return [Array<ExtensionVersion>] The list of extension versions that satisfy this requirement
def satisfying_versions(archdef)
ext = archdef.extension(@name)
return [] if ext.nil?

ext.versions.select { |v| @requirement.satisfied_by?(Gem::Version.new(v["version"])) }.map do |v|
ExtensionVersion.new(@name, v["version"])
end
end

# @overload
# @param extension_version [ExtensionVersion] A specific extension version
# @return [Boolean] whether or not the extension_version meets this requirement
Expand Down
4 changes: 2 additions & 2 deletions lib/arch_obj_models/manual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def instructions
@instructions << inst
end
end
@instructions
@instructions = @instructions.uniq(&:name)
end

# @return [Array<Csr>] All csrs defined in this version
Expand All @@ -184,6 +184,6 @@ def csrs
@csrs << csr
end
end
@csrs
@csrs = @csrs.uniq(&:name)
end
end

0 comments on commit 5bc774e

Please sign in to comment.