1subdir-y += acpi
2subdir-y += cpu
3subdir-y += genapic
4subdir-$(CONFIG_XEN_GUEST) += guest
5subdir-$(CONFIG_HVM) += hvm
6subdir-y += mm
7subdir-$(CONFIG_XENOPROF) += oprofile
8subdir-$(CONFIG_PV) += pv
9subdir-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-y += compat.o x86_64/compat.o
21obj-$(CONFIG_KEXEC) += crash.o
22obj-y += debug.o
23obj-y += delay.o
24obj-bin-y += dmi_scan.init.o
25obj-y += domctl.o
26obj-y += domain.o
27obj-bin-y += dom0_build.init.o
28obj-y += domain_page.o
29obj-y += e820.o
30obj-y += extable.o
31obj-y += flushtlb.o
32obj-$(CONFIG_CRASH_DEBUG) += gdbstub.o
33obj-y += hypercall.o
34obj-y += i387.o
35obj-y += i8259.o
36obj-y += io_apic.o
37obj-$(CONFIG_LIVEPATCH) += alternative.o livepatch.o
38obj-y += msi.o
39obj-y += msr.o
40obj-y += ioport_emulate.o
41obj-y += irq.o
42obj-$(CONFIG_KEXEC) += machine_kexec.o
43obj-y += microcode_amd.o
44obj-y += microcode_intel.o
45obj-y += microcode.o
46obj-y += mm.o x86_64/mm.o
47obj-y += 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 += srat.o
61obj-y += string.o
62obj-y += sysctl.o
63obj-y += time.o
64obj-y += trace.o
65obj-y += traps.o
66obj-y += usercopy.o
67obj-y += x86_emulate.o
68obj-$(CONFIG_TBOOT) += tboot.o
69obj-y += hpet.o
70obj-y += vm_event.o
71obj-y += xstate.o
72
73x86_emulate.o: x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h
74
75efi-y := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \
76                      -O $(BASEDIR)/include/xen/compile.h ]; then \
77                         echo '$(TARGET).efi'; fi)
78
79shim-$(CONFIG_PVH_GUEST) := $(TARGET)-shim
80
81ifneq ($(build_id_linker),)
82notes_phdrs = --notes
83else
84notes_phdrs =
85endif
86
87ifdef CONFIG_LIVEPATCH
88all_symbols = --all-symbols
89ifdef CONFIG_FAST_SYMBOL_LOOKUP
90all_symbols = --all-symbols --sort-by-name
91endif
92else
93all_symbols =
94endif
95
96syms-warn-dup-y := --warn-dup
97syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
98
99$(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
100	./boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TARGET) $(XEN_IMG_OFFSET) \
101	               `$(NM) $(TARGET)-syms | sed -ne 's/^\([^ ]*\) . __2M_rwdata_end$$/0x\1/p'`
102
103ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)
104
105ifeq ($(CONFIG_LTO),y)
106# Gather all LTO objects together
107prelink_lto.o: $(ALL_OBJS)
108	$(LD_LTO) -r -o $@ $^
109
110prelink-efi_lto.o: $(ALL_OBJS) efi/runtime.o efi/compat.o
111	$(guard) $(LD_LTO) -r -o $@ $(filter-out %/efi/built_in.o,$^)
112
113# Link it with all the binary objects
114prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o
115	$(LD) $(LDFLAGS) -r -o $@ $^
116
117prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o efi/boot.init.o
118	$(guard) $(LD) $(LDFLAGS) -r -o $@ $^
119else
120prelink.o: $(ALL_OBJS)
121	$(LD) $(LDFLAGS) -r -o $@ $^
122
123prelink-efi.o: $(ALL_OBJS) efi/boot.init.o efi/runtime.o efi/compat.o
124	$(guard) $(LD) $(LDFLAGS) -r -o $@ $(filter-out %/efi/built_in.o,$^)
125endif
126
127$(BASEDIR)/common/symbols-dummy.o:
128	$(MAKE) -f $(BASEDIR)/Rules.mk -C $(BASEDIR)/common symbols-dummy.o
129
130$(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o
131	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \
132	    $(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).0
133	$(NM) -pa --format=sysv $(@D)/.$(@F).0 \
134		| $(BASEDIR)/tools/symbols $(all_symbols) --sysv --sort \
135		>$(@D)/.$(@F).0.S
136	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0.o
137	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \
138	    $(@D)/.$(@F).0.o -o $(@D)/.$(@F).1
139	$(NM) -pa --format=sysv $(@D)/.$(@F).1 \
140		| $(BASEDIR)/tools/symbols $(all_symbols) --sysv --sort $(syms-warn-dup-y) \
141		>$(@D)/.$(@F).1.S
142	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).1.o
143	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \
144	    $(@D)/.$(@F).1.o -o $@
145	$(NM) -pa --format=sysv $(@D)/$(@F) \
146		| $(BASEDIR)/tools/symbols --xensyms --sysv --sort \
147		>$(@D)/$(@F).map
148	rm -f $(@D)/.$(@F).[0-9]*
149
150# Use elf32-x86-64 if toolchain support exists, elf32-i386 otherwise.
151$(TARGET)-shim: FORMAT = $(firstword $(filter elf32-x86-64,$(shell $(OBJCOPY) --help)) elf32-i386)
152$(TARGET)-shim: $(TARGET)-syms
153	$(OBJCOPY) -O $(FORMAT) $< $@
154
155note.o: $(TARGET)-syms
156	$(OBJCOPY) -O binary --only-section=.note.gnu.build-id  $(BASEDIR)/xen-syms $@.bin
157	$(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 \
158		--rename-section=.data=.note.gnu.build-id -S $@.bin $@
159	rm -f $@.bin
160
161EFI_LDFLAGS = $(patsubst -m%,-mi386pep,$(LDFLAGS)) --subsystem=10
162EFI_LDFLAGS += --image-base=$(1) --stack=0,0 --heap=0,0 --strip-debug
163EFI_LDFLAGS += --section-alignment=0x200000 --file-alignment=0x20
164EFI_LDFLAGS += --major-image-version=$(XEN_VERSION)
165EFI_LDFLAGS += --minor-image-version=$(XEN_SUBVERSION)
166EFI_LDFLAGS += --major-os-version=2 --minor-os-version=0
167EFI_LDFLAGS += --major-subsystem-version=2 --minor-subsystem-version=0
168
169$(TARGET).efi: VIRT_BASE = 0x$(shell $(NM) efi/relocs-dummy.o | sed -n 's, A VIRT_START$$,,p')
170$(TARGET).efi: ALT_BASE = 0x$(shell $(NM) efi/relocs-dummy.o | sed -n 's, A ALT_START$$,,p')
171# Don't use $(wildcard ...) here - at least make 3.80 expands this too early!
172$(TARGET).efi: guard = $(if $(shell echo efi/dis* | grep disabled),:)
173
174ifneq ($(build_id_linker),)
175ifeq ($(call ld-ver-build-id,$(LD) $(filter -m%,$(EFI_LDFLAGS))),y)
176CFLAGS += -DBUILD_ID_EFI
177EFI_LDFLAGS += $(build_id_linker)
178note_file := efi/buildid.o
179else
180note_file := note.o
181endif
182else
183note_file :=
184endif
185
186$(TARGET).efi: prelink-efi.o $(note_file) efi.lds efi/relocs-dummy.o $(BASEDIR)/common/symbols-dummy.o efi/mkreloc
187	$(foreach base, $(VIRT_BASE) $(ALT_BASE), \
188	          $(guard) $(LD) $(call EFI_LDFLAGS,$(base)) -T efi.lds -N $< efi/relocs-dummy.o \
189	                $(BASEDIR)/common/symbols-dummy.o $(note_file) -o $(@D)/.$(@F).$(base).0 &&) :
190	$(guard) efi/mkreloc $(foreach base,$(VIRT_BASE) $(ALT_BASE),$(@D)/.$(@F).$(base).0) >$(@D)/.$(@F).0r.S
191	$(guard) $(NM) -pa --format=sysv $(@D)/.$(@F).$(VIRT_BASE).0 \
192		| $(guard) $(BASEDIR)/tools/symbols $(all_symbols) --sysv --sort >$(@D)/.$(@F).0s.S
193	$(guard) $(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0r.o $(@D)/.$(@F).0s.o
194	$(foreach base, $(VIRT_BASE) $(ALT_BASE), \
195	          $(guard) $(LD) $(call EFI_LDFLAGS,$(base)) -T efi.lds -N $< \
196	                $(@D)/.$(@F).0r.o $(@D)/.$(@F).0s.o $(note_file) -o $(@D)/.$(@F).$(base).1 &&) :
197	$(guard) efi/mkreloc $(foreach base,$(VIRT_BASE) $(ALT_BASE),$(@D)/.$(@F).$(base).1) >$(@D)/.$(@F).1r.S
198	$(guard) $(NM) -pa --format=sysv $(@D)/.$(@F).$(VIRT_BASE).1 \
199		| $(guard) $(BASEDIR)/tools/symbols $(all_symbols) --sysv --sort >$(@D)/.$(@F).1s.S
200	$(guard) $(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).1r.o $(@D)/.$(@F).1s.o
201	$(guard) $(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T efi.lds -N $< \
202	                $(@D)/.$(@F).1r.o $(@D)/.$(@F).1s.o $(note_file) -o $@
203	if $(guard) false; then rm -f $@; echo 'EFI support disabled'; \
204	else $(NM) -pa --format=sysv $(@D)/$(@F) \
205		| $(BASEDIR)/tools/symbols --xensyms --sysv --sort >$(@D)/$(@F).map; fi
206	rm -f $(@D)/.$(@F).[0-9]*
207
208efi/boot.init.o efi/runtime.o efi/compat.o efi/buildid.o: $(BASEDIR)/arch/x86/efi/built_in.o
209efi/boot.init.o efi/runtime.o efi/compat.o efi/buildid.o: ;
210
211asm-offsets.s: $(TARGET_SUBARCH)/asm-offsets.c
212	$(CC) $(filter-out -flto,$(CFLAGS)) -S -o $@ $<
213
214xen.lds: xen.lds.S
215	$(CC) -P -E -Ui386 $(AFLAGS) -o $@ $<
216	sed -e 's/xen\.lds\.o:/xen\.lds:/g' <.xen.lds.d >.xen.lds.d.new
217	mv -f .xen.lds.d.new .xen.lds.d
218
219efi.lds: xen.lds.S
220	$(CC) -P -E -Ui386 -DEFI $(AFLAGS) -o $@ $<
221	sed -e 's/efi\.lds\.o:/efi\.lds:/g' <.$(@F).d >.$(@F).d.new
222	mv -f .$(@F).d.new .$(@F).d
223
224boot/mkelf32: boot/mkelf32.c
225	$(HOSTCC) $(HOSTCFLAGS) -o $@ $<
226
227efi/mkreloc: efi/mkreloc.c
228	$(HOSTCC) $(HOSTCFLAGS) -g -o $@ $<
229
230.PHONY: clean
231clean::
232	rm -f asm-offsets.s *.lds boot/*.o boot/*~ boot/core boot/mkelf32
233	rm -f $(BASEDIR)/.xen-syms.[0-9]* boot/.*.d
234	rm -f $(BASEDIR)/.xen.efi.[0-9]* efi/*.efi efi/disabled efi/mkreloc
235	rm -f $(BASEDIR)/xen-shim
236	rm -f boot/cmdline.S boot/reloc.S boot/*.lnk boot/*.bin
237	rm -f note.o
238