Skip to content

Commit dac886c

Browse files
author
Derek Hower
committed
Make misa extension bits definedBy their extension so they display correctly in docs. Fix optional calculation
1 parent 98126d8 commit dac886c

File tree

5 files changed

+34
-29
lines changed

5 files changed

+34
-29
lines changed

arch/csr/misa.yaml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ misa:
2323
Writing 0 to this field will cause all atomic instructions to raise an `IllegalInstruction` exception.
2424
type(): |
2525
return (implemented?(ExtensionName::A) && MUTABLE_MISA_A) ? CsrFieldType::RW : CsrFieldType::RO;
26-
reset_value(): |
27-
return implemented?(ExtensionName::A) ? 1 : 0;
26+
definedBy: A
27+
reset_value: 1
2828
B:
2929
location: 1
3030
description: |
@@ -34,8 +34,8 @@ misa:
3434
Writing 0 to this field will cause all bitmanip instructions to raise an `IllegalInstruction` exception.
3535
type(): |
3636
return (implemented?(ExtensionName::B) && MUTABLE_MISA_B) ? CsrFieldType::RW : CsrFieldType::RO;
37-
reset_value(): |
38-
return implemented?(ExtensionName::B) ? 1 : 0;
37+
definedBy: B
38+
reset_value: 1
3939
C:
4040
location: 2
4141
description: |
@@ -46,8 +46,8 @@ misa:
4646
Additionally, IALIGN becomes 32.
4747
type(): |
4848
return (implemented?(ExtensionName::C) && MUTABLE_MISA_C) ? CsrFieldType::RW : CsrFieldType::RO;
49-
reset_value(): |
50-
return implemented?(ExtensionName::C) ? 1 : 0;
49+
definedBy: C
50+
reset_value: 1
5151
D:
5252
location: 3
5353
description: |
@@ -61,8 +61,8 @@ misa:
6161
--
6262
type(): |
6363
return (implemented?(ExtensionName::D) && MUTABLE_MISA_D) ? CsrFieldType::RW : CsrFieldType::RO;
64-
reset_value(): |
65-
return implemented?(ExtensionName::D) ? 1 : 0;
64+
definedBy: D
65+
reset_value: 1
6666
F:
6767
location: 5
6868
description: |
@@ -76,8 +76,8 @@ misa:
7676
--
7777
type(): |
7878
return (implemented?(ExtensionName::F) && MUTABLE_MISA_F) ? CsrFieldType::RW : CsrFieldType::RO;
79-
reset_value(): |
80-
return implemented?(ExtensionName::F) ? 1 : 0;
79+
definedBy: F
80+
reset_value: 1
8181
sw_write(csr_value): |
8282
if (csr_value.F == 0 && csr_value.D == 1) {
8383
return UNDEFINED_LEGAL_DETERMINISTIC;
@@ -115,13 +115,14 @@ misa:
115115
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.
116116
type(): |
117117
return (implemented?(ExtensionName::H) && MUTABLE_MISA_H) ? CsrFieldType::RW : CsrFieldType::RO;
118-
reset_value(): |
119-
return implemented?(ExtensionName::H) ? 1 : 0;
118+
definedBy: H
119+
reset_value: 1
120120
I:
121121
location: 8
122122
description: |
123123
Indicates support for the `I` (base) extension.
124124
type: RO
125+
definedBy: I
125126
reset_value: 1
126127
M:
127128
location: 13
@@ -132,8 +133,8 @@ misa:
132133
Writing 0 to this field will cause all attempts to execute an integer multiply or divide instruction to raise an `IllegalInstruction` exception.
133134
type(): |
134135
return (implemented?(ExtensionName::M) && MUTABLE_MISA_M) ? CsrFieldType::RW : CsrFieldType::RO;
135-
reset_value(): |
136-
return implemented?(ExtensionName::M) ? 1 : 0;
136+
definedBy: M
137+
reset_value: 1
137138
S:
138139
location: 19
139140
description: |
@@ -143,8 +144,8 @@ misa:
143144
Writing 0 to this field will cause all attempts to enter S-mode or access S-mode state to raise an exception.
144145
type(): |
145146
return (implemented?(ExtensionName::S) && MUTABLE_MISA_S) ? CsrFieldType::RW : CsrFieldType::RO;
146-
reset_value(): |
147-
return implemented?(ExtensionName::S) ? 1 : 0;
147+
definedBy: S
148+
reset_value: 1
148149
U:
149150
location: 21
150151
description: |
@@ -154,19 +155,18 @@ misa:
154155
Writing 0 to this field will cause all attempts to enter U-mode to raise an exception.
155156
type(): |
156157
return (implemented?(ExtensionName::U) && MUTABLE_MISA_U) ? CsrFieldType::RW : CsrFieldType::RO;
157-
reset_value(): |
158-
return implemented?(ExtensionName::U) ? 1 : 0;
158+
definedBy: U
159+
reset_value: 1
159160
V:
160161
location: 22
161162
description: |
162163
Indicates support for the `V` (vector) extension.
163164
164-
[when,"MUTABLE_MISA_S == true"]
165+
[when,"MUTABLE_MISA_V == true"]
165166
Writing 0 to this field will cause all attempts to execute a vector instruction to raise an `IllegalInstruction` trap.
166167
type: RO
167-
reset_value: 0 # TODO
168-
# reset_value(): |
169-
# return implemented?(ExtensionName::V) ? 1 : 0;
168+
definedBy: V
169+
reset_value: 1
170170
sw_read(): |
171171
return (
172172
(CSR[misa].MXL << 62) |

backends/crd_doc/templates/crd.adoc.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ h| Privilege Mode | <%= csr.priv_mode %>
542542
.<%= csr.name %> format
543543
[wavedrom, ,svg,subs='attributes',width="100%"]
544544
....
545-
<%= JSON.dump csr.wavedrom_desc(arch_def, csr.base.nil? ? 32 : csr.base, optional_type: 3) %>
545+
<%= JSON.dump csr.wavedrom_desc(arch_def, csr.base.nil? ? 32 : csr.base, optional_type: 2) %>
546546
....
547547
<% else -%>
548548
<%# CSR has a dynamic length, or a field has a dynamic location,
@@ -552,13 +552,13 @@ This CSR format changes dynamically with XLEN.
552552
.<%= csr.name %> Format when <%= csr.length_cond32 %>
553553
[wavedrom, ,svg,subs='attributes',width="100%"]
554554
....
555-
<%= JSON.dump csr.wavedrom_desc(arch_def, 32, optional_type: 3) %>
555+
<%= JSON.dump csr.wavedrom_desc(arch_def, 32, optional_type: 2) %>
556556
....
557557

558558
.<%= csr.name %> Format when <%= csr.length_cond64 %>
559559
[wavedrom, ,svg,subs='attributes',width="100%"]
560560
....
561-
<%= JSON.dump csr.wavedrom_desc(arch_def, 64, optional_type: 3) %>
561+
<%= JSON.dump csr.wavedrom_desc(arch_def, 64, optional_type: 2) %>
562562
....
563563

564564

lib/arch_obj_models/csr.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ def pruned_sw_read_ast(arch_def)
512512
# @param exclude_unimplemented [Boolean] If true, do not create include unimplemented fields in the figure
513513
# @param optional_type [Integer] Wavedrom type (Fill color) for fields that are optional (not mandatory) in a partially-specified arch_def
514514
# @return [Hash] A representation of the WaveDrom drawing for the CSR (should be turned into JSON for wavedrom)
515-
def wavedrom_desc(arch_def, effective_xlen, exclude_unimplemented: false, optional_type: 2)
515+
def wavedrom_desc(arch_def, effective_xlen, exclude_unimplemented: false, optional_type: 3)
516516
desc = {
517517
"reg" => []
518518
}
@@ -536,9 +536,10 @@ def wavedrom_desc(arch_def, effective_xlen, exclude_unimplemented: false, option
536536
desc["reg"] << { "bits" => n, type: 1 }
537537
end
538538
if arch_def.partially_configured? && field.optional_in_cfg?(arch_def)
539+
puts "#{name}.#{field.name} is OPTIONAL"
539540
desc["reg"] << { "bits" => field.location(arch_def, effective_xlen).size, "name" => field.name, type: optional_type }
540541
else
541-
desc["reg"] << { "bits" => field.location(arch_def, effective_xlen).size, "name" => field.name, type: 2 }
542+
desc["reg"] << { "bits" => field.location(arch_def, effective_xlen).size, "name" => field.name, type: 3 }
542543
end
543544
last_idx = field.location(arch_def, effective_xlen).max
544545
end
@@ -570,7 +571,7 @@ def optional_in_cfg?(arch_def)
570571
raise "optional_in_cfg? should only be used by a partially-specified arch def" unless arch_def.partially_configured?
571572

572573
exists_in_cfg?(arch_def) &&
573-
arch_def.mandatory_extensions.none? do |ext_req|
574+
arch_def.mandatory_extensions.all? do |ext_req|
574575
ext_req.satisfying_versions(arch_def).none? { |ext_ver| defined_by?(ext_ver) }
575576
end
576577
end

lib/arch_obj_models/csr_field.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def optional_in_cfg?(arch_def)
5252
exists_in_cfg?(arch_def) &&
5353
(
5454
parent.optional_in_cfg?(arch_def) ||
55-
(data["definedBy"].nil? || arch_def.mandatory_extensions.none? do |ext_req|
55+
(data["definedBy"].nil? || arch_def.mandatory_extensions.all? do |ext_req|
5656
ext_req.satisfying_versions(arch_def).none? { |ext_ver| defined_by?(ext_ver) }
5757
end)
5858
)

lib/arch_obj_models/extension.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ def params(arch_def)
316316
ext(arch_def).params.select { |p| p.defined_in_extension_version?(@version) }
317317
end
318318

319+
def to_s
320+
"#{name}@#{version}"
321+
end
322+
319323
# @overload ==(other)
320324
# @param other [String] An extension name
321325
# @return [Boolean] whether or not this ExtensionVersion is named 'other'

0 commit comments

Comments
 (0)