Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
google
GitHub Repository: google/crosvm
Path: blob/main/aarch64_sys_reg/gen.sh
5392 views
1
#!/usr/bin/env bash
2
# Copyright 2025 The ChromiumOS Authors
3
# Use of this source code is governed by a BSD-style license that can be
4
# found in the LICENSE file.
5
6
# Regenerate AArch64 system register constants.
7
# This is the WRONG WAY to parse XML - don't try this at home.
8
9
cd "$(dirname "$0")"
10
11
echo >special.txt
12
for reg in SysReg_xml_A_profile-2024-12/AArch64-*.xml; do
13
data="$(grep -T -E -A13 'accessor="(MRS|MSR)' $reg; echo --)"
14
15
while IFS= read -r -d '--' reg; do
16
if [[ -z "$reg" ]]; then
17
continue
18
fi
19
20
reg_name="$(echo $reg | grep access_mechanism | awk '{ print $3 }' | tr -d '"')"
21
22
if [[ -z "$reg_name" ]]; then
23
continue
24
fi
25
26
op0="$(echo $reg | grep -E -o 'n="op0" v="0b[01]+' | awk '{ print $2 }' | sed -e 's/v="//')"
27
op1="$(echo $reg | grep -E -o 'n="op1" v="0b[01]+' | awk '{ print $2 }' | sed -e 's/v="//')"
28
crn="$(echo $reg | grep -E -o 'n="CRn" v="0b[01]+' | awk '{ print $2 }' | sed -e 's/v="//')"
29
crm="$(echo $reg | grep -E -o 'n="CRm" v="0b[01]+' | awk '{ print $2 }' | sed -e 's/v="//')"
30
op2="$(echo $reg | grep -E -o 'n="op2" v="0b[01]+' | awk '{ print $2 }' | sed -e 's/v="//')"
31
32
# skip parameterized regs
33
if [[ ${#op0} -ne 4 || ${#op1} -ne 5 || ${#crn} -ne 6 || ${#crm} -ne 6 || ${#op2} -ne 5 ]]; then
34
echo $reg_name >> special.txt
35
continue
36
fi
37
38
# prefix with the numeric value for sorting
39
printf "${op0}${op1}${crn}${crm}${op2}\tpub const %-19s : AArch64SysRegId = AArch64SysRegId::new_unchecked(${op0}, ${op1}, ${crn}, ${crm}, ${op2});\n" "${reg_name}"
40
done <<< "$data"
41
done > gen-unsorted.rs
42
43
cat >src/gen.rs <<EOF
44
/* automatically generated by gen.sh - do not manually edit */
45
46
#![cfg_attr(rustfmt, rustfmt_skip)]
47
#![allow(non_upper_case_globals)]
48
49
use crate::AArch64SysRegId;
50
51
// Op0 Op1 CRn CRm Op2
52
EOF
53
54
# Sort numerically, remove duplicates, and trim the sorting prefix.
55
sort gen-unsorted.rs | uniq | cut -f2- -d$'\t' >> src/gen.rs
56
rm gen-unsorted.rs
57
58
echo "These registers may require special handling:"
59
sort special.txt | uniq | sed -e 's/&lt;/</g' -e 's/&gt;/>/g'
60
61