Lines Matching +full:block +full:- +full:fetch

1 #!/usr/bin/awk -f
3 #-
4 # Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org>
39 print "usage: bhnd_nvram_map.awk <input map> [-hd] [-o output file]"
74 if (ARGV[_i] == "--debug") {
76 } else if (ARGV[_i] == "-d" && OUT_T == null) {
78 } else if (ARGV[_i] == "-h" && OUT_T == null) {
80 } else if (ARGV[_i] == "-v") {
82 } else if (ARGV[_i] == "-o") {
88 } else if (ARGV[_i] == "--") {
91 } else if (ARGV[_i] !~ /^-/) {
102 print("error: one of -d or -h required")
111 if (OUTPUT_FILE == "-") {
127 UINT_REGEX = "^(0|[1-9][0-9]*)$"
128 HEX_REGEX = "^(0x[A-Fa-f0-9]+)$"
129 OFF_REGEX = "^(0|[1-9][0-9]*)|^(0x[A-Fa-f0-9]+)"
130 REL_OFF_REGEX = "^\\+(0|[1-9][0-9]*)|^\\+(0x[A-Fa-f0-9]+)"
132 ARRAY_REGEX = "\\[(0|[1-9][0-9]*)\\]"
135 IDENT_REGEX = "[A-Za-z_][A-Za-z0-9_]*"
195 SPROM_OP_BIND_SKIP_IN_MIN = -3 # minimum SKIP_IN value
267 # User-specifiable value formats
294 Int8Min = -128
296 Int16Min = -32768
298 Int32Min = -2147483648
348 VAccessInternal = obj_new(VAccess) # Implementation-Internal
400 class_add_prop(SromLayout, p_output_var_counts, # Map<int, int> (rev->count)
443 # Check for complete block closure
447 errorx("missing '}' for block opened on line " _block_start "")
454 # This also has a side-effect of generating a unique monotonic ID
574 output_depth--
593 # Write all top-level bhnd_sprom_layout entries
602 output_depth--
635 output_depth--
639 # Write a top-level bhnd_sprom_layout entry for the given revision
661 # Fetch signature definition
674 # Fetch sromrev definition
682 errorx("'sromrev' entry has non-u8 type '" \
722 output_depth--
785 # opc: The standard opcode for non-IMM encoded data, or null if none
794 # Fetch current type width
799 # SHIFT_IMM -- the imm value must be positive and divisible by
808 # OFFSET_REL_IMM -- the imm value must be positive, divisible
817 # Fetch current offset, calculate relative value and determine
820 _delta = value - _offset
826 sprintf("/* %#x + %#x -> %#x */\n", _offset,
845 # Can't encode as immediate; do we have a non-immediate form?
848 "non-immediate form was provided")
902 # Fetch current state
930 if (_vid_prev <= _vid && (_vid - _vid_prev) <= SPROM_OP_IMM_MAX) {
933 _vid - _vid_prev, null)
958 # Sanity-check range values
992 # Fetch current offset
997 # Encode (possibly a relative, 1-byte form) of the offset opcode
1101 "range %d-%d", skip_in,
1107 "range %d-%d", skip_out,
1111 # Fetch basic segment info
1154 # Fetch new segment's offset
1168 _delta = _seg_offset - _bind_off
1201 # skip_out values of 1, and must contain no buffered post-BIND opcodes
1303 # Fetch (and assert valid) our skip values
1321 # The one-byte BINDN form requires encoding the count
1325 _count -= _count
1339 _count -= _written
1342 # The 1-byte BIND form can encode the same SKIP values
1343 # as the 2-byte BINDN, with a implicit count of 1
1350 _count--
1357 # Write any buffered post-BIND opcodes
1373 # Check the per-variable bind count to determine whether
1405 sprintf("/* bind (%s @ %#x -> %#x) */\n",
1468 # Write entry-specific array length (SROM layouts may define array
1485 output_depth--
1540 output_depth--
1576 _tab_align += (TAB_WIDTH - (_tab_align % TAB_WIDTH)) % TAB_WIDTH
1589 _lead -= (_lead % TAB_WIDTH);
1594 _pad = align_to - _lead;
1613 # Calculate the tab alignment to be used with a given integer-indexed array
1625 # Variable group block
1655 # SROM layout block
1661 # SROM layout revision filter block
1757 # Check class<->prop cache
1772 # Found; add to class<->prop cache
1819 # Return the property ID for a given class-defined property
1832 # Return the property ID for a given class-defined property name
2000 # Fetch all properties
2055 # Fetch NR
2130 errorx("prop_to_path() called with non-property head")
2140 errorx("prop_path() called with non-property head")
2143 errorx("prop_path() called with non-property tail")
2151 errorx("prop_path_append() called with non-property tail")
2164 # Fetch a value from obj using a property path previously returned by
2208 # Fetch a value property value from obj, using a property ID returned by
2302 # If `prop_path*` is non-NULL, the corresponding property path (or property ID)
2319 _qsort(array, prop_path0, prop_path1, prop_path2, 0, _size-1)
2351 return (-1)
2365 _qpivot = int(first + int((last-first+1) * rand()))
2382 _qright--
2394 _qright--
2407 # If `prop_path` is non-NULL, the corresponding property path (or property ID)
2417 # Fetch the value (and optionally, a target property)
2449 return (array_get(array, _size-1))
2477 # Fetch the value of `key` from the map. Will throw an error if the
2540 # Handle Type equality -- we just check for trivial identity
2628 # The lhs type must be able to represent -at least- as
2665 _count = substr(str, RSTART+1, RLENGTH-2)
2686 _count = substr(str, RSTART+1, RLENGTH-2)
2764 errorx("can't append to non-continuation string '" \
2784 line = substr(line, 1, RLENGTH-1)
2852 return (_start "-" _end)
2969 # Return true if var is internal-only, and should not be included
3086 # The name is gauranteed to be unique across SROM layouts with non-overlapping
3140 # Fetch our parent's revision range, confirm that we're
3232 # Return the single, non-shifted, non-masked offset/segment for the given
3235 # This is used to fetch special-cased variable definitions that are required
3243 # Fetch the single offset's segment list
3252 # Fetch the single segment
3356 # Return a human-readable representation of a Segment instance
3422 return (i < 0 ? -i : i)
3446 # Populate hex parsing lookup table on-demand
3571 # Advance to the next non-comment input record
3591 return (-1)
3608 for (_i = 1; _i <= NF-n; _i++) {
3611 NF = NF - n
3629 # Fetch the current parser state
3645 _g_parse_stack_depth--
3651 # Fetch the current context object associated with this parser state
3669 _state = _g_parse_stack[_g_parse_stack_depth - _i]
3683 # Find opening brace and push a new parser state for a brace-delimited block.
3697 # brace-delimited block is discarded.
3701 error("internal error - no closing brace")
3703 # pop states until we exit the first enclosing block
3710 # strip everything prior to the block closure
3728 # 4-10 # revisions 4-10, inclusive
3738 if ($2 ~ "[0-9]*-[0-9*]") {
3739 split($2, _g_rev_range, "[ \t]*-[ \t]*")
3742 } else if ($2 ~ "(>|>=|<|<=)" && $3 ~ "[1-9][0-9]*") {
3751 _end = int($3)-1
3754 _end = int($3)-1
3758 } else if ($2 ~ "[1-9][0-9]*") {
3769 # Parse a variable group block starting at the current line
3800 # Push our variable group block
3806 # Parse a variable definition block starting at the current line
3855 # Push our variable definition block
3861 # Return a string containing the human-readable list of valid Fmt names
3937 # Fetch an indirect property reference for either the 'desc'
3971 # Parse a top-level SROM layout block starting at the current line
3973 # srom 4-7 {
3995 # Parse a nested srom range filter block starting at the current line
3996 # srom 4-7 {
3997 # # Filter block
4052 _attrs = substr($0, RSTART+1, RLENGTH-2)
4055 $0 = substr($0, RSTART+RLENGTH, length($0) - RSTART+RLENGTH)
4065 _shift = - parse_uint_string(_attr)
4097 # Fetch the offset value
4148 # Fetch our parent context
4194 # Seek to either the block start ('{'), or the attributes to be
4198 # Using the block syntax? */
4204 # Otherwise, we're using the simplified syntax -- create and