18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#
38c2ecf20Sopenharmony_ci# Makefile for Kernel-based Virtual Machine module, HYP/nVHE part
48c2ecf20Sopenharmony_ci#
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ciasflags-y := -D__KVM_NVHE_HYPERVISOR__
78c2ecf20Sopenharmony_ciccflags-y := -D__KVM_NVHE_HYPERVISOR__
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_cilib-objs := clear_page.o copy_page.o memcpy.o memset.o
108c2ecf20Sopenharmony_cilib-objs := $(addprefix ../../../lib/, $(lib-objs))
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ciobj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o hyp-main.o
138c2ecf20Sopenharmony_ciobj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
148c2ecf20Sopenharmony_ci	 ../fpsimd.o ../hyp-entry.o
158c2ecf20Sopenharmony_ciobj-y += $(lib-objs)
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci##
188c2ecf20Sopenharmony_ci## Build rules for compiling nVHE hyp code
198c2ecf20Sopenharmony_ci## Output of this folder is `kvm_nvhe.o`, a partially linked object
208c2ecf20Sopenharmony_ci## file containing all nVHE hyp code and data.
218c2ecf20Sopenharmony_ci##
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cihyp-obj := $(patsubst %.o,%.nvhe.o,$(obj-y))
248c2ecf20Sopenharmony_ciobj-y := kvm_nvhe.o
258c2ecf20Sopenharmony_ciextra-y := $(hyp-obj) kvm_nvhe.tmp.o hyp.lds
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci# 1) Compile all source files to `.nvhe.o` object files. The file extension
288c2ecf20Sopenharmony_ci#    avoids file name clashes for files shared with VHE.
298c2ecf20Sopenharmony_ci$(obj)/%.nvhe.o: $(src)/%.c FORCE
308c2ecf20Sopenharmony_ci	$(call if_changed_rule,cc_o_c)
318c2ecf20Sopenharmony_ci$(obj)/%.nvhe.o: $(src)/%.S FORCE
328c2ecf20Sopenharmony_ci	$(call if_changed_rule,as_o_S)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci# 2) Compile linker script.
358c2ecf20Sopenharmony_ci$(obj)/hyp.lds: $(src)/hyp.lds.S FORCE
368c2ecf20Sopenharmony_ci	$(call if_changed_dep,cpp_lds_S)
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci# 3) Partially link all '.nvhe.o' files and apply the linker script.
398c2ecf20Sopenharmony_ci#    Prefixes names of ELF sections with '.hyp', eg. '.hyp.text'.
408c2ecf20Sopenharmony_ci#    Note: The following rule assumes that the 'ld' rule puts LDFLAGS before
418c2ecf20Sopenharmony_ci#          the list of dependencies to form '-T $(obj)/hyp.lds'. This is to
428c2ecf20Sopenharmony_ci#          keep the dependency on the target while avoiding an error from
438c2ecf20Sopenharmony_ci#          GNU ld if the linker script is passed to it twice.
448c2ecf20Sopenharmony_ciLDFLAGS_kvm_nvhe.tmp.o := -r -T
458c2ecf20Sopenharmony_ci$(obj)/kvm_nvhe.tmp.o: $(obj)/hyp.lds $(addprefix $(obj)/,$(hyp-obj)) FORCE
468c2ecf20Sopenharmony_ci	$(call if_changed,ld)
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci# 4) Produce the final 'kvm_nvhe.o', ready to be linked into 'vmlinux'.
498c2ecf20Sopenharmony_ci#    Prefixes names of ELF symbols with '__kvm_nvhe_'.
508c2ecf20Sopenharmony_ci$(obj)/kvm_nvhe.o: $(obj)/kvm_nvhe.tmp.o FORCE
518c2ecf20Sopenharmony_ci	$(call if_changed,hypcopy)
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci# The HYPCOPY command uses `objcopy` to prefix all ELF symbol names
548c2ecf20Sopenharmony_ci# to avoid clashes with VHE code/data.
558c2ecf20Sopenharmony_ciquiet_cmd_hypcopy = HYPCOPY $@
568c2ecf20Sopenharmony_ci      cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ $< $@
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci# Remove ftrace, Shadow Call Stack, and CFI CFLAGS.
598c2ecf20Sopenharmony_ci# This is equivalent to the 'notrace', '__noscs', and '__nocfi' annotations.
608c2ecf20Sopenharmony_ciKBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) $(CC_FLAGS_CFI), $(KBUILD_CFLAGS))
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci# KVM nVHE code is run at a different exception code with a different map, so
638c2ecf20Sopenharmony_ci# compiler instrumentation that inserts callbacks or checks into the code may
648c2ecf20Sopenharmony_ci# cause crashes. Just disable it.
658c2ecf20Sopenharmony_ciGCOV_PROFILE	:= n
668c2ecf20Sopenharmony_ciKASAN_SANITIZE	:= n
678c2ecf20Sopenharmony_ciUBSAN_SANITIZE	:= n
688c2ecf20Sopenharmony_ciKCOV_INSTRUMENT	:= n
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci# Skip objtool checking for this directory because nVHE code is compiled with
718c2ecf20Sopenharmony_ci# non-standard build rules.
728c2ecf20Sopenharmony_ciOBJECT_FILES_NON_STANDARD := y
73