1obj-y += acpi/
2obj-y += cpu/
3obj-y += genapic/
4obj-$(CONFIG_GUEST) += guest/
5obj-$(CONFIG_HVM) += hvm/
6obj-y += mm/
7obj-$(CONFIG_XENOPROF) += oprofile/
8obj-$(CONFIG_PV) += pv/
9obj-y += x86_64/
10
11alternative-y := alternative.init.o
12alternative-$(CONFIG_LIVEPATCH) :=
13obj-bin-y += $(alternative-y)
14obj-y += apic.o
15obj-y += bitops.o
16obj-bin-y += bzimage.init.o
17obj-bin-y += clear_page.o
18obj-bin-y += copy_page.o
19obj-y += cpuid.o
20obj-$(CONFIG_PV) += compat.o x86_64/compat.o
21obj-$(CONFIG_KEXEC) += crash.o
22obj-$(CONFIG_GDBSX) += debug.o
23obj-y += delay.o
24obj-y += desc.o
25obj-bin-y += dmi_scan.init.o
26obj-y += domctl.o
27obj-y += domain.o
28obj-bin-y += dom0_build.init.o
29obj-y += domain_page.o
30obj-y += e820.o
31obj-y += emul-i8254.o
32obj-y += extable.o
33obj-y += flushtlb.o
34obj-$(CONFIG_CRASH_DEBUG) += gdbstub.o
35obj-y += hypercall.o
36obj-y += i387.o
37obj-y += i8259.o
38obj-y += io_apic.o
39obj-$(CONFIG_LIVEPATCH) += alternative.o livepatch.o
40obj-y += msi.o
41obj-y += msr.o
42obj-$(CONFIG_INDIRECT_THUNK) += indirect-thunk.o
43obj-y += ioport_emulate.o
44obj-y += irq.o
45obj-$(CONFIG_KEXEC) += machine_kexec.o
46obj-y += mm.o x86_64/mm.o
47obj-$(CONFIG_HVM) += monitor.o
48obj-y += mpparse.o
49obj-y += nmi.o
50obj-y += numa.o
51obj-y += pci.o
52obj-y += percpu.o
53obj-y += physdev.o x86_64/physdev.o
54obj-y += platform_hypercall.o x86_64/platform_hypercall.o
55obj-y += psr.o
56obj-y += setup.o
57obj-y += shutdown.o
58obj-y += smp.o
59obj-y += smpboot.o
60obj-y += spec_ctrl.o
61obj-y += srat.o
62obj-y += string.o
63obj-y += sysctl.o
64obj-y += time.o
65obj-y += trace.o
66obj-y += traps.o
67obj-y += tsx.o
68obj-y += usercopy.o
69obj-y += x86_emulate.o
70obj-$(CONFIG_TBOOT) += tboot.o
71obj-y += hpet.o
72obj-y += vm_event.o
73obj-y += xstate.o
74extra-y += asm-macros.i
75
76ifneq ($(CONFIG_HVM),y)
77x86_emulate.o: CFLAGS-y += -Wno-unused-label
78endif
79x86_emulate.o: x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h
80
81efi-y := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \
82                      -O $(BASEDIR)/include/xen/compile.h ]; then \
83                         echo '$(TARGET).efi'; fi)
84
85ifneq ($(build_id_linker),)
86notes_phdrs = --notes
87else
88ifeq ($(CONFIG_PVH_GUEST),y)
89notes_phdrs = --notes
90endif
91endif
92
93ifdef CONFIG_LIVEPATCH
94all_symbols = --all-symbols
95ifdef CONFIG_FAST_SYMBOL_LOOKUP
96all_symbols = --all-symbols --sort-by-name
97endif
98else
99all_symbols =
100endif
101
102syms-warn-dup-y := --warn-dup
103syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
104syms-warn-dup-$(CONFIG_ENFORCE_UNIQUE_SYMBOLS) := --error-dup
105
106$(TARGET): TMP = $(@D)/.$(@F).elf32
107$(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
108	./boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TMP) $(XEN_IMG_OFFSET) \
109	               `$(NM) $(TARGET)-syms | sed -ne 's/^\([^ ]*\) . __2M_rwdata_end$$/0x\1/p'`
110	od -t x4 -N 8192 $(TMP)  | grep 1badb002 > /dev/null || \
111		{ echo "No Multiboot1 header found" >&2; false; }
112	od -t x4 -N 32768 $(TMP) | grep e85250d6 > /dev/null || \
113		{ echo "No Multiboot2 header found" >&2; false; }
114	mv $(TMP) $(TARGET)
115
116ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)
117
118ifeq ($(CONFIG_LTO),y)
119# Gather all LTO objects together
120prelink_lto.o: $(ALL_OBJS)
121	$(LD_LTO) -r -o $@ $^
122
123prelink-efi_lto.o: $(ALL_OBJS) efi/runtime.o efi/compat.o
124	$(LD_LTO) -r -o $@ $(filter-out %/efi/built_in.o,$^)
125
126# Link it with all the binary objects
127prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o FORCE
128	$(call if_changed,ld)
129
130prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o efi/boot.init.o FORCE
131	$(call if_changed,ld)
132else
133prelink.o: $(ALL_OBJS) FORCE
134	$(call if_changed,ld)
135
136prelink-efi.o: $(filter-out %/efi/built_in.o,$(ALL_OBJS)) efi/boot.init.o efi/runtime.o efi/compat.o FORCE
137	$(call if_changed,ld)
138endif
139
140targets += prelink.o prelink-efi.o
141
142$(TARGET)-syms: prelink.o xen.lds
143	$(LD) $(XEN_LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \
144	    $(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).0
145	$(NM) -pa --format=sysv $(@D)/.$(@F).0 \
146		| $(BASEDIR)/tools/symbols $(all_symbols) --sysv --sort \
147		>$(@D)/.$(@F).0.S
148	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0.o
149	$(LD) $(XEN_LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \
150	    $(@D)/.$(@F).0.o -o $(@D)/.$(@F).1
151	$(NM) -pa --format=sysv $(@D)/.$(@F).1 \
152		| $(BASEDIR)/tools/symbols $(all_symbols) --sysv --sort $(syms-warn-dup-y) \
153		>$(@D)/.$(@F).1.S
154	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).1.o
155	$(LD) $(XEN_LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \
156	    $(@D)/.$(@F).1.o -o $@
157	$(NM) -pa --format=sysv $(@D)/$(@F) \
158		| $(BASEDIR)/tools/symbols --xensyms --sysv --sort \
159		>$(@D)/$(@F).map
160	rm -f $(@D)/.$(@F).[0-9]* $(@D)/..$(@F).[0-9]*
161
162note.o: $(TARGET)-syms
163	$(OBJCOPY) -O binary --only-section=.note.gnu.build-id  $(BASEDIR)/xen-syms $@.bin
164	$(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 \
165		--rename-section=.data=.note.gnu.build-id -S $@.bin $@
166	rm -f $@.bin
167
168EFI_LDFLAGS = $(patsubst -m%,-mi386pep,$(XEN_LDFLAGS)) --subsystem=10
169EFI_LDFLAGS += --image-base=$(1) --stack=0,0 --heap=0,0 --strip-debug
170EFI_LDFLAGS += --section-alignment=0x200000 --file-alignment=0x20
171EFI_LDFLAGS += --major-image-version=$(XEN_VERSION)
172EFI_LDFLAGS += --minor-image-version=$(XEN_SUBVERSION)
173EFI_LDFLAGS += --major-os-version=2 --minor-os-version=0
174EFI_LDFLAGS += --major-subsystem-version=2 --minor-subsystem-version=0
175
176# Check if the compiler supports the MS ABI.
177export XEN_BUILD_EFI := $(shell $(CC) $(XEN_CFLAGS) -c efi/check.c -o efi/check.o 2>/dev/null && echo y)
178# Check if the linker supports PE.
179XEN_BUILD_PE := $(if $(XEN_BUILD_EFI),$(shell $(LD) -mi386pep --subsystem=10 -o efi/check.efi efi/check.o 2>/dev/null && echo y))
180CFLAGS-$(XEN_BUILD_EFI) += -DXEN_BUILD_EFI
181
182$(TARGET).efi: VIRT_BASE = 0x$(shell $(NM) efi/relocs-dummy.o | sed -n 's, A VIRT_START$$,,p')
183$(TARGET).efi: ALT_BASE = 0x$(shell $(NM) efi/relocs-dummy.o | sed -n 's, A ALT_START$$,,p')
184
185ifneq ($(build_id_linker),)
186ifeq ($(call ld-ver-build-id,$(LD) $(filter -m%,$(EFI_LDFLAGS))),y)
187CFLAGS-y += -DBUILD_ID_EFI
188EFI_LDFLAGS += $(build_id_linker)
189note_file := efi/buildid.o
190# NB: this must be the last input in the linker call, because inputs following
191# the -b option will all be treated as being in the specified format.
192note_file_option := -b pe-x86-64 $(note_file)
193else
194note_file := note.o
195endif
196else
197note_file :=
198endif
199note_file_option ?= $(note_file)
200
201ifeq ($(XEN_BUILD_PE),y)
202$(TARGET).efi: prelink-efi.o $(note_file) efi.lds efi/relocs-dummy.o efi/mkreloc
203	$(foreach base, $(VIRT_BASE) $(ALT_BASE), \
204	          $(LD) $(call EFI_LDFLAGS,$(base)) -T efi.lds -N $< efi/relocs-dummy.o \
205	                $(BASEDIR)/common/symbols-dummy.o $(note_file_option) -o $(@D)/.$(@F).$(base).0 &&) :
206	efi/mkreloc $(foreach base,$(VIRT_BASE) $(ALT_BASE),$(@D)/.$(@F).$(base).0) >$(@D)/.$(@F).0r.S
207	$(NM) -pa --format=sysv $(@D)/.$(@F).$(VIRT_BASE).0 \
208		| $(BASEDIR)/tools/symbols $(all_symbols) --sysv --sort >$(@D)/.$(@F).0s.S
209	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0r.o $(@D)/.$(@F).0s.o
210	$(foreach base, $(VIRT_BASE) $(ALT_BASE), \
211	          $(LD) $(call EFI_LDFLAGS,$(base)) -T efi.lds -N $< \
212	                $(@D)/.$(@F).0r.o $(@D)/.$(@F).0s.o $(note_file_option) -o $(@D)/.$(@F).$(base).1 &&) :
213	efi/mkreloc $(foreach base,$(VIRT_BASE) $(ALT_BASE),$(@D)/.$(@F).$(base).1) >$(@D)/.$(@F).1r.S
214	$(NM) -pa --format=sysv $(@D)/.$(@F).$(VIRT_BASE).1 \
215		| $(BASEDIR)/tools/symbols $(all_symbols) --sysv --sort >$(@D)/.$(@F).1s.S
216	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).1r.o $(@D)/.$(@F).1s.o
217	$(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T efi.lds -N $< \
218	                $(@D)/.$(@F).1r.o $(@D)/.$(@F).1s.o $(note_file_option) -o $@
219	$(NM) -pa --format=sysv $(@D)/$(@F) \
220		| $(BASEDIR)/tools/symbols --xensyms --sysv --sort >$(@D)/$(@F).map
221	rm -f $(@D)/.$(@F).[0-9]* $(@D)/..$(@F).[0-9]*
222else
223$(TARGET).efi: FORCE
224	rm -f $@
225	echo '$(if $(filter y,$(XEN_BUILD_EFI)),xen.efi generation,EFI support) disabled'
226endif
227
228efi/boot.init.o efi/runtime.o efi/compat.o efi/buildid.o efi/relocs-dummy.o: $(BASEDIR)/arch/x86/efi/built_in.o
229efi/boot.init.o efi/runtime.o efi/compat.o efi/buildid.o efi/relocs-dummy.o: ;
230
231asm-offsets.s: $(TARGET_SUBARCH)/asm-offsets.c $(BASEDIR)/include/asm-x86/asm-macros.h
232	$(CC) $(filter-out -Wa$(comma)% -flto,$(c_flags)) -S -o $@ $<
233
234asm-macros.i: CFLAGS-y += -D__ASSEMBLY__ -P
235
236$(BASEDIR)/include/asm-x86/asm-macros.h: asm-macros.i Makefile
237	echo '#if 0' >$@.new
238	echo '.if 0' >>$@.new
239	echo '#endif' >>$@.new
240	echo 'asm ( ".include \"$@\"" );' >>$@.new
241	echo '#if 0' >>$@.new
242	echo '.endif' >>$@.new
243	cat $< >>$@.new
244	echo '#endif' >>$@.new
245	$(call move-if-changed,$@.new,$@)
246
247efi.lds: AFLAGS-y += -DEFI
248xen.lds efi.lds: xen.lds.S
249	$(CPP) -P $(filter-out -Wa$(comma)%,$(a_flags)) -MQ $@ -o $@ $<
250
251boot/mkelf32: boot/mkelf32.c
252	$(HOSTCC) $(HOSTCFLAGS) -o $@ $<
253
254efi/mkreloc: efi/mkreloc.c
255	$(HOSTCC) $(HOSTCFLAGS) -g -o $@ $<
256
257.PHONY: clean
258clean::
259	rm -f asm-offsets.s *.lds boot/*.o boot/*~ boot/core boot/mkelf32
260	rm -f asm-macros.i $(BASEDIR)/include/asm-x86/asm-macros.*
261	rm -f $(BASEDIR)/.xen-syms.[0-9]* boot/.*.d $(BASEDIR)/.xen.elf32
262	rm -f $(BASEDIR)/.xen.efi.[0-9]* efi/*.efi efi/mkreloc
263	rm -f boot/cmdline.S boot/reloc.S boot/*.lnk boot/*.bin
264	rm -f note.o
265
266# Suppress loading of DEPS files for internal, temporary target files.  This
267# then also suppresses re-generation of the respective .*.d2 files.
268ifeq ($(filter-out .xen%.o,$(notdir $(MAKECMDGOALS))),)
269DEPS:=
270endif
271