diff --git a/arch/csr/misa.yaml b/arch/csr/misa.yaml index d82e3975a0..c7bf07fb7f 100644 --- a/arch/csr/misa.yaml +++ b/arch/csr/misa.yaml @@ -23,8 +23,8 @@ misa: Writing 0 to this field will cause all atomic instructions to raise an `IllegalInstruction` exception. type(): | return (implemented?(ExtensionName::A) && MUTABLE_MISA_A) ? CsrFieldType::RW : CsrFieldType::RO; - reset_value(): | - return implemented?(ExtensionName::A) ? 1 : 0; + definedBy: A + reset_value: 1 B: location: 1 description: | @@ -34,8 +34,8 @@ misa: Writing 0 to this field will cause all bitmanip instructions to raise an `IllegalInstruction` exception. type(): | return (implemented?(ExtensionName::B) && MUTABLE_MISA_B) ? CsrFieldType::RW : CsrFieldType::RO; - reset_value(): | - return implemented?(ExtensionName::B) ? 1 : 0; + definedBy: B + reset_value: 1 C: location: 2 description: | @@ -46,8 +46,8 @@ misa: Additionally, IALIGN becomes 32. type(): | return (implemented?(ExtensionName::C) && MUTABLE_MISA_C) ? CsrFieldType::RW : CsrFieldType::RO; - reset_value(): | - return implemented?(ExtensionName::C) ? 1 : 0; + definedBy: C + reset_value: 1 D: location: 3 description: | @@ -61,8 +61,8 @@ misa: -- type(): | return (implemented?(ExtensionName::D) && MUTABLE_MISA_D) ? CsrFieldType::RW : CsrFieldType::RO; - reset_value(): | - return implemented?(ExtensionName::D) ? 1 : 0; + definedBy: D + reset_value: 1 F: location: 5 description: | @@ -76,8 +76,8 @@ misa: -- type(): | return (implemented?(ExtensionName::F) && MUTABLE_MISA_F) ? CsrFieldType::RW : CsrFieldType::RO; - reset_value(): | - return implemented?(ExtensionName::F) ? 1 : 0; + definedBy: F + reset_value: 1 sw_write(csr_value): | if (csr_value.F == 0 && csr_value.D == 1) { return UNDEFINED_LEGAL_DETERMINISTIC; @@ -115,13 +115,14 @@ misa: Writing 0 to this field will cause all attempts to enter VS- or VU- mode, execute a hypervisor instruction, or access a hypervisor CSR to raise an `IllegalInstruction` fault. type(): | return (implemented?(ExtensionName::H) && MUTABLE_MISA_H) ? CsrFieldType::RW : CsrFieldType::RO; - reset_value(): | - return implemented?(ExtensionName::H) ? 1 : 0; + definedBy: H + reset_value: 1 I: location: 8 description: | Indicates support for the `I` (base) extension. type: RO + definedBy: I reset_value: 1 M: location: 13 @@ -132,8 +133,8 @@ misa: Writing 0 to this field will cause all attempts to execute an integer multiply or divide instruction to raise an `IllegalInstruction` exception. type(): | return (implemented?(ExtensionName::M) && MUTABLE_MISA_M) ? CsrFieldType::RW : CsrFieldType::RO; - reset_value(): | - return implemented?(ExtensionName::M) ? 1 : 0; + definedBy: M + reset_value: 1 S: location: 19 description: | @@ -143,8 +144,8 @@ misa: Writing 0 to this field will cause all attempts to enter S-mode or access S-mode state to raise an exception. type(): | return (implemented?(ExtensionName::S) && MUTABLE_MISA_S) ? CsrFieldType::RW : CsrFieldType::RO; - reset_value(): | - return implemented?(ExtensionName::S) ? 1 : 0; + definedBy: S + reset_value: 1 U: location: 21 description: | @@ -154,19 +155,18 @@ misa: Writing 0 to this field will cause all attempts to enter U-mode to raise an exception. type(): | return (implemented?(ExtensionName::U) && MUTABLE_MISA_U) ? CsrFieldType::RW : CsrFieldType::RO; - reset_value(): | - return implemented?(ExtensionName::U) ? 1 : 0; + definedBy: U + reset_value: 1 V: location: 22 description: | Indicates support for the `V` (vector) extension. - [when,"MUTABLE_MISA_S == true"] + [when,"MUTABLE_MISA_V == true"] Writing 0 to this field will cause all attempts to execute a vector instruction to raise an `IllegalInstruction` trap. type: RO - reset_value: 0 # TODO - # reset_value(): | - # return implemented?(ExtensionName::V) ? 1 : 0; + definedBy: V + reset_value: 1 sw_read(): | return ( (CSR[misa].MXL << 62) | diff --git a/backends/crd_doc/templates/crd.adoc.erb b/backends/crd_doc/templates/crd.adoc.erb index eb1ee3826c..e17221661a 100644 --- a/backends/crd_doc/templates/crd.adoc.erb +++ b/backends/crd_doc/templates/crd.adoc.erb @@ -542,7 +542,7 @@ h| Privilege Mode | <%= csr.priv_mode %> .<%= csr.name %> format [wavedrom, ,svg,subs='attributes',width="100%"] .... -<%= JSON.dump csr.wavedrom_desc(arch_def, csr.base.nil? ? 32 : csr.base, optional_type: 3) %> +<%= JSON.dump csr.wavedrom_desc(arch_def, csr.base.nil? ? 32 : csr.base, optional_type: 2) %> .... <% else -%> <%# CSR has a dynamic length, or a field has a dynamic location, @@ -552,13 +552,13 @@ This CSR format changes dynamically with XLEN. .<%= csr.name %> Format when <%= csr.length_cond32 %> [wavedrom, ,svg,subs='attributes',width="100%"] .... -<%= JSON.dump csr.wavedrom_desc(arch_def, 32, optional_type: 3) %> +<%= JSON.dump csr.wavedrom_desc(arch_def, 32, optional_type: 2) %> .... .<%= csr.name %> Format when <%= csr.length_cond64 %> [wavedrom, ,svg,subs='attributes',width="100%"] .... -<%= JSON.dump csr.wavedrom_desc(arch_def, 64, optional_type: 3) %> +<%= JSON.dump csr.wavedrom_desc(arch_def, 64, optional_type: 2) %> .... diff --git a/lib/arch_obj_models/csr.rb b/lib/arch_obj_models/csr.rb index 0c0ad725f1..3071dc9d91 100644 --- a/lib/arch_obj_models/csr.rb +++ b/lib/arch_obj_models/csr.rb @@ -512,7 +512,7 @@ def pruned_sw_read_ast(arch_def) # @param exclude_unimplemented [Boolean] If true, do not create include unimplemented fields in the figure # @param optional_type [Integer] Wavedrom type (Fill color) for fields that are optional (not mandatory) in a partially-specified arch_def # @return [Hash] A representation of the WaveDrom drawing for the CSR (should be turned into JSON for wavedrom) - def wavedrom_desc(arch_def, effective_xlen, exclude_unimplemented: false, optional_type: 2) + def wavedrom_desc(arch_def, effective_xlen, exclude_unimplemented: false, optional_type: 3) desc = { "reg" => [] } @@ -536,9 +536,10 @@ def wavedrom_desc(arch_def, effective_xlen, exclude_unimplemented: false, option desc["reg"] << { "bits" => n, type: 1 } end if arch_def.partially_configured? && field.optional_in_cfg?(arch_def) + puts "#{name}.#{field.name} is OPTIONAL" desc["reg"] << { "bits" => field.location(arch_def, effective_xlen).size, "name" => field.name, type: optional_type } else - desc["reg"] << { "bits" => field.location(arch_def, effective_xlen).size, "name" => field.name, type: 2 } + desc["reg"] << { "bits" => field.location(arch_def, effective_xlen).size, "name" => field.name, type: 3 } end last_idx = field.location(arch_def, effective_xlen).max end @@ -570,7 +571,7 @@ def optional_in_cfg?(arch_def) raise "optional_in_cfg? should only be used by a partially-specified arch def" unless arch_def.partially_configured? exists_in_cfg?(arch_def) && - arch_def.mandatory_extensions.none? do |ext_req| + arch_def.mandatory_extensions.all? do |ext_req| ext_req.satisfying_versions(arch_def).none? { |ext_ver| defined_by?(ext_ver) } end end diff --git a/lib/arch_obj_models/csr_field.rb b/lib/arch_obj_models/csr_field.rb index 2d0cdd6c1f..ed1d0bfe52 100644 --- a/lib/arch_obj_models/csr_field.rb +++ b/lib/arch_obj_models/csr_field.rb @@ -52,7 +52,7 @@ def optional_in_cfg?(arch_def) exists_in_cfg?(arch_def) && ( parent.optional_in_cfg?(arch_def) || - (data["definedBy"].nil? || arch_def.mandatory_extensions.none? do |ext_req| + (data["definedBy"].nil? || arch_def.mandatory_extensions.all? do |ext_req| ext_req.satisfying_versions(arch_def).none? { |ext_ver| defined_by?(ext_ver) } end) ) diff --git a/lib/arch_obj_models/extension.rb b/lib/arch_obj_models/extension.rb index f8675e9425..f63b9f68b7 100644 --- a/lib/arch_obj_models/extension.rb +++ b/lib/arch_obj_models/extension.rb @@ -316,6 +316,10 @@ def params(arch_def) ext(arch_def).params.select { |p| p.defined_in_extension_version?(@version) } end + def to_s + "#{name}@#{version}" + end + # @overload ==(other) # @param other [String] An extension name # @return [Boolean] whether or not this ExtensionVersion is named 'other'