找到解压后的SysReg_xml_v86A-2019-12
目录
wget https://developer.arm.com/-/media/developer/products/architecture/armv8-a-architecture/2019-12/SysReg_xml_v86A-2019-12.tar.gz
wget https://developer.arm.com/-/media/developer/products/architecture/armv8-a-architecture/2019-12/A64_ISA_xml_v86A-2019-12.tar.gz
wget https://developer.arm.com/-/media/developer/products/architecture/armv8-a-architecture/2019-12/AArch32_ISA_xml_v86A-2019-12.tar.gztar zxf A64_ISA_xml_v86A-2019-12.tar.gz
tar zxf AArch32_ISA_xml_v86A-2019-12.tar.gz
tar zxf SysReg_xml_v86A-2019-12.tar.gz
替换脚本中的dir_path
路径
from xml.dom.minidom import parseString
import sys
import os
import reGREEN = '\033[32m'
RED = '\033[31m'
YELLOW = '\033[33m'
END_COLOR = '\033[0m'def print_red(content):print(RED + content + END_COLOR)def print_green(content):print(GREEN + content + END_COLOR)def print_yellow(content):print(YELLOW + content + END_COLOR)def bit_32(value):result = str(bin(int(value)).replace("0b", "").zfill(32))reversed_content = ''.join(reversed(result))return reversed_contentdef bit_64(value):result = str(bin(int(value)).replace("0b", "").zfill(64))reversed_content = ''.join(reversed(result))return reversed_contentdef parse_system_register_xml(file_path, register_value):f = open(file_path)lines = f.read()xml_string = lines.replace("<arm-defined-word>", "").replace("</arm-defined-word>", "").replace("<binarynumber>", '').\replace("</binarynumber>", "").replace("<instruction>", '').replace("</instruction>", '')xml_string = re.sub("<register_link[\w\W]*?>", '', xml_string)xml_string = re.sub("</register_link>", '', xml_string)dom = parseString(xml_string)data = dom.documentElementfield = data.getElementsByTagName('field')# 获取该寄存器的bit长度bit_len = int(data.getElementsByTagName('fields')[0].getAttribute('length'))content = "Not value"if bit_len == 64:content = bit_64(register_value)elif bit_len == 32:content = bit_32(register_value)for field_signal in field:print("------------------------------------------------------------------------------------------------")id = field_signal.getAttribute('id')# print(str(id))field_name = field_signal.getElementsByTagName('field_name')[0].childNodes[0].nodeValuefield_msb = field_signal.getElementsByTagName('field_msb')[0].childNodes[0].nodeValuefield_lsb = field_signal.getElementsByTagName('field_lsb')[0].childNodes[0].nodeValueint_field_msb = int(field_msb)int_field_lsb = int(field_lsb)field_description = field_signal.getElementsByTagName('field_description')[0].getElementsByTagName('para')[0].childNodes[0].nodeValueprint_yellow(str(id).strip() + "\t" + str(field_description).strip())value = '0b' + ''.join(reversed(content[int_field_lsb:int_field_msb+1]))# 解析赋值field_value = field_signal.getElementsByTagName('field_values')[0]field_value_instances = field_value.getElementsByTagName('field_value_instance')for field_value_instance in field_value_instances:field_value = field_value_instance.getElementsByTagName('field_value')[0].childNodes[0].nodeValuefield_value_description = field_value_instance.getElementsByTagName('field_value_description')[0].getElementsByTagName('para')[0].childNodes[0].nodeValueif field_value == value:if field_value == '0b0' or field_value == '0b00':print_red("\t" + field_value + " :\t" + field_value_description)else:print_green("\t" + field_value + " :\t" + field_value_description)def search_file(arch, register_name):dir_path = "/Users/showme/workspace/tools/mra_tools/v8.6/SysReg_xml_v86A-2019-12"return dir_path + "/" + arch + "-" + register_name + ".xml"def do(arch, register_name, register_value):file_path = search_file(arch, register_name)if not os.path.exists(file_path):print_red("file not found")exit(0)parse_system_register_xml(file_path, register_value)def help():print("use: ./main.py AArch32|AArch64 register_name hex_register_value")print("use: ./main.py 32|64 register_name hex_register_value")exit(0)if __name__ == '__main__':if len(sys.argv) != 4:help()arch = ""if "32" in str(sys.argv[1]):arch = "AArch32"elif "64" in str(sys.argv[1]):arch = "AArch64"else:help()register_name = str(sys.argv[2]).lower()register_value = int(sys.argv[3], 16)do(arch, register_name, register_value)
运行
python3 ./parse_xml.py AArch64 SCTLR_EL3 0x30C50830
参考
https://github.com/alastairreid/mra_tools
https://github.com/lelegard/arm-cpusysregs
https://github.com/ashwio/arm64-sysreg-lib