1 # SPDX-License-Identifier: GPL-2.0
3 # Makefile for Kernel-based Virtual Machine module, HYP/nVHE part
6 asflags-y := -D__KVM_NVHE_HYPERVISOR__
7 ccflags-y := -D__KVM_NVHE_HYPERVISOR__
9 obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \
10 hyp-main.o hyp-smp.o psci-relay.o
11 obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
12 ../fpsimd.o ../hyp-entry.o ../exception.o
15 ## Build rules for compiling nVHE hyp code
16 ## Output of this folder is `kvm_nvhe.o`, a partially linked object
17 ## file containing all nVHE hyp code and data.
20 hyp-obj := $(patsubst %.o,%.nvhe.o,$(obj-y))
22 extra-y := $(hyp-obj) kvm_nvhe.tmp.o hyp.lds
24 # 1) Compile all source files to `.nvhe.o` object files. The file extension
25 # avoids file name clashes for files shared with VHE.
26 $(obj)/%.nvhe.o: $(src)/%.c FORCE
27 $(call if_changed_rule,cc_o_c)
28 $(obj)/%.nvhe.o: $(src)/%.S FORCE
29 $(call if_changed_rule,as_o_S)
31 # 2) Compile linker script.
32 $(obj)/hyp.lds: $(src)/hyp.lds.S FORCE
33 $(call if_changed_dep,cpp_lds_S)
35 # 3) Partially link all '.nvhe.o' files and apply the linker script.
36 # Prefixes names of ELF sections with '.hyp', eg. '.hyp.text'.
37 # Note: The following rule assumes that the 'ld' rule puts LDFLAGS before
38 # the list of dependencies to form '-T $(obj)/hyp.lds'. This is to
39 # keep the dependency on the target while avoiding an error from
40 # GNU ld if the linker script is passed to it twice.
41 LDFLAGS_kvm_nvhe.tmp.o := -r -T
42 $(obj)/kvm_nvhe.tmp.o: $(obj)/hyp.lds $(addprefix $(obj)/,$(hyp-obj)) FORCE
45 # 4) Produce the final 'kvm_nvhe.o', ready to be linked into 'vmlinux'.
46 # Prefixes names of ELF symbols with '__kvm_nvhe_'.
47 $(obj)/kvm_nvhe.o: $(obj)/kvm_nvhe.tmp.o FORCE
48 $(call if_changed,hypcopy)
50 # The HYPCOPY command uses `objcopy` to prefix all ELF symbol names
51 # to avoid clashes with VHE code/data.
52 quiet_cmd_hypcopy = HYPCOPY $@
53 cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ $< $@
55 # Remove ftrace and Shadow Call Stack CFLAGS.
56 # This is equivalent to the 'notrace' and '__noscs' annotations.
57 KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS), $(KBUILD_CFLAGS))
59 # KVM nVHE code is run at a different exception code with a different map, so
60 # compiler instrumentation that inserts callbacks or checks into the code may
61 # cause crashes. Just disable it.
67 # Skip objtool checking for this directory because nVHE code is compiled with
68 # non-standard build rules.
69 OBJECT_FILES_NON_STANDARD := y