Class: Udb::CsrField
- Inherits:
-
DatabaseObject
- Object
- DatabaseObject
- Udb::CsrField
- Extended by:
- T::Sig
- Includes:
- Idl::CsrField, CertifiableObject
- Defined in:
- lib/udb/obj/csr_field.rb
Overview
A CSR field object
Defined Under Namespace
Classes: Alias, MemoizedState
Constant Summary collapse
- TYPE_DESC_MAP =
{ "RO" => <<~DESC, "RO-H" => <<~DESC, "RW" => <<~DESC, "RW-R" => <<~DESC, "RW-H" => <<~DESC, "RW-RH" => <<~DESC *Read-Write Restricted with Hardware update* Field is writable by software. Only certain values are legal. Writing an illegal value into the field is ignored, such that the field retains its prior state. Hardware also updates the field without an explicit software write.) DESC }.freeze
Instance Attribute Summary collapse
-
#parent ⇒ Csr
(also: #csr)
readonly
The Csr that defines this field.
Instance Method Summary collapse
-
#__source ⇒ Object
CSR fields are defined in their parent CSR YAML file.
-
#affected_by?(ext_ver) ⇒ Boolean
Whether or not the presence of ext_ver affects this CSR Field definition This does not take the parent CSR into account, i.e., a field can be unaffected by ext_ver even if the parent CSR is affected.
-
#alias ⇒ Alias?
The aliased field, or nil if there is no alias.
- #base ⇒ nil, Integer
-
#base32_only? ⇒ Boolean
Whether or not this field only exists when XLEN == 32.
-
#base64_only? ⇒ Boolean
Whether or not this field only exists when XLEN == 64.
- #cert_coverage_point(id) ⇒ CertNormativeRule? included from CertifiableObject
-
#cert_coverage_point_hash ⇒ Hash<String, CertNormativeRule>
included
from CertifiableObject
Hash with ID as key of all normative rules defined by database object.
- #cert_normative_rules ⇒ Array<CertNormativeRule> included from CertifiableObject
- #cert_test_procedure(id) ⇒ CertTestProcedure? included from CertifiableObject
-
#cert_test_procedure_hash ⇒ Hash<String, CertTestProcedure>
included
from CertifiableObject
Hash of all normative rules defined by database object.
- #cert_test_procedures ⇒ Array<CertTestProcedure> included from CertifiableObject
-
#defined_in_all_bases? ⇒ Boolean
Whether or not this field exists for any XLEN.
- #defined_in_base32? ⇒ Boolean
- #defined_in_base64? ⇒ Boolean
- #defined_in_base?(xlen) ⇒ Boolean
-
#dynamic_location? ⇒ Boolean
Whether or not the location of the field changes dynamically (e.g., based on mstatus.SXL) in the configuration.
- #dynamic_reset_value? ⇒ Boolean
- #exists? ⇒ Boolean
-
#exists_in_cfg?(cfg_arch) ⇒ Boolean
For a full config, whether or not the field is implemented For a partial config, whether or the it is possible for the field to be implemented.
- #fill_symtab_for_reset(ast) ⇒ Object
- #fill_symtab_for_sw_write(effective_xlen, ast) ⇒ Idl::SymbolTable
- #fill_symtab_for_type(effective_xlen, ast) ⇒ Idl::SymbolTable
-
#has_custom_sw_write? ⇒ Boolean
True if the CSR field has a custom sw_write function.
- #initialize(parent_csr, field_name, field_data) constructor
-
#location(effective_xlen = nil) ⇒ Range<Integer>
The location within the CSR as a range (single bit fields will be a range of size 1).
- #location_cond32 ⇒ String
- #location_cond64 ⇒ String
-
#location_pretty(effective_xlen = nil) ⇒ String
Pretty-printed location string.
- #max_width ⇒ Integer
-
#optional_in_cfg?(cfg_arch) ⇒ Boolean
For a partially configured cfg_arch, whether or not the field is optional (not mandatory or prohibited).
- #pruned_reset_value_ast ⇒ nil, Idl::FunctionBodyAst
- #pruned_sw_write_ast(effective_xlen) ⇒ nil, Idl::AstNode
- #pruned_type_ast(effective_xlen) ⇒ nil, Idl::FunctionBodyAst
-
#reachable_functions(effective_xlen) ⇒ Array<Idl::FunctionDefAst>
List of functions called through this field.
- #reset_value ⇒ String, Idl::ValueRbType
- #reset_value_ast ⇒ nil, Idl::FunctionBodyAst
- #reset_value_pretty ⇒ String
-
#source_line(path) ⇒ Integer
CSR field data starts at fields: NAME: with the YAML.
- #sw_write_ast(symtab) ⇒ nil, Idl::FunctionBodyAst
-
#type(effective_xlen = nil) ⇒ nil, String
returns the definitive type for a configuration.
- #type_ast ⇒ nil, Idl::FunctionBodyAst
- #type_checked_reset_value_ast ⇒ nil, Idl::FunctionBodyAst
-
#type_checked_sw_write_ast(symtab, effective_xlen) ⇒ Idl::FunctionBodyAst?
The abstract syntax tree of the sw_write() function, after being type checked.
- #type_checked_type_ast(effective_xlen) ⇒ nil, Idl::FunctionBodyAst
-
#type_desc(effective_xlen = nil) ⇒ String
Long description of the field type.
-
#type_pretty(effective_xlen = nil) ⇒ String
A pretty-printed type string.
-
#width(effective_xlen) ⇒ Integer
Number of bits in the field.
Constructor Details
#initialize(parent_csr, field_name, field_data)
57 58 59 60 61 |
# File 'lib/udb/obj/csr_field.rb', line 57 def initialize(parent_csr, field_name, field_data) super(field_data, parent_csr.data_path, parent_csr.arch, DatabaseObject::Kind::CsrField, name: field_name) @parent = parent_csr @memo = MemoizedState.new(reachable_functions: {}) end |
Instance Attribute Details
#parent ⇒ Csr (readonly) Also known as: csr
Returns The Csr that defines this field.
26 27 28 |
# File 'lib/udb/obj/csr_field.rb', line 26 def parent @parent end |
Instance Method Details
#__source ⇒ Object
CSR fields are defined in their parent CSR YAML file
64 |
# File 'lib/udb/obj/csr_field.rb', line 64 def __source = @parent.__source |
#affected_by?(ext_ver) ⇒ Boolean
Returns Whether or not the presence of ext_ver affects this CSR Field definition This does not take the parent CSR into account, i.e., a field can be unaffected by ext_ver even if the parent CSR is affected.
109 110 111 112 113 |
# File 'lib/udb/obj/csr_field.rb', line 109 def affected_by?(ext_ver) defined_by_condition.empty? \ ? false : defined_by_condition.satisfiability_depends_on_ext_req?(ext_ver.to_ext_req) end |
#alias ⇒ Alias?
Returns The aliased field, or nil if there is no alias.
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 |
# File 'lib/udb/obj/csr_field.rb', line 282 def alias return @alias unless @alias.nil? if @data.key?("alias") raise "Can't parse alias" unless data["alias"] =~ /^[a-z][a-z0-9]+\.[A-Z0-9]+(\[([0-9]+)(:[0-9]+)?\])?$/ csr_name = T.must(Regexp.last_match(1)) csr_field = Regexp.last_match(2) range = Regexp.last_match(3) range_start = Regexp.last_match(4) range_end = Regexp.last_match(5) csr_field = T.must(cfg_arch.csr(csr_name)).field(csr_field) range = if range.nil? csr_field.location elsif range_end.nil? (range_start.to_i..range_start.to_i) else (range_start.to_i..range_end[1..].to_i) end @alias = Alias.new(csr_field, range) end @alias end |
#base ⇒ nil, Integer
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/udb/obj/csr_field.rb', line 37 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 |
#base32_only? ⇒ Boolean
Returns Whether or not this field only exists when XLEN == 32.
695 |
# File 'lib/udb/obj/csr_field.rb', line 695 def base32_only? = base == 32 |
#base64_only? ⇒ Boolean
Returns Whether or not this field only exists when XLEN == 64.
691 |
# File 'lib/udb/obj/csr_field.rb', line 691 def base64_only? = base == 64 |
#cert_coverage_point(id) ⇒ CertNormativeRule? Originally defined in module CertifiableObject
#cert_coverage_point_hash ⇒ Hash<String, CertNormativeRule> Originally defined in module CertifiableObject
Returns Hash with ID as key of all normative rules defined by database object.
#cert_normative_rules ⇒ Array<CertNormativeRule> Originally defined in module CertifiableObject
#cert_test_procedure(id) ⇒ CertTestProcedure? Originally defined in module CertifiableObject
#cert_test_procedure_hash ⇒ Hash<String, CertTestProcedure> Originally defined in module CertifiableObject
Returns Hash of all normative rules defined by database object.
#cert_test_procedures ⇒ Array<CertTestProcedure> Originally defined in module CertifiableObject
#defined_in_all_bases? ⇒ Boolean
Returns Whether or not this field exists for any XLEN.
708 |
# File 'lib/udb/obj/csr_field.rb', line 708 def defined_in_all_bases? = base.nil? |
#defined_in_base32? ⇒ Boolean
698 |
# File 'lib/udb/obj/csr_field.rb', line 698 def defined_in_base32? = base != 64 |
#defined_in_base64? ⇒ Boolean
701 |
# File 'lib/udb/obj/csr_field.rb', line 701 def defined_in_base64? = base != 32 |
#defined_in_base?(xlen) ⇒ Boolean
704 |
# File 'lib/udb/obj/csr_field.rb', line 704 def defined_in_base?(xlen) = xlen == 32 ? defined_in_base32? : defined_in_base64? |
#dynamic_location? ⇒ Boolean
Returns Whether or not the location of the field changes dynamically (e.g., based on mstatus.SXL) in the configuration.
351 352 353 354 355 356 357 |
# File 'lib/udb/obj/csr_field.rb', line 351 def dynamic_location? # if there is no location_rv32, the the field never changes return false unless @data["location"].nil? # the field changes *if* some mode with access can change XLEN csr.modes_with_access.any? { |mode| @cfg_arch.multi_xlen_in_mode?(mode) } end |
#dynamic_reset_value? ⇒ Boolean
441 442 443 444 445 446 447 448 |
# File 'lib/udb/obj/csr_field.rb', line 441 def dynamic_reset_value? return false unless @data["reset_value"].nil? Idl::AstNode.value_try do reset_value false end || true end |
#exists? ⇒ Boolean
92 |
# File 'lib/udb/obj/csr_field.rb', line 92 def exists? = exists_in_cfg?(cfg_arch) |
#exists_in_cfg?(cfg_arch) ⇒ Boolean
For a full config, whether or not the field is implemented For a partial config, whether or the it is possible for the field to be implemented
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/udb/obj/csr_field.rb', line 77 def exists_in_cfg?(cfg_arch) if cfg_arch.fully_configured? parent.exists_in_cfg?(cfg_arch) && (base.nil? || cfg_arch.possible_xlens.include?(base)) && (defined_by_condition.satisfied_by_cfg_arch?(cfg_arch) == SatisfiedResult::Yes) elsif cfg_arch.partially_configured? parent.exists_in_cfg?(cfg_arch) && (base.nil? || cfg_arch.possible_xlens.include?(base)) && defined_by_condition.could_be_satisfied_by_cfg_arch?(cfg_arch) else true end end |
#fill_symtab_for_reset(ast) ⇒ Object
593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
# File 'lib/udb/obj/csr_field.rb', line 593 def fill_symtab_for_reset(ast) symtab = cfg_arch.symtab.global_clone symtab.push(ast) symtab.add("__expected_return_type", Idl::Type.new(:bits, width: max_width)) # XLEN at reset is always mxlen symtab.add( "__effective_xlen", Idl::Var.new("__effective_xlen", Idl::Type.new(:bits, width: 6), cfg_arch.mxlen) ) symtab end |
#fill_symtab_for_sw_write(effective_xlen, ast) ⇒ Idl::SymbolTable
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 |
# File 'lib/udb/obj/csr_field.rb', line 533 def fill_symtab_for_sw_write(effective_xlen, ast) symtab = cfg_arch.symtab.global_clone symtab.push(ast) # all CSR instructions are 32-bit symtab.add( "__instruction_encoding_size", Idl::Var.new("__instruction_encoding_size", Idl::Type.new(:bits, width: 6), 32) ) symtab.add( "__expected_return_type", Idl::Type.new(:bits, width: 128) ) symtab.add( "csr_value", Idl::Var.new("csr_value", csr.bitfield_type(@cfg_arch, effective_xlen)) ) if symtab.get("MXLEN").value.nil? symtab.add( "MXLEN", Idl::Var.new( "MXLEN", Idl::Type.new(:bits, width: 6, qualifiers: [:const]), effective_xlen, param: true ) ) end symtab end |
#fill_symtab_for_type(effective_xlen, ast) ⇒ Idl::SymbolTable
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
# File 'lib/udb/obj/csr_field.rb', line 565 def fill_symtab_for_type(effective_xlen, ast) symtab = cfg_arch.symtab.global_clone symtab.push(ast) # all CSR instructions are 32-bit symtab.add( "__instruction_encoding_size", Idl::Var.new("__instruction_encoding_size", Idl::Type.new(:bits, width: 6), 32) ) symtab.add( "__expected_return_type", Idl::Type.new(:enum_ref, enum_class: symtab.get("CsrFieldType")) ) if symtab.get("MXLEN").value.nil? symtab.add( "MXLEN", Idl::Var.new( "MXLEN", Idl::Type.new(:bits, width: 6, qualifiers: [:const]), effective_xlen, param: true ) ) end symtab end |
#has_custom_sw_write? ⇒ Boolean
Returns true if the CSR field has a custom sw_write function.
465 466 467 |
# File 'lib/udb/obj/csr_field.rb', line 465 def has_custom_sw_write? @data.key?("sw_write(csr_value)") && !@data["sw_write(csr_value)"].empty? end |
#location(effective_xlen = nil) ⇒ Range<Integer>
Returns the location within the CSR as a range (single bit fields will be a range of size 1).
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 |
# File 'lib/udb/obj/csr_field.rb', line 644 def location(effective_xlen = nil) key = if @data.key?("location") "location" else raise ArgumentError, "The location of #{csr.name}.#{name} changes with XLEN, so effective_xlen must be provided" unless [32, 64].include?(effective_xlen) "location_rv#{effective_xlen}" end raise "Missing location for #{csr.name}.#{name} (#{key})?" unless @data.key?(key) if @data[key].is_a?(Integer) csr_length = csr.length(effective_xlen || base) if csr_length.nil? # we don't know the csr length for sure, so we can only check again max_length if @data[key] > csr.max_length raise "Location (#{key} = #{@data[key]}) is past the max csr length (#{csr.max_length}) in #{csr.name}.#{name}" end elsif @data[key] > csr_length raise "Location (#{key} = #{@data[key]}) is past the csr length (#{csr.length(effective_xlen)}) in #{csr.name}.#{name}" end @data[key]..@data[key] else raise "Unexpected location field" unless @data[key].is_a?(String) e, s = @data[key].split("-").map(&:to_i) raise "Invalid location" if s > e csr_length = csr.length(effective_xlen || base) if csr_length.nil? # we don't know the csr length for sure, so we can only check again max_length if e > csr.max_length Udb.logger.warn "Location (#{key} = #{@data[key]}) is past the max csr length (#{csr.max_length}) in #{csr.name}.#{name}" end elsif e > csr_length Udb.logger.warn "Location (#{key} = #{@data[key]}) is past the csr length (#{csr_length}) in #{csr.name}.#{name}" end s..e end end |
#location_cond32 ⇒ String
732 733 734 735 736 737 738 739 740 741 742 743 744 745 |
# File 'lib/udb/obj/csr_field.rb', line 732 def location_cond32 case csr.priv_mode when "M" "CSR[misa].MXL == 0" when "S" "CSR[mstatus].SXL == 0" when "VS" "CSR[hstatus].VSXL == 0" when "U" "CSR[mstatus].UXL == 0" else raise "Unexpected priv mode #{csr.priv_mode} for #{csr.name}" end end |
#location_cond64 ⇒ String
748 749 750 751 752 753 754 755 756 757 758 759 760 761 |
# File 'lib/udb/obj/csr_field.rb', line 748 def location_cond64 case csr.priv_mode when "M" "CSR[misa].MXL == 1" when "S" "CSR[mstatus].SXL == 1" when "VS" "CSR[hstatus].VSXL == 1" when "U" "CSR[mstatus].UXL == 1" else raise "Unexpected priv mode #{csr.priv_mode} for #{csr.name}" end end |
#location_pretty(effective_xlen = nil) ⇒ String
Returns Pretty-printed location string.
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 |
# File 'lib/udb/obj/csr_field.rb', line 766 def location_pretty(effective_xlen = nil) derangeify = proc { |loc| next loc.min.to_s if loc.size == 1 "#{loc.max}:#{loc.min}" } if dynamic_location? condition = case csr.priv_mode when "M" "CSR[misa].MXL == %%" when "S" "CSR[mstatus].SXL == %%" when "VS" "CSR[hstatus].VSXL == %%" when "U" "CSR[mstatus].UXL == %%" else raise "Unexpected priv mode #{csr.priv_mode} for #{csr.name}" end if effective_xlen.nil? <<~LOC * #{derangeify.call(location(32))} when #{condition.sub('%%', '0')} * #{derangeify.call(location(64))} when #{condition.sub('%%', '1')} LOC else derangeify.call(location(effective_xlen)) end else derangeify.call(location(cfg_arch.mxlen)) end end |
#max_width ⇒ Integer
718 719 720 721 722 723 724 725 726 727 728 729 |
# File 'lib/udb/obj/csr_field.rb', line 718 def max_width @max_width ||= if base64_only? cfg_arch.possible_xlens.include?(64) ? width(64) : 0 elsif base32_only? cfg_arch.possible_xlens.include?(32) ? width(32) : 0 else @cfg_arch.possible_xlens.map do |xlen| width(xlen) end.max end end |
#optional_in_cfg?(cfg_arch) ⇒ Boolean
Returns For a partially configured cfg_arch, whether or not the field is optional (not mandatory or prohibited).
96 97 98 99 100 101 102 103 |
# File 'lib/udb/obj/csr_field.rb', line 96 def optional_in_cfg?(cfg_arch) raise "optional_in_cfg? should only be called on a partially configured cfg_arch" unless cfg_arch.partially_configured? exists_in_cfg?(cfg_arch) && defined_by_condition.empty? \ ? parent.optional_in_cfg?(cfg_arch) : (defined_by_condition.satisfied_by_cfg_arch?(cfg_arch) == SatisfiedResult::Maybe) end |
#pruned_reset_value_ast ⇒ nil, Idl::FunctionBodyAst
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/udb/obj/csr_field.rb', line 401 def pruned_reset_value_ast return @pruned_reset_value_ast unless @pruned_reset_value_ast.nil? return nil unless @data.key?("reset_value()") ast = T.must(type_checked_reset_value_ast) symtab = fill_symtab_for_reset(ast) ast = ast.prune(symtab) symtab.pop ast.freeze_tree(symtab) symtab.release @pruned_reset_value_ast = ast end |
#pruned_sw_write_ast(effective_xlen) ⇒ nil, Idl::AstNode
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
# File 'lib/udb/obj/csr_field.rb', line 612 def pruned_sw_write_ast(effective_xlen) return @pruned_sw_write_ast unless @pruned_sw_write_ast.nil? return nil unless @data.key?("sw_write(csr_value)") ast = T.must(type_checked_sw_write_ast(cfg_arch.symtab, effective_xlen)) return ast if cfg_arch.unconfigured? symtab = fill_symtab_for_sw_write(effective_xlen, ast) ast = ast.prune(symtab) raise "Symbol table didn't come back at global + 1" unless symtab.levels == 2 ast.freeze_tree(cfg_arch.symtab) cfg_arch.idl_compiler.type_check( ast, symtab, "CSR[#{name}].sw_write(csr_value)" ) symtab.pop symtab.release @pruned_sw_write_ast = ast end |
#pruned_type_ast(effective_xlen) ⇒ nil, Idl::FunctionBodyAst
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/udb/obj/csr_field.rb', line 173 def pruned_type_ast(effective_xlen) @pruned_type_ast ||= { 32 => nil, 64 => nil } return @pruned_type_ast[effective_xlen] unless @pruned_type_ast[effective_xlen].nil? ast = type_checked_type_ast(effective_xlen) if ast.nil? # there is no type() (it must be constant) return nil end symtab = fill_symtab_for_type(effective_xlen, ast) ast = ast.prune(symtab) symtab.release symtab = fill_symtab_for_type(effective_xlen, ast) ast.freeze_tree(symtab) @cfg_arch.idl_compiler.type_check( ast, symtab, "CSR[#{name}].type()" ) symtab.pop symtab.release @pruned_type_ast[effective_xlen] = ast end |
#reachable_functions(effective_xlen) ⇒ Array<Idl::FunctionDefAst>
Returns List of functions called through this field.
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 343 |
# File 'lib/udb/obj/csr_field.rb', line 312 def reachable_functions(effective_xlen) cache_key = effective_xlen.nil? ? :nil : effective_xlen return @memo.reachable_functions[cache_key] unless @memo.reachable_functions[cache_key].nil? fns = [] if has_custom_sw_write? ast = pruned_sw_write_ast(effective_xlen) unless ast.nil? sw_write_symtab = fill_symtab_for_sw_write(effective_xlen, ast) fns.concat ast.reachable_functions(sw_write_symtab) sw_write_symtab.release end end if @data.key?("type()") ast = pruned_type_ast(effective_xlen) unless ast.nil? type_symtab = fill_symtab_for_type(effective_xlen, ast) fns.concat ast.reachable_functions(type_symtab) type_symtab.release end end if @data.key?("reset_value()") ast = pruned_reset_value_ast unless ast.nil? symtab = fill_symtab_for_reset(ast) fns.concat ast.reachable_functions(symtab) symtab.release end end @memo.reachable_functions[cache_key] = fns.uniq end |
#reset_value ⇒ String, Idl::ValueRbType
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/udb/obj/csr_field.rb', line 420 def reset_value @reset_value ||= if @data.key?("reset_value") @data["reset_value"] else ast = T.must(pruned_reset_value_ast) symtab = fill_symtab_for_reset(ast) val = T.let(nil, T.untyped) value_result = Idl::AstNode.value_try do val = ast.return_value(symtab) end Idl::AstNode.value_else(value_result) do val = "UNDEFINED_LEGAL" end val = "UNDEFINED_LEGAL" if val == 0x1_0000_0000_0000_0000 symtab.release val end end |
#reset_value_ast ⇒ nil, Idl::FunctionBodyAst
362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/udb/obj/csr_field.rb', line 362 def reset_value_ast return @reset_value_ast unless @reset_value_ast.nil? return nil unless @data.key?("reset_value()") @reset_value_ast = cfg_arch.idl_compiler.compile_func_body( @data["reset_value()"], return_type: Idl::Type.new(:bits, width: max_width), name: "CSR[#{parent.name}].#{name}.reset_value()", input_file: csr.__source, input_line: csr.source_line(["fields", name, "reset_value()"]), symtab: cfg_arch.symtab, type_check: false ) end |
#reset_value_pretty ⇒ String
451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/udb/obj/csr_field.rb', line 451 def reset_value_pretty str = T.let(nil, T.nilable(Idl::ValueRbType)) value_result = Idl::AstNode.value_try do str = reset_value end Idl::AstNode.value_else(value_result) do ast = T.must(reset_value_ast) str = ast.gen_option_adoc end T.must(str).to_s end |
#source_line(path) ⇒ Integer
CSR field data starts at fields: NAME: with the YAML
68 69 70 |
# File 'lib/udb/obj/csr_field.rb', line 68 def source_line(path) super(["fields", name].concat(path)) end |
#sw_write_ast(symtab) ⇒ nil, Idl::FunctionBodyAst
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
# File 'lib/udb/obj/csr_field.rb', line 512 def sw_write_ast(symtab) return @sw_write_ast unless @sw_write_ast.nil? return nil if @data["sw_write(csr_value)"].nil? # now, parse the function @sw_write_ast = @cfg_arch.idl_compiler.compile_func_body( @data["sw_write(csr_value)"], return_type: Idl::Type.new(:bits, width: 128), # big int to hold special return values name: "CSR[#{csr.name}].#{name}.sw_write(csr_value)", input_file: csr.__source, input_line: csr.source_line(["fields", name, "sw_write(csr_value)"]), symtab:, type_check: false ) raise "unexpected #{@sw_write_ast.class}" unless @sw_write_ast.is_a?(Idl::FunctionBodyAst) @sw_write_ast end |
#type(effective_xlen = nil) ⇒ nil, String
returns the definitive type for a configuration
216 217 218 219 220 221 222 223 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 |
# File 'lib/udb/obj/csr_field.rb', line 216 def type(effective_xlen = nil) @type ||= { 32 => nil, 64 => nil } return @type[effective_xlen] unless @type[effective_xlen].nil? type = T.let(nil, T.untyped) type = if @data.key?("type") @data["type"] else # the type is config-specific... ast = T.must(type_checked_type_ast(effective_xlen)) begin symtab = fill_symtab_for_type(effective_xlen, ast) value_result = ast.value_try do type = case ast.return_value(symtab) when 0 "RO" when 1 "RO-H" when 2 "RW" when 3 "RW-R" when 4 "RW-H" when 5 "RW-RH" else raise "Unhandled CsrFieldType value" end end ast.value_else(value_result) do type = nil end ensure symtab&.pop symtab&.release end type # end # Idl::AstNode.value_else(value_result) do # warn "In parsing #{csr.name}.#{name}::type()" # raise " Return of type() function cannot be evaluated at compile time" # Idl::AstNode.value_error "" # end end @type[effective_xlen] = type end |
#type_ast ⇒ nil, Idl::FunctionBodyAst
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/udb/obj/csr_field.rb', line 118 def type_ast return @type_ast unless @type_ast.nil? return nil if @data["type()"].nil? idl_code = T.must(@data["type()"]) @type_ast = @cfg_arch.idl_compiler.compile_func_body( idl_code, name: "CSR[#{csr.name}].#{name}.type()", input_file: csr.__source, input_line: csr.source_line(["fields", name, "type()"]), symtab: @cfg_arch.symtab, type_check: false ) raise "ast is nil?" if @type_ast.nil? raise "unexpected #{@type_ast.class}" unless @type_ast.is_a?(Idl::FunctionBodyAst) @type_ast end |
#type_checked_reset_value_ast ⇒ nil, Idl::FunctionBodyAst
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/udb/obj/csr_field.rb', line 380 def type_checked_reset_value_ast return @type_checked_reset_value_ast unless @type_checked_reset_value_ast.nil? return nil unless @data.key?("reset_value()") ast = reset_value_ast symtab = fill_symtab_for_reset(ast) cfg_arch.idl_compiler.type_check( ast, symtab, "CSR[#{csr.name}].reset_value()" ) symtab.release @type_checked_reset_value_ast = ast end |
#type_checked_sw_write_ast(symtab, effective_xlen) ⇒ Idl::FunctionBodyAst?
Returns The abstract syntax tree of the sw_write() function, after being type checked.
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
# File 'lib/udb/obj/csr_field.rb', line 473 def type_checked_sw_write_ast(symtab, effective_xlen) @type_checked_sw_write_asts ||= {} ast = @type_checked_sw_write_asts[symtab.hash] return ast unless ast.nil? return nil unless @data.key?("sw_write(csr_value)") symtab_hash = symtab.hash symtab = symtab.global_clone symtab.push(ast) # all CSR instructions are 32-bit symtab.add( "__instruction_encoding_size", Idl::Var.new("__instruction_encoding_size", Idl::Type.new(:bits, width: 6), 32) ) symtab.add( "__expected_return_type", Idl::Type.new(:bits, width: 128) # to accommodate special return values (e.g., UNDEFIEND_LEGAL_DETERMINISITIC) ) symtab.add( "csr_value", Idl::Var.new("csr_value", csr.bitfield_type(@cfg_arch, effective_xlen)) ) ast = T.must(sw_write_ast(symtab)) @cfg_arch.idl_compiler.type_check( ast, symtab, "CSR[#{csr.name}].#{name}.sw_write()" ) symtab.pop symtab.release @type_checked_sw_write_asts[symtab_hash] = ast end |
#type_checked_type_ast(effective_xlen) ⇒ nil, Idl::FunctionBodyAst
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/udb/obj/csr_field.rb', line 144 def type_checked_type_ast(effective_xlen) @type_checked_type_ast ||= { 32 => nil, 64 => nil } return @type_checked_type_ast[effective_xlen] unless @type_checked_type_ast[effective_xlen].nil? ast = type_ast if ast.nil? # there is no type() (it must be constant) return nil end symtab = fill_symtab_for_type(effective_xlen, ast) cfg_arch.idl_compiler.type_check( ast, symtab, "CSR[#{name}].type()" ) symtab.pop symtab.release @type_checked_type_ast[effective_xlen] = ast end |
#type_desc(effective_xlen = nil) ⇒ String
Returns Long description of the field type.
852 853 854 |
# File 'lib/udb/obj/csr_field.rb', line 852 def type_desc(effective_xlen = nil) TYPE_DESC_MAP.fetch(type(effective_xlen), "") end |
#type_pretty(effective_xlen = nil) ⇒ String
Returns A pretty-printed type string.
271 272 273 274 275 276 277 278 |
# File 'lib/udb/obj/csr_field.rb', line 271 def type_pretty(effective_xlen = nil) str = type(effective_xlen) if str.nil? ast = T.must(type_ast) str = ast.gen_option_adoc end T.must(str) end |
#width(effective_xlen) ⇒ Integer
Returns Number of bits in the field.
713 714 715 |
# File 'lib/udb/obj/csr_field.rb', line 713 def width(effective_xlen) T.must(location(effective_xlen).size) end |