xref: /linux/arch/x86/Makefile (revision 5551a34e5aeab868f8d37f70d8754868921b4ee5)
174b469f2SSam Ravnborg# Unified Makefile for i386 and x86_64
274b469f2SSam Ravnborg
32266cfd5SSam Ravnborg# select defconfig based on actual architecture
4d746d647SSam Ravnborgifeq ($(ARCH),x86)
5ffee0de4SDavid Woodhouse  ifeq ($(shell uname -m),x86_64)
6ffee0de4SDavid Woodhouse        KBUILD_DEFCONFIG := x86_64_defconfig
7ffee0de4SDavid Woodhouse  else
8d746d647SSam Ravnborg        KBUILD_DEFCONFIG := i386_defconfig
9ffee0de4SDavid Woodhouse  endif
10d746d647SSam Ravnborgelse
112266cfd5SSam Ravnborg        KBUILD_DEFCONFIG := $(ARCH)_defconfig
12d746d647SSam Ravnborgendif
132266cfd5SSam Ravnborg
140a6ef376SSam Ravnborg# BITS is used as extension for files which are available in a 32 bit
150a6ef376SSam Ravnborg# and a 64 bit version to simplify shared Makefiles.
160a6ef376SSam Ravnborg# e.g.: obj-y += foo_$(BITS).o
170a6ef376SSam Ravnborgexport BITS
1874b469f2SSam Ravnborg
19a0215061SKees Cookifdef CONFIG_X86_NEED_RELOCS
20a0215061SKees Cook        LDFLAGS_vmlinux := --emit-relocs
21a0215061SKees Cookendif
22a0215061SKees Cook
23d746d647SSam Ravnborgifeq ($(CONFIG_X86_32),y)
240a6ef376SSam Ravnborg        BITS := 32
258c6531f7SAndreas Herrmann        UTS_MACHINE := i386
264ba7e5cdSSam Ravnborg        CHECKFLAGS += -D__i386__
270a6ef376SSam Ravnborg
284ba7e5cdSSam Ravnborg        biarch := $(call cc-option,-m32)
294ba7e5cdSSam Ravnborg        KBUILD_AFLAGS += $(biarch)
304ba7e5cdSSam Ravnborg        KBUILD_CFLAGS += $(biarch)
310a6ef376SSam Ravnborg
320a6ef376SSam Ravnborg        KBUILD_CFLAGS += -msoft-float -mregparm=3 -freg-struct-return
330a6ef376SSam Ravnborg
34*5551a34eSH. Peter Anvin        # Don't autogenerate SSE instructions
35*5551a34eSH. Peter Anvin	KBUILD_CFLAGS += -mno-sse
36*5551a34eSH. Peter Anvin
37484d90eeSAndrew Boie        # Never want PIC in a 32-bit kernel, prevent breakage with GCC built
38484d90eeSAndrew Boie        # with nonstandard options
39484d90eeSAndrew Boie        KBUILD_CFLAGS += -fno-pic
40484d90eeSAndrew Boie
410a6ef376SSam Ravnborg        # prevent gcc from keeping the stack 16 byte aligned
420a6ef376SSam Ravnborg        KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=2)
430a6ef376SSam Ravnborg
440a6ef376SSam Ravnborg        # Disable unit-at-a-time mode on pre-gcc-4.0 compilers, it makes gcc use
450a6ef376SSam Ravnborg        # a lot more stack due to the lack of sharing of stacklots:
46c7bd0414SFrans Pop        KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0400, \
47c7bd0414SFrans Pop				$(call cc-option,-fno-unit-at-a-time))
480a6ef376SSam Ravnborg
490a6ef376SSam Ravnborg        # CPU-specific tuning. Anything which can be shared with UML should go here.
500a6ef376SSam Ravnborg        include $(srctree)/arch/x86/Makefile_32.cpu
510a6ef376SSam Ravnborg        KBUILD_CFLAGS += $(cflags-y)
520a6ef376SSam Ravnborg
530a6ef376SSam Ravnborg        # temporary until string.h is fixed
540a6ef376SSam Ravnborg        KBUILD_CFLAGS += -ffreestanding
550a6ef376SSam Ravnborgelse
560a6ef376SSam Ravnborg        BITS := 64
570a6ef376SSam Ravnborg        UTS_MACHINE := x86_64
580a6ef376SSam Ravnborg        CHECKFLAGS += -D__x86_64__ -m64
590a6ef376SSam Ravnborg
600a6ef376SSam Ravnborg        KBUILD_AFLAGS += -m64
610a6ef376SSam Ravnborg        KBUILD_CFLAGS += -m64
620a6ef376SSam Ravnborg
63*5551a34eSH. Peter Anvin        # Don't autogenerate SSE instructions
64*5551a34eSH. Peter Anvin	KBUILD_CFLAGS += -mno-sse
65*5551a34eSH. Peter Anvin
66d9b0cde9SH.J. Lu	# Use -mpreferred-stack-boundary=3 if supported.
67*5551a34eSH. Peter Anvin	KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3)
68d9b0cde9SH.J. Lu
690a6ef376SSam Ravnborg        # FIXME - should be integrated in Makefile.cpu (Makefile_32.cpu)
700a6ef376SSam Ravnborg        cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8)
710a6ef376SSam Ravnborg        cflags-$(CONFIG_MPSC) += $(call cc-option,-march=nocona)
720a6ef376SSam Ravnborg
730a6ef376SSam Ravnborg        cflags-$(CONFIG_MCORE2) += \
740a6ef376SSam Ravnborg                $(call cc-option,-march=core2,$(call cc-option,-mtune=generic))
75366d19e1STobias Doerffel	cflags-$(CONFIG_MATOM) += $(call cc-option,-march=atom) \
76366d19e1STobias Doerffel		$(call cc-option,-mtune=atom,$(call cc-option,-mtune=generic))
770a6ef376SSam Ravnborg        cflags-$(CONFIG_GENERIC_CPU) += $(call cc-option,-mtune=generic)
780a6ef376SSam Ravnborg        KBUILD_CFLAGS += $(cflags-y)
790a6ef376SSam Ravnborg
800a6ef376SSam Ravnborg        KBUILD_CFLAGS += -mno-red-zone
810a6ef376SSam Ravnborg        KBUILD_CFLAGS += -mcmodel=kernel
820a6ef376SSam Ravnborg
830a6ef376SSam Ravnborg        # -funit-at-a-time shrinks the kernel .text considerably
840a6ef376SSam Ravnborg        # unfortunately it makes reading oopses harder.
850a6ef376SSam Ravnborg        KBUILD_CFLAGS += $(call cc-option,-funit-at-a-time)
860a6ef376SSam Ravnborg
870a6ef376SSam Ravnborg        # this works around some issues with generating unwind tables in older gccs
880a6ef376SSam Ravnborg        # newer gccs do it by default
890a6ef376SSam Ravnborg        KBUILD_CFLAGS += -maccumulate-outgoing-args
905d707e9cSTejun Heoendif
910a6ef376SSam Ravnborg
925d707e9cSTejun Heoifdef CONFIG_CC_STACKPROTECTOR
935d707e9cSTejun Heo	cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
9408c2b394Sbasile@opensource.dyc.edu        ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
955d707e9cSTejun Heo                stackp-y := -fstack-protector
960a6ef376SSam Ravnborg                KBUILD_CFLAGS += $(stackp-y)
975d707e9cSTejun Heo        else
985d707e9cSTejun Heo                $(warning stack protector enabled but no compiler support)
995d707e9cSTejun Heo        endif
1000a6ef376SSam Ravnborgendif
1010a6ef376SSam Ravnborg
1020bf62763SH. Peter Anvinifdef CONFIG_X86_X32
1030bf62763SH. Peter Anvin	x32_ld_ok := $(call try-run,\
1040bf62763SH. Peter Anvin			/bin/echo -e '1: .quad 1b' | \
1050bf62763SH. Peter Anvin			$(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" - && \
1060bf62763SH. Peter Anvin			$(OBJCOPY) -O elf32-x86-64 "$$TMP" "$$TMPO" && \
1070bf62763SH. Peter Anvin			$(LD) -m elf32_x86_64 "$$TMPO" -o "$$TMP",y,n)
1080bf62763SH. Peter Anvin        ifeq ($(x32_ld_ok),y)
1090bf62763SH. Peter Anvin                CONFIG_X86_X32_ABI := y
1100bf62763SH. Peter Anvin                KBUILD_AFLAGS += -DCONFIG_X86_X32_ABI
1110bf62763SH. Peter Anvin                KBUILD_CFLAGS += -DCONFIG_X86_X32_ABI
1120bf62763SH. Peter Anvin        else
1130bf62763SH. Peter Anvin                $(warning CONFIG_X86_X32 enabled but no binutils support)
1140bf62763SH. Peter Anvin        endif
1150bf62763SH. Peter Anvinendif
1160bf62763SH. Peter Anvinexport CONFIG_X86_X32_ABI
1170bf62763SH. Peter Anvin
118dfec072eSVegard Nossum# Don't unroll struct assignments with kmemcheck enabled
119dfec072eSVegard Nossumifeq ($(CONFIG_KMEMCHECK),y)
120dfec072eSVegard Nossum	KBUILD_CFLAGS += $(call cc-option,-fno-builtin-memcpy)
121dfec072eSVegard Nossumendif
122dfec072eSVegard Nossum
1230a6ef376SSam Ravnborg# Stackpointer is addressed different for 32 bit and 64 bit x86
1240a6ef376SSam Ravnborgsp-$(CONFIG_X86_32) := esp
1250a6ef376SSam Ravnborgsp-$(CONFIG_X86_64) := rsp
1260a6ef376SSam Ravnborg
1270a6ef376SSam Ravnborg# do binutils support CFI?
1280a6ef376SSam Ravnborgcfi := $(call as-instr,.cfi_startproc\n.cfi_rel_offset $(sp-y)$(comma)0\n.cfi_endproc,-DCONFIG_AS_CFI=1)
1290a6ef376SSam Ravnborg# is .cfi_signal_frame supported too?
1300a6ef376SSam Ravnborgcfi-sigframe := $(call as-instr,.cfi_startproc\n.cfi_signal_frame\n.cfi_endproc,-DCONFIG_AS_CFI_SIGNAL_FRAME=1)
1319e565292SRoland McGrathcfi-sections := $(call as-instr,.cfi_sections .debug_frame,-DCONFIG_AS_CFI_SECTIONS=1)
132d7acb92fSH. Peter Anvin
133d7acb92fSH. Peter Anvin# does binutils support specific instructions?
134d7acb92fSH. Peter Anvinasinstr := $(call as-instr,fxsaveq (%rax),-DCONFIG_AS_FXSAVEQ=1)
135ea4d26aeSJim Kukunasavx_instr := $(call as-instr,vxorps %ymm0$(comma)%ymm1$(comma)%ymm2,-DCONFIG_AS_AVX=1)
1367056741fSJim Kukunasavx2_instr :=$(call as-instr,vpbroadcastb %xmm0$(comma)%ymm1,-DCONFIG_AS_AVX2=1)
137d7acb92fSH. Peter Anvin
1387056741fSJim KukunasKBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr)
1397056741fSJim KukunasKBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr)
1400a6ef376SSam Ravnborg
1410a6ef376SSam RavnborgLDFLAGS := -m elf_$(UTS_MACHINE)
14225dfeeb7SSam Ravnborg
14325dfeeb7SSam Ravnborg# Speed up the build
1440a6ef376SSam RavnborgKBUILD_CFLAGS += -pipe
14525dfeeb7SSam Ravnborg# Workaround for a gcc prelease that unfortunately was shipped in a suse release
14625dfeeb7SSam RavnborgKBUILD_CFLAGS += -Wno-sign-compare
14725dfeeb7SSam Ravnborg#
14825dfeeb7SSam RavnborgKBUILD_CFLAGS += -fno-asynchronous-unwind-tables
14925dfeeb7SSam Ravnborg# prevent gcc from generating any FP code by mistake
15025dfeeb7SSam RavnborgKBUILD_CFLAGS += $(call cc-option,-mno-sse -mno-mmx -mno-sse2 -mno-3dnow,)
151c0e9afc0SAndi KleenKBUILD_CFLAGS += $(call cc-option,-mno-avx,)
1520a6ef376SSam Ravnborg
1530a6ef376SSam RavnborgKBUILD_CFLAGS += $(mflags-y)
1540a6ef376SSam RavnborgKBUILD_AFLAGS += $(mflags-y)
1550a6ef376SSam Ravnborg
1563ce9e53eSMichal Marekarchscripts: scripts_basic
1576520fe55SH. Peter Anvin	$(Q)$(MAKE) $(build)=arch/x86/tools relocs
1586520fe55SH. Peter Anvin
1590a6ef376SSam Ravnborg###
160303395acSH. Peter Anvin# Syscall table generation
161303395acSH. Peter Anvin
162303395acSH. Peter Anvinarchheaders:
163303395acSH. Peter Anvin	$(Q)$(MAKE) $(build)=arch/x86/syscalls all
164303395acSH. Peter Anvin
165303395acSH. Peter Anvin###
1660a6ef376SSam Ravnborg# Kernel objects
1670a6ef376SSam Ravnborg
1680a6ef376SSam Ravnborghead-y := arch/x86/kernel/head_$(BITS).o
169700efc1bSEric W. Biedermanhead-y += arch/x86/kernel/head$(BITS).o
1700c51a965SHuang, Yinghead-y += arch/x86/kernel/head.o
1710a6ef376SSam Ravnborg
1720a6ef376SSam Ravnborglibs-y  += arch/x86/lib/
1730a6ef376SSam Ravnborg
174d1f0ae5eSSam Ravnborg# See arch/x86/Kbuild for content of core part of the kernel
175d1f0ae5eSSam Ravnborgcore-y += arch/x86/
1760a6ef376SSam Ravnborg
1770a6ef376SSam Ravnborg# drivers-y are linked after core-y
1780a6ef376SSam Ravnborgdrivers-$(CONFIG_MATH_EMULATION) += arch/x86/math-emu/
1790a6ef376SSam Ravnborgdrivers-$(CONFIG_PCI)            += arch/x86/pci/
1800a6ef376SSam Ravnborg
1810a6ef376SSam Ravnborg# must be linked after kernel/
1820a6ef376SSam Ravnborgdrivers-$(CONFIG_OPROFILE) += arch/x86/oprofile/
1830a6ef376SSam Ravnborg
184cf7700feSRafael J. Wysocki# suspend and hibernation support
1850a6ef376SSam Ravnborgdrivers-$(CONFIG_PM) += arch/x86/power/
186cf7700feSRafael J. Wysocki
1870a6ef376SSam Ravnborgdrivers-$(CONFIG_FB) += arch/x86/video/
1880a6ef376SSam Ravnborg
1890a6ef376SSam Ravnborg####
1900a6ef376SSam Ravnborg# boot loader support. Several targets are kept for legacy purposes
1910a6ef376SSam Ravnborg
1920a6ef376SSam Ravnborgboot := arch/x86/boot
1930a6ef376SSam Ravnborg
1941648e4f8SH. Peter AnvinBOOT_TARGETS = bzlilo bzdisk fdimage fdimage144 fdimage288 isoimage
195f9c5107cSH. Peter Anvin
196f9c5107cSH. Peter AnvinPHONY += bzImage $(BOOT_TARGETS)
1970a6ef376SSam Ravnborg
1980a6ef376SSam Ravnborg# Default kernel to build
1990a6ef376SSam Ravnborgall: bzImage
2000a6ef376SSam Ravnborg
2010a6ef376SSam Ravnborg# KBUILD_IMAGE specify target image being built
2020a6ef376SSam RavnborgKBUILD_IMAGE := $(boot)/bzImage
2030a6ef376SSam Ravnborg
204f9c5107cSH. Peter AnvinbzImage: vmlinux
205ca0e9badSMasami Hiramatsuifeq ($(CONFIG_X86_DECODER_SELFTEST),y)
206ca0e9badSMasami Hiramatsu	$(Q)$(MAKE) $(build)=arch/x86/tools posttest
207ca0e9badSMasami Hiramatsuendif
2080a6ef376SSam Ravnborg	$(Q)$(MAKE) $(build)=$(boot) $(KBUILD_IMAGE)
2090a6ef376SSam Ravnborg	$(Q)mkdir -p $(objtree)/arch/$(UTS_MACHINE)/boot
21041b3eae6SJan Beulich	$(Q)ln -fsn ../../x86/boot/bzImage $(objtree)/arch/$(UTS_MACHINE)/boot/$@
2110a6ef376SSam Ravnborg
212f9c5107cSH. Peter Anvin$(BOOT_TARGETS): vmlinux
213f9c5107cSH. Peter Anvin	$(Q)$(MAKE) $(build)=$(boot) $@
2140a6ef376SSam Ravnborg
2151648e4f8SH. Peter AnvinPHONY += install
2161648e4f8SH. Peter Anvininstall:
2171648e4f8SH. Peter Anvin	$(Q)$(MAKE) $(build)=$(boot) $@
2181648e4f8SH. Peter Anvin
2190a6ef376SSam RavnborgPHONY += vdso_install
2200a6ef376SSam Ravnborgvdso_install:
2210a6ef376SSam Ravnborg	$(Q)$(MAKE) $(build)=arch/x86/vdso $@
2220a6ef376SSam Ravnborg
2230a6ef376SSam Ravnborgarchclean:
2240a6ef376SSam Ravnborg	$(Q)rm -rf $(objtree)/arch/i386
2250a6ef376SSam Ravnborg	$(Q)rm -rf $(objtree)/arch/x86_64
2260a6ef376SSam Ravnborg	$(Q)$(MAKE) $(clean)=$(boot)
227b2d668daSJarkko Sakkinen	$(Q)$(MAKE) $(clean)=arch/x86/tools
2280a6ef376SSam Ravnborg
229fc58be75SBorislav PetkovPHONY += kvmconfig
23046ff5387SBorislav Petkovkvmconfig:
23146ff5387SBorislav Petkov	$(if $(wildcard $(objtree)/.config),, $(error You need an existing .config for this target))
23246ff5387SBorislav Petkov	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh -m -O $(objtree) $(objtree)/.config arch/x86/configs/kvm_guest.config
23346ff5387SBorislav Petkov	$(Q)yes "" | $(MAKE) oldconfig
23446ff5387SBorislav Petkov
2350a6ef376SSam Ravnborgdefine archhelp
2360a6ef376SSam Ravnborg  echo  '* bzImage      - Compressed kernel image (arch/x86/boot/bzImage)'
2370a6ef376SSam Ravnborg  echo  '  install      - Install kernel using'
238caa27b66SSam Ravnborg  echo  '                  (your) ~/bin/$(INSTALLKERNEL) or'
239caa27b66SSam Ravnborg  echo  '                  (distribution) /sbin/$(INSTALLKERNEL) or'
2400a6ef376SSam Ravnborg  echo  '                  install to $$(INSTALL_PATH) and run lilo'
24137f30e21SAndi Kleen  echo  '  fdimage      - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)'
24237f30e21SAndi Kleen  echo  '  fdimage144   - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)'
24337f30e21SAndi Kleen  echo  '  fdimage288   - Create 2.8MB boot floppy image (arch/x86/boot/fdimage)'
24437f30e21SAndi Kleen  echo  '  isoimage     - Create a boot CD-ROM image (arch/x86/boot/image.iso)'
24537f30e21SAndi Kleen  echo  '                  bzdisk/fdimage*/isoimage also accept:'
24637f30e21SAndi Kleen  echo  '                  FDARGS="..."  arguments for the booted kernel'
24737f30e21SAndi Kleen  echo  '                  FDINITRD=file initrd for the booted kernel'
24846ff5387SBorislav Petkov  echo  '  kvmconfig	- Enable additional options for guest kernel support'
2490a6ef376SSam Ravnborgendef
250