Skip to content

Commit a962e90

Browse files
Raise error if portfilio created with cfg_arch with wrong base size (it happens and will need to be fixed).
1 parent 998bce3 commit a962e90

File tree

6 files changed

+84
-17
lines changed

6 files changed

+84
-17
lines changed

.vscode/launch.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"configurations": [
44
{
55
"type": "rdbg",
6-
"name": "RVA20",
6+
"name": "MC100-32",
77
"request": "launch",
88
"command": "bundle exec rake",
9-
"script": "gen:profile[RVA20]",
9+
"script": "gen:cert_model_pdf[MC100-32]",
1010
"args": [],
1111
"askParameters": false
1212
},
@@ -18,6 +18,15 @@
1818
"script": "gen:cert_model_pdf[MC200-32]",
1919
"args": [],
2020
"askParameters": false
21+
},
22+
{
23+
"type": "rdbg",
24+
"name": "RVA20",
25+
"request": "launch",
26+
"command": "bundle exec rake",
27+
"script": "gen:profile[RVA20]",
28+
"args": [],
29+
"askParameters": false
2130
}
2231
]
2332
}

backends/certificate_doc/tasks.rake

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ Dir.glob("#{$root}/arch/certificate_model/*.yaml") do |f|
2424
"#{CERT_DOC_DIR}/templates/certificate.adoc.erb",
2525
__FILE__
2626
] do |t|
27-
# TODO: schema validation
27+
# Create bootstrap ConfiguredArchitecture object which also creates and contains
28+
# a PartialConfig object for the rv32/rv64 configuration.
2829
base_cfg_arch = cfg_arch_for("rv#{base}")
30+
31+
# Creates CertModel object for every certificate model in database
32+
# using rv32/rv64 PartialConfig object and then returns named CertModel object.
2933
base_cert_model = base_cfg_arch.cert_model(cert_model_name)
3034
raise "No certificate model named '#{cert_model_name}'" if base_cert_model.nil?
3135

32-
# Ask base certification model to create an in-memory config arch for this model.
33-
# XXX - Add this to profile releases
36+
# Ask base certification model to create an in-memory ConfiguredArchitecture for this model.
3437
cfg_arch = base_cert_model.to_cfg_arch
3538

3639
# Set globals for ERB template.

cert_flow.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
backends/certificate_doc/tasks.rake
2+
base_cfg_arch = cfg_arch_for("rv#{base}") # rv32 or rv64
3+
Rakefile
4+
Calls ConfiguredArchitecture.new("gen/resolved_arch/rv32")
5+
Calls Architecture.new # Parent class
6+
Calls Config.create("cfgs/rv32/cfg.yaml") # Factory class method
7+
Loads config yaml file into @data # File specifies if fully, partially, or unconfigured
8+
Calls PartialConfig.new(cfg path, @data) # Uses Ruby send() method
9+
@mxlen = @data["params"].xlen
10+
@name = "rv32"
11+
base_cert_model = base_cfg_arch.cert_model(cert_model_name = "MC100-32")
12+
Calls self.generate_obj_methods("cert_model", "certificate_model", CertModel) in Architecture # Magic
13+
Calls define_method("cert_model")
14+
Calls define_method("cert_models")
15+
Creates @cert_models array and @cert_model_hash # Per arch_dir
16+
For every certificiate model in the database
17+
Loads yaml under gen/resolved_arch/rv32 into @cert_models hash
18+
Calls cert_model.new() -> DatabaseObject.initialize(yaml, yaml_path, arch=base_cfg_arch)
19+
@data = yaml
20+
@cfg_arch = arch # rv32 (nil if Architecture object provided)
21+
@specification = arch # rv32

lib/arch_obj_models/certificate.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ def mandatory_priv_modes = @data["mandatory_priv_modes"]
2020
# Holds information about a certificate model YAML file.
2121
# The inherited "data" member is the database of extensions, instructions, CSRs, etc.
2222
class CertModel < Portfolio
23+
# @param obj_yaml [Hash<String, Object>] Contains contents of Certificate Model yaml file (put in @data)
24+
# @param data_path [String] Path to yaml file
25+
# @param cfg_arch [ConfiguredArchitecture] Architecture for a specific configuration
26+
def initialize(obj_yaml, yaml_path, arch: nil)
27+
super(obj_yaml, yaml_path, arch: arch)
28+
29+
unless arch.is_a?(ConfiguredArchitecture)
30+
raise ArgumentError, "For #{name} arch is a #{arch.class} but must be a ConfiguredArchitecture"
31+
end
32+
end
33+
2334
def unpriv_isa_manual_revision = @data["unpriv_isa_manual_revision"]
2435
def priv_isa_manual_revision = @data["priv_isa_manual_revision"]
2536
def debug_manual_revision = @data["debug_manual_revision"]

lib/arch_obj_models/obj.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def definedBy
182182
# @param data [Hash<String,Object>] Hash with fields to be added
183183
# @param data_path [Pathname] Path to the data file
184184
def initialize(data, data_path, arch: nil)
185-
raise "Bad data" unless data.is_a?(Hash)
185+
raise ArgumentError, "Bad data" unless data.is_a?(Hash)
186186

187187
@data = data
188188
@data_path = data_path

lib/arch_obj_models/portfolio.rb

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ def portfolio_classes_matching_portfolio_kind_and_processor_kind
5252
# Holds information about a Portfolio (certificate or profile).
5353
# The inherited "data" member is the database of extensions, instructions, CSRs, etc.
5454
class Portfolio < DatabaseObject
55+
# @param obj_yaml [Hash<String, Object>] Contains contents of Portfolio yaml file (put in @data)
56+
# @param data_path [String] Path to yaml file
57+
# @param cfg_arch [ConfiguredArchitecture] Architecture for a specific configuration
58+
def initialize(obj_yaml, yaml_path, arch: nil)
59+
super(obj_yaml, yaml_path, arch: arch)
60+
61+
unless arch.is_a?(ConfiguredArchitecture)
62+
raise ArgumentError, "For #{name} arch is a #{arch.class} but must be a ConfiguredArchitecture"
63+
end
64+
65+
raise "For #{name} @data[\"base\"] is nil" if @data["base"].nil?
66+
raise "For #{name} arch.mxlen is nil" if arch.mxlen.nil?
67+
68+
if (obj_yaml["base"] != arch.mxlen)
69+
bad_base = obj_yaml["base"]
70+
raise "For #{name} called with ConfigureArchitecture #{arch.name} with mxlen=#{arch.mxlen} but my base is #{bad_base}"
71+
end
72+
end
73+
5574
# @return [ConfiguredArchitecture] The defining ConfiguredArchitecture
5675
attr_reader :cfg_arch
5776

@@ -122,6 +141,10 @@ def extension_note(ext_name)
122141
return ext_data["note"] unless ext_data.nil?
123142
end
124143

144+
def mandatory_ext_reqs = in_scope_ext_reqs(ExtensionPresence.mandatory)
145+
def optional_ext_reqs = in_scope_ext_reqs(ExtensionPresence.optional)
146+
def optional_type_ext_reqs = in_scope_ext_reqs(ExtensionPresence.optional)
147+
125148
# @param desired_presence [String, Hash, ExtensionPresence]
126149
# @return [Array<ExtensionRequirements>] - # Extensions with their portfolio information.
127150
# If desired_presence is provided, only returns extensions with that presence.
@@ -181,9 +204,16 @@ def in_scope_ext_reqs(desired_presence = nil)
181204
in_scope_ext_reqs
182205
end
183206

184-
def mandatory_ext_reqs = in_scope_ext_reqs(ExtensionPresence.mandatory)
185-
def optional_ext_reqs = in_scope_ext_reqs(ExtensionPresence.optional)
186-
def optional_type_ext_reqs = in_scope_ext_reqs(ExtensionPresence.optional)
207+
# @return [Array<Instruction>] Sorted list of all instructions associated with extensions listed as
208+
# mandatory or optional in portfolio. Uses minimum version of
209+
# extension version that meets extension requirement specified in portfolio.
210+
def in_scope_instructions
211+
return @in_scope_instructions unless @in_scope_instructions.nil?
212+
213+
# XXX
214+
# @in_scope_instructions = in_scope_ext_reqs.map { |ext_req| ext_req.instructions }.flatten.uniq.sort
215+
@in_scope_instructions = in_scope_extensions.map { |ext| ext.instructions }.flatten.uniq.sort
216+
end
187217

188218
# @return [Array<Extension>] List of all extensions listed in portfolio.
189219
def in_scope_extensions
@@ -196,13 +226,6 @@ def in_scope_extensions
196226
@in_scope_extensions
197227
end
198228

199-
# @return [Array<Instruction>] Sorted list of all instructions associated with extensions listed as
200-
# mandatory or optional in portfolio. Uses minimum version of
201-
# extension version that meets extension requirement specified in portfolio.
202-
def in_scope_instructions
203-
in_scope_extensions.map { |ext| ext.instructions }.flatten.uniq.sort
204-
end
205-
206229
# @return [Boolean] Does the profile differentiate between different types of optional.
207230
def uses_optional_types?
208231
return @uses_optional_types unless @uses_optional_types.nil?
@@ -220,7 +243,7 @@ def uses_optional_types?
220243
@uses_optional_types
221244
end
222245

223-
# Called by rakefile when generating a particular portfolio instance.
246+
# Called by rakefile when generating a portfolio.
224247
# Creates an in-memory data structure used by all portfolio routines that access a cfg_arch.
225248
#
226249
# @return [ConfiguredArchitecture] A partially-configured architecture definition corresponding to this portfolio.

0 commit comments

Comments
 (0)