Class: Udb::Csr
- Inherits:
-
TopLevelDatabaseObject
- Object
- DatabaseObject
- TopLevelDatabaseObject
- Udb::Csr
- Includes:
- Idl::Csr, HasFields
- Defined in:
- lib/udb/obj/csr.rb
Overview
CSR definition
Defined Under Namespace
Classes: MemoizedState
Constant Summary collapse
- BITS6_TYPE =
Frozen constant Type/Var objects reused across all fill_symtab calls
Idl::Type.new(:bits, width: 6).freeze
- BITS6_CONST_TYPE =
Idl::Type.new(:bits, width: 6, qualifiers: [:const]).freeze
- BITS128_TYPE =
Idl::Type.new(:bits, width: 128).freeze
- ENCODING_SIZE_VAR =
Idl::Var.new("__instruction_encoding_size", BITS6_TYPE, 32).freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from DatabaseObject
Instance Method Summary collapse
- #==(other) ⇒ Object
- #address ⇒ Integer?
- #base ⇒ Object
-
#bitfield_type(cfg_arch, effective_xlen = nil) ⇒ Idl::BitfieldType
A bitfield type that can represent all fields of the CSR.
-
#defined_in_all_bases? ⇒ Boolean
True if this CSR is defined regardless of the effective XLEN.
-
#defined_in_base32? ⇒ Boolean
True if this CSR is defined when XLEN is 32.
-
#defined_in_base64? ⇒ Boolean
True if this CSR is defined when XLEN is 64.
-
#defined_in_base?(xlen) ⇒ Boolean
True if this CSR is defined when XLEN is xlen.
- #defining_extension_requirements ⇒ Object
-
#description_html ⇒ String
parse description field with asciidoctor, and return the HTML result.
-
#dynamic_length? ⇒ Boolean
Whether or not the length of the CSR depends on a runtime value (e.g., mstatus.SXL).
- #exists_in_cfg?(cfg_arch) ⇒ Boolean
- #fields ⇒ Object
-
#fill_symtab(ast, effective_xlen) ⇒ IdL::SymbolTable
A symbol table populated with globals and syms specific to this CSR.
-
#format_changes_with_xlen? ⇒ Boolean
Whether or not the format of this CSR changes when the effective XLEN changes in some mode.
-
#has_custom_sw_read? ⇒ Boolean
True if the CSR has a custom sw_read function.
-
#indirect? ⇒ Boolean
Whether or not the CSR can be accessed by indirect address.
-
#indirect_address ⇒ Integer
The indirect address.
-
#indirect_slot ⇒ Integer
The indirect window slot.
-
#initialize(data, data_path, arch) ⇒ Csr
constructor
A new instance of Csr.
- #length(effective_xlen = nil) ⇒ Object
-
#length_cond32 ⇒ String
IDL condition of when the effective xlen is 32.
-
#length_cond64 ⇒ String
IDL condition of when the effective xlen is 64.
-
#length_pretty(effective_xlen = nil) ⇒ String
Pretty-printed length string.
- #long_name ⇒ Object
- #max_length ⇒ Object
-
#min_length ⇒ Integer
Smallest length of the CSR in any mode.
-
#modes_with_access ⇒ Object
list of modes that can potentially access the field.
-
#priv_mode ⇒ String
Least-privileged mode that can access this CSR.
-
#pruned_sw_read_ast(effective_xlen) ⇒ FunctionBodyAst
Pruned (but not re-type-checked) AST for sw_read().
- #reachable_functions(effective_xlen = nil, cache = T.let({}, T::Hash[Integer, Idl::AstNode::ReachableFunctionCacheType])) ⇒ Object
-
#sw_read_ast(symtab) ⇒ FunctionBodyAst
The abstract syntax tree of the sw_read() function.
-
#type_checked_pruned_sw_read_ast(effective_xlen) ⇒ FunctionBodyAst
Pruned and re-type-checked AST for sw_read() Use this when you need the AST to be fully type-checked (e.g., for the type_check pass).
- #type_checked_sw_read_ast(effective_xlen) ⇒ Object
- #value ⇒ Object (also: #reset_value)
- #virtual_address ⇒ Integer?
Methods included from HasFields
#affected_by?, #field, #field?, #field_hash, #fields_for, #optional_in_cfg?, #possible_fields, #possible_fields_for, #wavedrom_desc, #writable
Methods inherited from TopLevelDatabaseObject
create_json_schemer_resolver, #key?, #keys, #validate
Methods inherited from DatabaseObject
#<=>, #__source, #cfg_arch, #cfg_arch?, #clone, #defer, #defined_by_condition, #description, #inspect, #kind, #source_line
Constructor Details
#initialize(data, data_path, arch) ⇒ Csr
Returns a new instance of Csr.
33 34 35 36 37 |
# File 'lib/udb/obj/csr.rb', line 33 def initialize(data, data_path, arch) super(data, data_path, arch) @memo = MemoizedState.new(reachable_functions: {}) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
40 41 42 |
# File 'lib/udb/obj/csr.rb', line 40 def name @name end |
Instance Method Details
#==(other) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/udb/obj/csr.rb', line 42 def ==(other) if other.is_a?(Csr) name == other.name else raise ArgumentError, "Csr is not comparable to #{other.class.name}" end end |
#address ⇒ Integer?
52 53 54 |
# File 'lib/udb/obj/csr.rb', line 52 def address @data["address"] end |
#base ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/udb/obj/csr.rb', line 97 def base return @base if defined?(@base) @base = if defined_by_condition.rv32_only? 32 elsif defined_by_condition.rv64_only? 64 else nil end end |
#bitfield_type(cfg_arch, effective_xlen = nil) ⇒ Idl::BitfieldType
Returns A bitfield type that can represent all fields of the CSR.
469 470 471 472 473 474 475 476 477 |
# File 'lib/udb/obj/csr.rb', line 469 def bitfield_type(cfg_arch, effective_xlen = nil) @bitfield_type_cache ||= {} @bitfield_type_cache[effective_xlen] ||= Idl::BitfieldType.new( "Csr#{name.capitalize}Bitfield", length(effective_xlen), fields_for(effective_xlen).map(&:name), fields_for(effective_xlen).map { |f| f.location(effective_xlen) } ) end |
#defined_in_all_bases? ⇒ Boolean
Returns true if this CSR is defined regardless of the effective XLEN.
117 |
# File 'lib/udb/obj/csr.rb', line 117 def defined_in_all_bases? = base.nil? |
#defined_in_base32? ⇒ Boolean
Returns true if this CSR is defined when XLEN is 32.
111 |
# File 'lib/udb/obj/csr.rb', line 111 def defined_in_base32? = base != 64 |
#defined_in_base64? ⇒ Boolean
Returns true if this CSR is defined when XLEN is 64.
114 |
# File 'lib/udb/obj/csr.rb', line 114 def defined_in_base64? = base != 32 |
#defined_in_base?(xlen) ⇒ Boolean
Returns true if this CSR is defined when XLEN is xlen.
121 |
# File 'lib/udb/obj/csr.rb', line 121 def defined_in_base?(xlen) = xlen == 32 ? defined_in_base32? : defined_in_base64? |
#defining_extension_requirements ⇒ Object
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
# File 'lib/udb/obj/csr.rb', line 438 def defining_extension_requirements @defining_extension_requirements ||= begin pb = Udb.( "Determining defining extensions for CSR #{name} [:bar] :current/:total", total: @cfg_arch.csrs.size, clear: true ) @cfg_arch.extensions.map do |ext| pb.advance vers = ext.versions.select do |ext_ver| if defined_by_condition.mentions?(ext_ver) (-defined_by_condition & ext_ver.to_condition).unsatisfiable? end end unless vers.empty? ExtensionRequirement.create_from_ext_vers(vers) end end.compact end end |
#description_html ⇒ String
parse description field with asciidoctor, and return the HTML result
429 430 431 |
# File 'lib/udb/obj/csr.rb', line 429 def description_html Asciidoctor.convert description end |
#dynamic_length? ⇒ Boolean
Returns Whether or not the length of the CSR depends on a runtime value (e.g., mstatus.SXL).
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/udb/obj/csr.rb', line 178 def dynamic_length? return false if @data["length"].is_a?(Integer) # when a CSR is only defined in one base, its length can't change return false unless base.nil? case @data["length"] when "MXLEN" # mxlen can never change at runtime, so if we have it in the config, the length is not dynamic # if we don't have it in the config, we don't know what the length is cfg_arch.mxlen.nil? when "SXLEN" # dynamic if either we don't know SXLEN or SXLEN is explicitly mutable cfg_arch.param_values["SXLEN"].nil? || cfg_arch.param_values["SXLEN"].size > 1 when "VSXLEN" # dynamic if either we don't know VSXLEN or VSXLEN is explicitly mutable !cfg_arch.param_values.key?("VSXLEN") || cfg_arch.param_values["VSXLEN"].size > 1 when "XLEN" # must always have M-mode # SXLEN condition applies if S-mode is possible # VSXLEN condition applies if VS-mode is possible (cfg_arch.mxlen.nil?) || \ (cfg_arch.possible_extensions.map(&:name).include?("S") && \ (cfg_arch.param_values["SXLEN"].nil? || cfg_arch.param_values["SXLEN"].size > 1)) && \ (cfg_arch.possible_extensions.map(&:name).include?("H") && \ (cfg_arch.param_values["VSXLEN"].nil? || cfg_arch.param_values["VSXLEN"].size > 1)) else raise "Unexpected length" end end |
#exists_in_cfg?(cfg_arch) ⇒ Boolean
616 617 618 |
# File 'lib/udb/obj/csr.rb', line 616 def exists_in_cfg?(cfg_arch) @exists_in_cfg ||= defined_by_condition.could_be_satisfied_by_cfg_arch?(cfg_arch) end |
#fields ⇒ Object
465 |
# File 'lib/udb/obj/csr.rb', line 465 def fields = T.unsafe(super) |
#fill_symtab(ast, effective_xlen) ⇒ IdL::SymbolTable
Returns A symbol table populated with globals and syms specific to this CSR.
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/udb/obj/csr.rb', line 542 def fill_symtab(ast, effective_xlen) symtab = @cfg_arch.symtab.global_clone symtab.push(ast) # all CSR instructions are 32-bit if effective_xlen @xlen_var_cache ||= {} @xlen_var_cache[effective_xlen] ||= Idl::Var.new("__effective_xlen", BITS6_TYPE, effective_xlen).freeze symtab.add("__effective_xlen", @xlen_var_cache[effective_xlen]) end symtab.add("__instruction_encoding_size", ENCODING_SIZE_VAR) symtab.add("__expected_return_type", BITS128_TYPE) if symtab.get("MXLEN").value.nil? # Cache per-xlen MXLEN var; use :nil_xlen sentinel so nil key doesn't collide with unset mxlen_key = effective_xlen.nil? ? :nil_xlen : effective_xlen @mxlen_var_cache ||= {} @mxlen_var_cache[mxlen_key] ||= Idl::Var.new( "MXLEN", BITS6_CONST_TYPE, effective_xlen, param: true ).freeze symtab.add("MXLEN", @mxlen_var_cache[mxlen_key]) end symtab end |
#format_changes_with_xlen? ⇒ Boolean
Returns Whether or not the format of this CSR changes when the effective XLEN changes in some mode.
124 125 126 127 128 |
# File 'lib/udb/obj/csr.rb', line 124 def format_changes_with_xlen? dynamic_length? || \ (defined_in_all_bases? && (possible_fields_for(32) != possible_fields_for(64))) || \ possible_fields.any?(&:dynamic_location?) end |
#has_custom_sw_read? ⇒ Boolean
Returns true if the CSR has a custom sw_read function.
480 481 482 |
# File 'lib/udb/obj/csr.rb', line 480 def has_custom_sw_read? @data.key?("sw_read()") && !@data["sw_read()"].empty? end |
#indirect? ⇒ Boolean
Returns Whether or not the CSR can be accessed by indirect address.
57 58 59 |
# File 'lib/udb/obj/csr.rb', line 57 def indirect? @data.key?("indirect_address") end |
#indirect_address ⇒ Integer
Returns The indirect address.
62 63 64 |
# File 'lib/udb/obj/csr.rb', line 62 def indirect_address @data["indirect_address"] end |
#indirect_slot ⇒ Integer
Returns The indirect window slot.
67 68 69 |
# File 'lib/udb/obj/csr.rb', line 67 def indirect_slot @data["indirect_slot"] end |
#length(effective_xlen = nil) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/udb/obj/csr.rb', line 224 def length(effective_xlen = nil) case @data["length"] when "MXLEN" return T.must(cfg_arch.mxlen) unless cfg_arch.mxlen.nil? if !base.nil? base else # don't know MXLEN effective_xlen end when "SXLEN" if cfg_arch.param_values.key?("SXLEN") if cfg_arch.param_values["SXLEN"].size > 1 effective_xlen else cfg_arch.param_values["SXLEN"][0] end elsif !base.nil? # if this CSR is only available in one base, then we know its length base else # don't know SXLEN effective_xlen end when "VSXLEN" if cfg_arch.param_values.key?("VSXLEN") if cfg_arch.param_values["VSXLEN"].size > 1 effective_xlen else cfg_arch.param_values["VSXLEN"][0] end elsif !base.nil? # if this CSR is only available in one base, then we know its length base else # don't know VSXLEN effective_xlen end when "XLEN" effective_xlen when Integer @data["length"] else raise "Unexpected length field for #{name}" end end |
#length_cond32 ⇒ String
Returns IDL condition of when the effective xlen is 32.
345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/udb/obj/csr.rb', line 345 def length_cond32 case @data["length"] when "MXLEN" "CSR[misa].MXL == 0" when "SXLEN" "CSR[mstatus].SXL == 0" when "VSXLEN" "CSR[hstatus].VSXL == 0" when "XLEN" "(priv_mode() == PrivilegeMode::M && CSR[misa].MXL == 0) || (priv_mode() == PrivilegeMode::S && CSR[mstatus].SXL == 0) || (priv_mode() == PrivilegeMode::VS && CSR[hstatus].VSXL == 0)" else raise "Unexpected length #{@data['length']} for #{name}" end end |
#length_cond64 ⇒ String
Returns IDL condition of when the effective xlen is 64.
361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/udb/obj/csr.rb', line 361 def length_cond64 case @data["length"] when "MXLEN" "CSR[misa].MXL == 1" when "SXLEN" "CSR[mstatus].SXL == 1" when "VSXLEN" "CSR[hstatus].VSXL == 1" when "XLEN" "(priv_mode() == PrivilegeMode::M && CSR[misa].MXL == 1) || (priv_mode() == PrivilegeMode::S && CSR[mstatus].SXL == 1) || (priv_mode() == PrivilegeMode::VS && CSR[hstatus].VSXL == 1)" else raise "Unexpected length" end end |
#length_pretty(effective_xlen = nil) ⇒ String
Returns Pretty-printed length string.
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
# File 'lib/udb/obj/csr.rb', line 378 def length_pretty(effective_xlen = nil) raise ArgumentError, "effective_xlen is non-nil and is a #{effective_xlen.class} but must be an Integer" unless effective_xlen.nil? || effective_xlen.is_a?(Integer) if dynamic_length? cond = case @data["length"] when "MXLEN" "CSR[misa].MXL == %%" when "SXLEN" "CSR[mstatus].SXL == %%" when "VSXLEN" "CSR[hstatus].VSXL == %%" when "XLEN" "(priv_mode() == PrivilegeMode::M && CSR[misa].MXL == %%) || (priv_mode() == PrivilegeMode::S && CSR[mstatus].SXL == %%) || (priv_mode() == PrivilegeMode::VS && CSR[hstatus].VSXL == %%)" else raise "Unexpected length '#{@data['length']}'" end if effective_xlen.nil? [ "* #{length(32)} when #{cond.sub('%%', '0')}", "* #{length(64)} when #{cond.sub('%%', '1')}" ].join("\n") else "#{length(effective_xlen)}-bit" end else "#{length}-bit" end end |
#long_name ⇒ Object
76 77 78 |
# File 'lib/udb/obj/csr.rb', line 76 def long_name @data["long_name"] end |
#max_length ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/udb/obj/csr.rb', line 275 def max_length return T.must(base) unless base.nil? case @data["length"] when "MXLEN" cfg_arch.mxlen || 64 when "SXLEN" if cfg_arch.param_values.key?("SXLEN") if cfg_arch.param_values["SXLEN"].size > 1 cfg_arch.param_values["SXLEN"].max else cfg_arch.param_values.fetch("SXLEN").fetch(0) end else 64 end when "VSXLEN" if cfg_arch.param_values.key?("VSXLEN") if cfg_arch.param_values["VSXLEN"].size > 1 cfg_arch.param_values["VSXLEN"].max else cfg_arch.param_values["VSXLEN"][0] end else 64 end when "XLEN" if cfg_arch.possible_extensions.map(&:name).include?("M") cfg_arch.mxlen || 64 elsif cfg_arch.possible_extensions.map(&:name).include?("S") if cfg_arch.param_values.key?("SXLEN") if cfg_arch.param_values.fetch("SXLEN").size > 1 cfg_arch.param_values.fetch("SXLEN").max else cfg_arch.param_values.fetch("SXLEN").fetch(0) end else # SXLEN can never be greater than MXLEN cfg_arch.mxlen || 64 end elsif cfg_arch.possible_extensions.map(&:name).include?("H") if cfg_arch.param_values.key?("VSXLEN") if cfg_arch.param_values["VSXLEN"].size > 1 cfg_arch.param_values["VSXLEN"].max else cfg_arch.param_values["VSXLEN"][0] end else # VSXLEN can never be greater than MXLEN or SXLEN if cfg_arch.param_values.key?("SXLEN") if cfg_arch.param_values.fetch("SXLEN").size > 1 cfg_arch.param_values.fetch("SXLEN").max else cfg_arch.param_values.fetch("SXLEN").fetch(0) end else cfg_arch.mxlen || 64 end end else raise "Unexpected" end when Integer @data["length"] else raise "Unexpected length field for #{name}" end end |
#min_length ⇒ Integer
Returns Smallest length of the CSR in any mode.
211 212 213 214 215 216 217 218 219 220 |
# File 'lib/udb/obj/csr.rb', line 211 def min_length case @data["length"] when "MXLEN", "SXLEN", "VSXLEN", "XLEN" @cfg_arch.possible_xlens.min when Integer @data["length"] else raise "Unexpected length" end end |
#modes_with_access ⇒ Object
list of modes that can potentially access the field
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/udb/obj/csr.rb', line 409 def modes_with_access case @data["priv_mode"] when "M" ["M"] when "S" ["M", "S", "VS"] when "U" ["M", "S", "U", "VS", "VU"] when "VS" ["M", "S", "VS"] when "D" ["M", "D"] else raise "unexpected priv mode" end end |
#priv_mode ⇒ String
Returns Least-privileged mode that can access this CSR. One of [‘m’, ‘s’, ‘u’, ‘vs’, ‘vu’].
72 73 74 |
# File 'lib/udb/obj/csr.rb', line 72 def priv_mode @data["priv_mode"] end |
#pruned_sw_read_ast(effective_xlen) ⇒ FunctionBodyAst
Returns Pruned (but not re-type-checked) AST for sw_read().
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 |
# File 'lib/udb/obj/csr.rb', line 570 def pruned_sw_read_ast(effective_xlen) raise ArgumentError, "effective_xlen is non-nil and is a #{effective_xlen.class} but must be an Integer" unless effective_xlen.nil? || effective_xlen.is_a?(Integer) @pruned_sw_read_ast ||= {} return @pruned_sw_read_ast[effective_xlen] unless @pruned_sw_read_ast[effective_xlen].nil? ast = type_checked_sw_read_ast(effective_xlen) symtab = fill_symtab(ast, effective_xlen) ast = ast.prune(symtab) ast.freeze_tree(@cfg_arch.symtab) symtab.pop symtab.release @pruned_sw_read_ast[effective_xlen] = ast end |
#reachable_functions(effective_xlen = nil, cache = T.let({}, T::Hash[Integer, Idl::AstNode::ReachableFunctionCacheType])) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/udb/obj/csr.rb', line 139 def reachable_functions(effective_xlen = nil, cache = T.let({}, T::Hash[Integer, Idl::AstNode::ReachableFunctionCacheType])) cache_key = effective_xlen return @memo.reachable_functions[cache_key] unless @memo.reachable_functions[cache_key].nil? fns = [] if has_custom_sw_read? xlens = if cfg_arch.multi_xlen? defined_in_all_bases? ? [32, 64] : [base] else [cfg_arch.possible_xlens[0]] end xlens.each do |xlen| ast = pruned_sw_read_ast(xlen) symtab = cfg_arch.symtab.deep_clone symtab.push(ast) fns.concat(ast.reachable_functions(symtab, cache.fetch(xlen))) end end if cfg_arch.multi_xlen? possible_fields_for(32).each do |field| fns.concat(field.reachable_functions(32, cache.fetch(32))) end possible_fields_for(64).each do |field| fns.concat(field.reachable_functions(64, cache.fetch(64))) end else possible_fields_for(cfg_arch.mxlen).each do |field| fns.concat(field.reachable_functions(cfg_arch.mxlen, cache.fetch(T.must(cfg_arch.mxlen)))) end end @memo.reachable_functions[cache_key] = fns.uniq end |
#sw_read_ast(symtab) ⇒ FunctionBodyAst
Returns The abstract syntax tree of the sw_read() function.
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 |
# File 'lib/udb/obj/csr.rb', line 518 def sw_read_ast(symtab) raise ArgumentError, "Argument should be a symtab" unless symtab.is_a?(Idl::SymbolTable) return @sw_read_ast if instance_variable_defined?(:@sw_read_ast) return (@sw_read_ast = nil) if @data["sw_read()"].nil? # now, parse the function @sw_read_ast = @cfg_arch.idl_compiler.compile_func_body( @data["sw_read()"], return_type: Idl::Type.new(:bits, width: 128), # big int to hold special return values name: "CSR[#{name}].sw_read()", input_file: __source, input_line: source_line(["sw_read()"]), symtab:, type_check: false ) raise "unexpected #{@sw_read_ast.class}" unless @sw_read_ast.is_a?(Idl::FunctionBodyAst) @sw_read_ast end |
#type_checked_pruned_sw_read_ast(effective_xlen) ⇒ FunctionBodyAst
Returns Pruned and re-type-checked AST for sw_read() Use this when you need the AST to be fully type-checked (e.g., for the type_check pass). For reachable_functions, use pruned_sw_read_ast directly.
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 |
# File 'lib/udb/obj/csr.rb', line 592 def type_checked_pruned_sw_read_ast(effective_xlen) raise ArgumentError, "effective_xlen is non-nil and is a #{effective_xlen.class} but must be an Integer" unless effective_xlen.nil? || effective_xlen.is_a?(Integer) @type_checked_pruned_sw_read_ast ||= {} return @type_checked_pruned_sw_read_ast[effective_xlen] if @type_checked_pruned_sw_read_ast.key?(effective_xlen) ast = pruned_sw_read_ast(effective_xlen) symtab = fill_symtab(type_checked_sw_read_ast(effective_xlen), effective_xlen) @cfg_arch.idl_compiler.type_check( ast, symtab, "CSR[#{name}].sw_read()" ) symtab.pop symtab.release @type_checked_pruned_sw_read_ast[effective_xlen] = ast end |
#type_checked_sw_read_ast(effective_xlen) ⇒ Object
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/udb/obj/csr.rb', line 486 def type_checked_sw_read_ast(effective_xlen) @type_checked_sw_read_asts ||= {} ast = @type_checked_sw_read_asts[effective_xlen.nil? ? :none : effective_xlen] return ast unless ast.nil? symtab = cfg_arch.symtab.global_clone symtab.push(ast) # all CSR instructions are 32-bit unless effective_xlen.nil? @xlen_var_cache ||= {} @xlen_var_cache[effective_xlen] ||= Idl::Var.new("__effective_xlen", BITS6_TYPE, effective_xlen).freeze symtab.add("__effective_xlen", @xlen_var_cache[effective_xlen]) end symtab.add("__instruction_encoding_size", ENCODING_SIZE_VAR) symtab.add( "__expected_return_type", BITS128_TYPE ) ast = sw_read_ast(symtab) @cfg_arch.idl_compiler.type_check( ast, symtab, "CSR[#{name}].sw_read()" ) symtab.pop symtab.release @type_checked_sw_read_asts[effective_xlen.nil? ? :none : effective_xlen] = ast end |
#value ⇒ Object Also known as: reset_value
87 88 89 90 91 |
# File 'lib/udb/obj/csr.rb', line 87 def value return nil unless fields.all? { |f| f.type == "RO" } fields.reduce(0) { |val, f| val | (T.cast(f.reset_value, Integer) << f.location.begin) } end |
#virtual_address ⇒ Integer?
82 83 84 |
# File 'lib/udb/obj/csr.rb', line 82 def virtual_address @data["virtual_address"] end |