当前位置: 首页 > article >正文

一个查看armv8系统寄存器-值-含义的方式

找到解压后的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.gz

tar 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 re

GREEN = '\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_content


def bit_64(value):
    result = str(bin(int(value)).replace("0b", "").zfill(64))
    reversed_content = ''.join(reversed(result))
    return reversed_content

def 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.documentElement
    field = 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].nodeValue
        field_msb = field_signal.getElementsByTagName('field_msb')[0].childNodes[0].nodeValue
        field_lsb = field_signal.getElementsByTagName('field_lsb')[0].childNodes[0].nodeValue
        int_field_msb = int(field_msb)
        int_field_lsb = int(field_lsb)
        field_description = field_signal.getElementsByTagName('field_description')[0].getElementsByTagName('para')[0].childNodes[0].nodeValue
        print_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].nodeValue
            field_value_description = field_value_instance.getElementsByTagName('field_value_description')[0].getElementsByTagName('para')[0].childNodes[0].nodeValue
            if 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


http://www.kler.cn/a/229151.html

相关文章:

  • 从 SQL 语句到数据库操作
  • Dubbo泛化调用
  • 怎么在iPhone手机上使用便签进行记录?
  • 微信小程序校园自助点餐系统实战:从设计到实现
  • 【25考研】西南交通大学软件工程复试攻略!
  • 工作中redis常用的5种场景
  • k8s学习-Kubernetes的网络
  • 开源免费的物联网网关 IoT Gateway
  • 手拉手Vue3+vite引入echarts
  • vue3.x 英文转换成简体中文
  • EasyExcel下载带下拉框和批注模板
  • fastapi mysql 开发restful 3
  • MongoDB的操作和理解
  • 6. 尚硅谷大数据111门技术+42个项目
  • ref和reactive, toRefs的使用
  • 计算机项目SpringBoot项目 办公小程序开发
  • haiku实现TemplatePairStack类
  • 【Linux】Linux权限(下)
  • 倒模专用制作耳机壳UV树脂:改性丙烯酸树脂
  • 保研机试算法训练个人记录笔记(三)
  • 代码随想录day18--二叉树的应用6
  • 速盾:cdn技术和原理是什么关系
  • transformers重要组件(模型与分词器)
  • 信息打点Day9
  • 02-Java抽象工厂模式 ( Abstract Factory Pattern )
  • 框架学习Maven