>From f0e489cebdac1ba94b8082bc240f2d889555f7ea Mon Sep 17 00:00:00 2001 From: Khushit Shah <[email protected]> Date: Fri, 19 Jun 2026 11:54:29 +0530 Subject: [PATCH] scripts: bug fixes in update-aarch64-cpu-sysreg-properties
Signed-off-by: Khushit Shah <[email protected]> --- While rebasing I found two bugs here: - It outputs incorrect value for field that defined a ValueRange. For example, CTX_CMPs (and all similar fields). - decimal 10 might be incorrectly parsed as to 2. Sending inline patch that I have added. --- .../update-aarch64-cpu-sysreg-properties.py | 56 ++++++++++++------- 1 file changed, 35 insertions(+), 21 deletions(-) mode change 100644 => 100755 scripts/update-aarch64-cpu-sysreg-properties.py diff --git a/scripts/update-aarch64-cpu-sysreg-properties.py b/scripts/update-aarch64-cpu-sysreg-properties.py old mode 100644 new mode 100755 index 9e829fda2e..2e28b03598 --- a/scripts/update-aarch64-cpu-sysreg-properties.py +++ b/scripts/update-aarch64-cpu-sysreg-properties.py @@ -106,6 +106,29 @@ def collect_fields(item, bit_offset=0): return fields +def parse_value_int(raw_val): + if raw_val is None or isinstance(raw_val, bool): + return None + + # may already be real number + if isinstance(raw_val, int): + return raw_val + + raw_str = str(raw_val).strip() + + if "'" in raw_str: + # quoted bitstring like "'0100'" + bits = raw_str.replace("'", "") + try: + return int(bits, 2) + except ValueError: + return None + + # unquoted, try decimal + try: + return int(raw_str, 0) + except ValueError: + return None def extract_field_enums(field): enums = [] @@ -124,32 +147,23 @@ def extract_field_enums(field): if not isinstance(val_entries, list): return enums + # A Values.ValueRange field specifies start and end value for a range. + # Don't enumerate anything for them. + for val_entry in val_entries: + if isinstance(val_entry, dict) and \ + val_entry.get("_type") == "Values.ValueRange": + return [] + for val_entry in val_entries: if not isinstance(val_entry, dict): continue - + if val_entry.get("_type") == "Values.Value": - raw_val = val_entry.get("value") - if raw_val is None: + int_val = parse_value_int(val_entry.get("value")) + if int_val is None: continue - - # some of the values have ' like "'0100'" - raw_val_str = str(raw_val).strip().replace("'", "") - - try: - # convert into bin - int_val = int(raw_val_str, 2) - except ValueError: - try: - # Fallback to dec if not bin - int_val = int(raw_val_str, 0) - except ValueError: - continue - - enums.append({ - 'value': int_val - }) - + enums.append({'value': int_val}) + return enums def generate_sysreg_properties_from_registers_json(id_reg_names, raw_json_path): -- 2.52.0
