Add the infrastructure to extract KVM/arm64 code into s390 at built time similar to the arm64 header sharing. Add copy-arm64c.awk hat detects ARM64_S390_COMMON markers and extracts marked section into an .inc file that can be consumed by arm on s390 host code. If no marker is found make will fail. To ensure that no code is consumed twice by accident a guard is added during file generation. A s390 C file wanting to consume such an inc file must first define __INCL_GEN_ARM_FILE otherwise the inc file will emit a compile error. Example: #define __INCL_GEN_ARM_FILE #include #undef __INCL_GEN_ARM_FILE Signed-off-by: Steffen Eiden --- arch/s390/kvm/arm64/Makefile.gen | 30 +++++++++++++ arch/s390/kvm/arm64/copy-arm64c.awk | 69 +++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 arch/s390/kvm/arm64/Makefile.gen create mode 100644 arch/s390/kvm/arm64/copy-arm64c.awk diff --git a/arch/s390/kvm/arm64/Makefile.gen b/arch/s390/kvm/arm64/Makefile.gen new file mode 100644 index 000000000000..2e8838bc6921 --- /dev/null +++ b/arch/s390/kvm/arm64/Makefile.gen @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Extracts ARM64 marked sections to .inc files that are included by main source +# files + +# List of ARM64 C files to extract +ARM64_CFILES := \ + arm.c \ + guest.c \ + reset.c \ + handle_exit.c \ + mmio.c \ + +quiet_cmd_extract_inc = GEN $@ + cmd_extract_inc = mkdir -p $(dir $@); \ + $(AWK) -f $(src)/copy-arm64c.awk $< > $@ || \ + { echo "Error: No ARM64_S390_COMMON markers in $<" >&2; rm -f $@; exit 1; } + +$(obj)/generated/%.inc: $(srctree)/arch/arm64/kvm/%.c $(src)/copy-arm64c.awk FORCE + $(call if_changed,extract_inc) + +ARM64_INC_FILES := $(foreach cfile,$(ARM64_CFILES),generated/$(basename $(cfile)).inc) + +targets += $(ARM64_INC_FILES) +clean-files += generated/*.inc + +$(addprefix $(obj)/,$(kvm-arm64-obj)): $(addprefix $(obj)/,$(ARM64_INC_FILES)) + +$(foreach cfile,$(basename $(ARM64_CFILES)),\ + $(eval $(obj)/$(cfile).o: $(obj)/generated/$(cfile).inc)) diff --git a/arch/s390/kvm/arm64/copy-arm64c.awk b/arch/s390/kvm/arm64/copy-arm64c.awk new file mode 100644 index 000000000000..45d9c7034c17 --- /dev/null +++ b/arch/s390/kvm/arm64/copy-arm64c.awk @@ -0,0 +1,69 @@ +#!/usr/bin/awk -f +# SPDX-License-Identifier: GPL-2.0 +# +# Extract marked sections from ARM64 C files for sharing with s390 KVM +# +# Usage: share-arm64-cfile.awk +# +# Extracts all sections between start/end markers. If no markers found, signals failure. + +BEGIN { + # Constants + start_pattern = "^#ifdef ARM64_S390_COMMON$" + end_pattern = "^#endif /\\* ARM64_S390_COMMON \\*/$" + + # State variables + copying = found_marker = 0 + file_header_done = 0 +} + +!file_header_done { + if (/^\/\*/ || /^\/\/ SPDX-License-Identifier:/) { + print + next + } + if (/[[:space:]]\*([[:space:]]|$)/) { + print + next + } + if (/\*\//) { + print " *" + } else { + print "/*" + } + + filename = FILENAME + sub(/^.*arch\/arm64\//, "arch/arm64/", filename) + print " * This file was automatically generated from " filename + print " * Do not modify this file directly." + print " */" + print "" + print "#ifndef __INCL_GEN_ARM_FILE" + print "#error included .inc file w/o proper guard definition" + print "#undef __INCL_GEN_ARM_FILE" + print "#endif /* __INCL_GEN_ARM_FILE */" + print "" + + file_header_done = 1 +} + +$0 ~ start_pattern { + copying = found_marker = 1 + next +} + +$0 ~ end_pattern { + copying = 0 + next +} + +copying { + gsub(/#include