From: Eric Auger <eric.au...@redhat.com>

Introduce scripts that automate the generation of system register
definitions from a given linux source tree arch/arm64/tools/sysreg.

Invocation of
./update-aarch64-sysreg-code.sh $PATH_TO_LINUX_SOURCE_TREE
in scripts directory generates target/arm/cpu-sysregs.h.inc
containing defines for all system registers.

[CH: update to handle current kernel sysregs structure, and to emit
     the re-worked register structures; cpu properties will be added
     later]
Reviewed-by: Sebastian Ott <seb...@redhat.com>
Signed-off-by: Eric Auger <eric.au...@redhat.com>
Signed-off-by: Cornelia Huck <coh...@redhat.com>
---
 MAINTAINERS                            |  1 +
 scripts/arm-gen-cpu-sysregs-header.awk | 37 ++++++++++++++++++++++++++
 scripts/update-aarch64-sysreg-code.sh  | 32 ++++++++++++++++++++++
 3 files changed, 70 insertions(+)
 create mode 100755 scripts/arm-gen-cpu-sysregs-header.awk
 create mode 100755 scripts/update-aarch64-sysreg-code.sh

diff --git a/MAINTAINERS b/MAINTAINERS
index 28b3dd2684b4..01334cb93ca1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -443,6 +443,7 @@ M: Peter Maydell <peter.mayd...@linaro.org>
 L: qemu-...@nongnu.org
 S: Maintained
 F: target/arm/kvm.c
+F: scripts/*-sysreg*
 
 MIPS KVM CPUs
 M: Huacai Chen <chenhua...@kernel.org>
diff --git a/scripts/arm-gen-cpu-sysregs-header.awk 
b/scripts/arm-gen-cpu-sysregs-header.awk
new file mode 100755
index 000000000000..f92bbbafa727
--- /dev/null
+++ b/scripts/arm-gen-cpu-sysregs-header.awk
@@ -0,0 +1,37 @@
+#!/bin/awk -f
+# SPDX-License-Identifier: GPL-2.0-or-later
+# arm-gen-cpu-sysregs-header.awk: arm64 sysreg header include generator
+#
+# Usage: awk -f arm-gen-cpu-sysregs-header.awk 
$LINUX_PATH/arch/arm64/tools/sysreg
+
+BEGIN {
+    print "/* SPDX-License-Identifier: GPL-2.0-or-later */"
+    print "/* GENERATED FILE, DO NOT EDIT */"
+    print "/* use arm-gen-cpu-sysregs-header.awk to regenerate */"
+} END {
+    print ""
+}
+
+# skip blank lines and comment lines
+/^$/ { next }
+/^[\t ]*#/ { next }
+
+/^Sysreg\t/ || /^Sysreg /{
+
+       reg = $2
+       op0 = $3
+       op1 = $4
+       crn = $5
+       crm = $6
+       op2 = $7
+
+       if (op0 == 3 && (op1==0 || op1==1 || op1==3) && crn==0 && (crm>=0 && 
crm<=7) && (op2>=0 && op2<=7)) {
+           print "DEF("reg", "op0", "op1", "crn", "crm", "op2")"
+       }
+       next
+}
+
+{
+       /* skip all other lines */
+       next
+}
diff --git a/scripts/update-aarch64-sysreg-code.sh 
b/scripts/update-aarch64-sysreg-code.sh
new file mode 100755
index 000000000000..7bba0bcd6f66
--- /dev/null
+++ b/scripts/update-aarch64-sysreg-code.sh
@@ -0,0 +1,32 @@
+#!/bin/sh -e
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Update target/arm/cpu-sysregs.h
+# from a linux source tree (arch/arm64/tools/sysreg)
+#
+# Copyright Red Hat, Inc. 2024
+#
+# Authors:
+#          Eric Auger <eric.au...@redhat.com>
+#
+
+scripts="$(dirname "$0")"
+linux="$1"
+output="$2"
+
+if [ -z "$linux" ] || ! [ -d "$linux" ]; then
+    cat << EOF
+usage: update-aarch64-sysreg-code.sh LINUX_PATH [OUTPUT_PATH]
+
+LINUX_PATH      Linux kernel directory to obtain the register definitions from
+OUTPUT_PATH     output directory, usually the qemu source tree (default: $PWD)
+EOF
+    exit 1
+fi
+
+if [ -z "$output" ]; then
+    output="$PWD"
+fi
+
+awk -f $scripts/arm-gen-cpu-sysregs-header.awk \
+    $linux/arch/arm64/tools/sysreg > $output/target/arm/cpu-sysregs.h.inc
-- 
2.49.0


Reply via email to