xref: /linux/arch/x86/Makefile (revision be6cb02779ca74d83481f017db21578cfe92891c)
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
141c678da3SDavid Woodhouse# How to compile the 16-bit code.  Note we always compile for -march=i386;
151c678da3SDavid Woodhouse# that way we can complain to the user if the CPU is insufficient.
16de3accdaSDavid Woodhouse#
17de3accdaSDavid Woodhouse# The -m16 option is supported by GCC >= 4.9 and clang >= 3.5. For
18a9cfcceeSH. Peter Anvin# older versions of GCC, include an *assembly* header to make sure that
19a9cfcceeSH. Peter Anvin# gcc doesn't play any games behind our back.
20a9cfcceeSH. Peter AnvinCODE16GCC_CFLAGS := -m32 -Wa,$(srctree)/arch/x86/boot/code16gcc.h
21de3accdaSDavid WoodhouseM16_CFLAGS	 := $(call cc-option, -m16, $(CODE16GCC_CFLAGS))
22de3accdaSDavid Woodhouse
23de3accdaSDavid WoodhouseREALMODE_CFLAGS	:= $(M16_CFLAGS) -g -Os -D__KERNEL__ \
24de3accdaSDavid Woodhouse		   -DDISABLE_BRANCH_PROFILING \
251c678da3SDavid Woodhouse		   -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
261c678da3SDavid Woodhouse		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
271c678da3SDavid Woodhouse		   -mno-mmx -mno-sse \
281c678da3SDavid Woodhouse		   $(call cc-option, -ffreestanding) \
291c678da3SDavid Woodhouse		   $(call cc-option, -fno-stack-protector) \
301c678da3SDavid Woodhouse		   $(call cc-option, -mpreferred-stack-boundary=2)
311c678da3SDavid Woodhouseexport REALMODE_CFLAGS
321c678da3SDavid Woodhouse
330a6ef376SSam Ravnborg# BITS is used as extension for files which are available in a 32 bit
340a6ef376SSam Ravnborg# and a 64 bit version to simplify shared Makefiles.
350a6ef376SSam Ravnborg# e.g.: obj-y += foo_$(BITS).o
360a6ef376SSam Ravnborgexport BITS
3774b469f2SSam Ravnborg
38a0215061SKees Cookifdef CONFIG_X86_NEED_RELOCS
39a0215061SKees Cook        LDFLAGS_vmlinux := --emit-relocs
40a0215061SKees Cookendif
41a0215061SKees Cook
42d746d647SSam Ravnborgifeq ($(CONFIG_X86_32),y)
430a6ef376SSam Ravnborg        BITS := 32
448c6531f7SAndreas Herrmann        UTS_MACHINE := i386
454ba7e5cdSSam Ravnborg        CHECKFLAGS += -D__i386__
460a6ef376SSam Ravnborg
474ba7e5cdSSam Ravnborg        biarch := $(call cc-option,-m32)
484ba7e5cdSSam Ravnborg        KBUILD_AFLAGS += $(biarch)
494ba7e5cdSSam Ravnborg        KBUILD_CFLAGS += $(biarch)
500a6ef376SSam Ravnborg
510a6ef376SSam Ravnborg        KBUILD_CFLAGS += -msoft-float -mregparm=3 -freg-struct-return
520a6ef376SSam Ravnborg
53484d90eeSAndrew Boie        # Never want PIC in a 32-bit kernel, prevent breakage with GCC built
54484d90eeSAndrew Boie        # with nonstandard options
55484d90eeSAndrew Boie        KBUILD_CFLAGS += -fno-pic
56484d90eeSAndrew Boie
570a6ef376SSam Ravnborg        # prevent gcc from keeping the stack 16 byte aligned
580a6ef376SSam Ravnborg        KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=2)
590a6ef376SSam Ravnborg
600a6ef376SSam Ravnborg        # Disable unit-at-a-time mode on pre-gcc-4.0 compilers, it makes gcc use
610a6ef376SSam Ravnborg        # a lot more stack due to the lack of sharing of stacklots:
62c7bd0414SFrans Pop        KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0400, \
63c7bd0414SFrans Pop				$(call cc-option,-fno-unit-at-a-time))
640a6ef376SSam Ravnborg
650a6ef376SSam Ravnborg        # CPU-specific tuning. Anything which can be shared with UML should go here.
66a436bb7bSMasahiro Yamada        include arch/x86/Makefile_32.cpu
670a6ef376SSam Ravnborg        KBUILD_CFLAGS += $(cflags-y)
680a6ef376SSam Ravnborg
690a6ef376SSam Ravnborg        # temporary until string.h is fixed
700a6ef376SSam Ravnborg        KBUILD_CFLAGS += -ffreestanding
710a6ef376SSam Ravnborgelse
720a6ef376SSam Ravnborg        BITS := 64
730a6ef376SSam Ravnborg        UTS_MACHINE := x86_64
740a6ef376SSam Ravnborg        CHECKFLAGS += -D__x86_64__ -m64
750a6ef376SSam Ravnborg
7614262d67SGeorge Spelvin        biarch := -m64
770a6ef376SSam Ravnborg        KBUILD_AFLAGS += -m64
780a6ef376SSam Ravnborg        KBUILD_CFLAGS += -m64
790a6ef376SSam Ravnborg
80*be6cb027SIngo Molnar        # Align jump targets to 1 byte, not the default 16 bytes:
81*be6cb027SIngo Molnar        KBUILD_CFLAGS += -falign-jumps=1
82*be6cb027SIngo Molnar
835c630089SRasmus Villemoes        # Don't autogenerate traditional x87 instructions
848f2dd677SBehan Webster        KBUILD_CFLAGS += $(call cc-option,-mno-80387)
858f2dd677SBehan Webster        KBUILD_CFLAGS += $(call cc-option,-mno-fp-ret-in-387)
865551a34eSH. Peter Anvin
87d9b0cde9SH.J. Lu	# Use -mpreferred-stack-boundary=3 if supported.
885551a34eSH. Peter Anvin	KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3)
89d9b0cde9SH.J. Lu
90d9ee948dSH.J. Lu	# Use -mskip-rax-setup if supported.
91d9ee948dSH.J. Lu	KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)
92d9ee948dSH.J. Lu
930a6ef376SSam Ravnborg        # FIXME - should be integrated in Makefile.cpu (Makefile_32.cpu)
940a6ef376SSam Ravnborg        cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8)
950a6ef376SSam Ravnborg        cflags-$(CONFIG_MPSC) += $(call cc-option,-march=nocona)
960a6ef376SSam Ravnborg
970a6ef376SSam Ravnborg        cflags-$(CONFIG_MCORE2) += \
980a6ef376SSam Ravnborg                $(call cc-option,-march=core2,$(call cc-option,-mtune=generic))
99366d19e1STobias Doerffel	cflags-$(CONFIG_MATOM) += $(call cc-option,-march=atom) \
100366d19e1STobias Doerffel		$(call cc-option,-mtune=atom,$(call cc-option,-mtune=generic))
1010a6ef376SSam Ravnborg        cflags-$(CONFIG_GENERIC_CPU) += $(call cc-option,-mtune=generic)
1020a6ef376SSam Ravnborg        KBUILD_CFLAGS += $(cflags-y)
1030a6ef376SSam Ravnborg
1040a6ef376SSam Ravnborg        KBUILD_CFLAGS += -mno-red-zone
1050a6ef376SSam Ravnborg        KBUILD_CFLAGS += -mcmodel=kernel
1060a6ef376SSam Ravnborg
1070a6ef376SSam Ravnborg        # -funit-at-a-time shrinks the kernel .text considerably
1080a6ef376SSam Ravnborg        # unfortunately it makes reading oopses harder.
1090a6ef376SSam Ravnborg        KBUILD_CFLAGS += $(call cc-option,-funit-at-a-time)
1100a6ef376SSam Ravnborg
1110a6ef376SSam Ravnborg        # this works around some issues with generating unwind tables in older gccs
1120a6ef376SSam Ravnborg        # newer gccs do it by default
113fd2d0a19SJan-Simon Möller        KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
1145d707e9cSTejun Heoendif
1150a6ef376SSam Ravnborg
11619952a92SKees Cook# Make sure compiler does not have buggy stack-protector support.
1175d707e9cSTejun Heoifdef CONFIG_CC_STACKPROTECTOR
1185d707e9cSTejun Heo	cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
11919952a92SKees Cook        ifneq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
12019952a92SKees Cook                $(warning stack-protector enabled but compiler support broken)
1215d707e9cSTejun Heo        endif
1220a6ef376SSam Ravnborgendif
1230a6ef376SSam Ravnborg
1240bf62763SH. Peter Anvinifdef CONFIG_X86_X32
1250bf62763SH. Peter Anvin	x32_ld_ok := $(call try-run,\
1260bf62763SH. Peter Anvin			/bin/echo -e '1: .quad 1b' | \
1270bf62763SH. Peter Anvin			$(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" - && \
1280bf62763SH. Peter Anvin			$(OBJCOPY) -O elf32-x86-64 "$$TMP" "$$TMPO" && \
1290bf62763SH. Peter Anvin			$(LD) -m elf32_x86_64 "$$TMPO" -o "$$TMP",y,n)
1300bf62763SH. Peter Anvin        ifeq ($(x32_ld_ok),y)
1310bf62763SH. Peter Anvin                CONFIG_X86_X32_ABI := y
1320bf62763SH. Peter Anvin                KBUILD_AFLAGS += -DCONFIG_X86_X32_ABI
1330bf62763SH. Peter Anvin                KBUILD_CFLAGS += -DCONFIG_X86_X32_ABI
1340bf62763SH. Peter Anvin        else
1350bf62763SH. Peter Anvin                $(warning CONFIG_X86_X32 enabled but no binutils support)
1360bf62763SH. Peter Anvin        endif
1370bf62763SH. Peter Anvinendif
1380bf62763SH. Peter Anvinexport CONFIG_X86_X32_ABI
1390bf62763SH. Peter Anvin
140dfec072eSVegard Nossum# Don't unroll struct assignments with kmemcheck enabled
141dfec072eSVegard Nossumifeq ($(CONFIG_KMEMCHECK),y)
142dfec072eSVegard Nossum	KBUILD_CFLAGS += $(call cc-option,-fno-builtin-memcpy)
143dfec072eSVegard Nossumendif
144dfec072eSVegard Nossum
1450a6ef376SSam Ravnborg# Stackpointer is addressed different for 32 bit and 64 bit x86
1460a6ef376SSam Ravnborgsp-$(CONFIG_X86_32) := esp
1470a6ef376SSam Ravnborgsp-$(CONFIG_X86_64) := rsp
1480a6ef376SSam Ravnborg
1490a6ef376SSam Ravnborg# do binutils support CFI?
1500a6ef376SSam Ravnborgcfi := $(call as-instr,.cfi_startproc\n.cfi_rel_offset $(sp-y)$(comma)0\n.cfi_endproc,-DCONFIG_AS_CFI=1)
1510a6ef376SSam Ravnborg# is .cfi_signal_frame supported too?
1520a6ef376SSam Ravnborgcfi-sigframe := $(call as-instr,.cfi_startproc\n.cfi_signal_frame\n.cfi_endproc,-DCONFIG_AS_CFI_SIGNAL_FRAME=1)
1539e565292SRoland McGrathcfi-sections := $(call as-instr,.cfi_sections .debug_frame,-DCONFIG_AS_CFI_SECTIONS=1)
154d7acb92fSH. Peter Anvin
155d7acb92fSH. Peter Anvin# does binutils support specific instructions?
156d7acb92fSH. Peter Anvinasinstr := $(call as-instr,fxsaveq (%rax),-DCONFIG_AS_FXSAVEQ=1)
15775aaf4c3SJan Beulichasinstr += $(call as-instr,pshufb %xmm0$(comma)%xmm0,-DCONFIG_AS_SSSE3=1)
15806325190SJan Beulichasinstr += $(call as-instr,crc32l %eax$(comma)%eax,-DCONFIG_AS_CRC32=1)
159ea4d26aeSJim Kukunasavx_instr := $(call as-instr,vxorps %ymm0$(comma)%ymm1$(comma)%ymm2,-DCONFIG_AS_AVX=1)
1607056741fSJim Kukunasavx2_instr :=$(call as-instr,vpbroadcastb %xmm0$(comma)%ymm1,-DCONFIG_AS_AVX2=1)
161d7acb92fSH. Peter Anvin
1627056741fSJim KukunasKBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr)
1637056741fSJim KukunasKBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr)
1640a6ef376SSam Ravnborg
1650a6ef376SSam RavnborgLDFLAGS := -m elf_$(UTS_MACHINE)
16625dfeeb7SSam Ravnborg
16725dfeeb7SSam Ravnborg# Speed up the build
1680a6ef376SSam RavnborgKBUILD_CFLAGS += -pipe
16925dfeeb7SSam Ravnborg# Workaround for a gcc prelease that unfortunately was shipped in a suse release
17025dfeeb7SSam RavnborgKBUILD_CFLAGS += -Wno-sign-compare
17125dfeeb7SSam Ravnborg#
17225dfeeb7SSam RavnborgKBUILD_CFLAGS += -fno-asynchronous-unwind-tables
17325dfeeb7SSam Ravnborg# prevent gcc from generating any FP code by mistake
1745c630089SRasmus VillemoesKBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow
175c0e9afc0SAndi KleenKBUILD_CFLAGS += $(call cc-option,-mno-avx,)
1760a6ef376SSam Ravnborg
1770a6ef376SSam RavnborgKBUILD_CFLAGS += $(mflags-y)
1780a6ef376SSam RavnborgKBUILD_AFLAGS += $(mflags-y)
1790a6ef376SSam Ravnborg
1803ce9e53eSMichal Marekarchscripts: scripts_basic
1816520fe55SH. Peter Anvin	$(Q)$(MAKE) $(build)=arch/x86/tools relocs
1826520fe55SH. Peter Anvin
1830a6ef376SSam Ravnborg###
184303395acSH. Peter Anvin# Syscall table generation
185303395acSH. Peter Anvin
186303395acSH. Peter Anvinarchheaders:
187303395acSH. Peter Anvin	$(Q)$(MAKE) $(build)=arch/x86/syscalls all
188303395acSH. Peter Anvin
1898fc5b4d4SVivek Goyalarchprepare:
19074ca317cSVivek Goyalifeq ($(CONFIG_KEXEC_FILE),y)
1918fc5b4d4SVivek Goyal	$(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
1928fc5b4d4SVivek Goyalendif
1938fc5b4d4SVivek Goyal
194303395acSH. Peter Anvin###
1950a6ef376SSam Ravnborg# Kernel objects
1960a6ef376SSam Ravnborg
1970a6ef376SSam Ravnborghead-y := arch/x86/kernel/head_$(BITS).o
198700efc1bSEric W. Biedermanhead-y += arch/x86/kernel/head$(BITS).o
1990c51a965SHuang, Yinghead-y += arch/x86/kernel/head.o
2000a6ef376SSam Ravnborg
2010a6ef376SSam Ravnborglibs-y  += arch/x86/lib/
2020a6ef376SSam Ravnborg
203d1f0ae5eSSam Ravnborg# See arch/x86/Kbuild for content of core part of the kernel
204d1f0ae5eSSam Ravnborgcore-y += arch/x86/
2050a6ef376SSam Ravnborg
2060a6ef376SSam Ravnborg# drivers-y are linked after core-y
2070a6ef376SSam Ravnborgdrivers-$(CONFIG_MATH_EMULATION) += arch/x86/math-emu/
2080a6ef376SSam Ravnborgdrivers-$(CONFIG_PCI)            += arch/x86/pci/
2090a6ef376SSam Ravnborg
2100a6ef376SSam Ravnborg# must be linked after kernel/
2110a6ef376SSam Ravnborgdrivers-$(CONFIG_OPROFILE) += arch/x86/oprofile/
2120a6ef376SSam Ravnborg
213cf7700feSRafael J. Wysocki# suspend and hibernation support
2140a6ef376SSam Ravnborgdrivers-$(CONFIG_PM) += arch/x86/power/
215cf7700feSRafael J. Wysocki
2160a6ef376SSam Ravnborgdrivers-$(CONFIG_FB) += arch/x86/video/
2170a6ef376SSam Ravnborg
2180a6ef376SSam Ravnborg####
2190a6ef376SSam Ravnborg# boot loader support. Several targets are kept for legacy purposes
2200a6ef376SSam Ravnborg
2210a6ef376SSam Ravnborgboot := arch/x86/boot
2220a6ef376SSam Ravnborg
2231648e4f8SH. Peter AnvinBOOT_TARGETS = bzlilo bzdisk fdimage fdimage144 fdimage288 isoimage
224f9c5107cSH. Peter Anvin
225f9c5107cSH. Peter AnvinPHONY += bzImage $(BOOT_TARGETS)
2260a6ef376SSam Ravnborg
2270a6ef376SSam Ravnborg# Default kernel to build
2280a6ef376SSam Ravnborgall: bzImage
2290a6ef376SSam Ravnborg
2300a6ef376SSam Ravnborg# KBUILD_IMAGE specify target image being built
2310a6ef376SSam RavnborgKBUILD_IMAGE := $(boot)/bzImage
2320a6ef376SSam Ravnborg
233f9c5107cSH. Peter AnvinbzImage: vmlinux
234ca0e9badSMasami Hiramatsuifeq ($(CONFIG_X86_DECODER_SELFTEST),y)
235ca0e9badSMasami Hiramatsu	$(Q)$(MAKE) $(build)=arch/x86/tools posttest
236ca0e9badSMasami Hiramatsuendif
2370a6ef376SSam Ravnborg	$(Q)$(MAKE) $(build)=$(boot) $(KBUILD_IMAGE)
2380a6ef376SSam Ravnborg	$(Q)mkdir -p $(objtree)/arch/$(UTS_MACHINE)/boot
23941b3eae6SJan Beulich	$(Q)ln -fsn ../../x86/boot/bzImage $(objtree)/arch/$(UTS_MACHINE)/boot/$@
2400a6ef376SSam Ravnborg
241f9c5107cSH. Peter Anvin$(BOOT_TARGETS): vmlinux
242f9c5107cSH. Peter Anvin	$(Q)$(MAKE) $(build)=$(boot) $@
2430a6ef376SSam Ravnborg
2441648e4f8SH. Peter AnvinPHONY += install
2451648e4f8SH. Peter Anvininstall:
2461648e4f8SH. Peter Anvin	$(Q)$(MAKE) $(build)=$(boot) $@
2471648e4f8SH. Peter Anvin
2480a6ef376SSam RavnborgPHONY += vdso_install
2490a6ef376SSam Ravnborgvdso_install:
2500a6ef376SSam Ravnborg	$(Q)$(MAKE) $(build)=arch/x86/vdso $@
2510a6ef376SSam Ravnborg
2520a6ef376SSam Ravnborgarchclean:
2530a6ef376SSam Ravnborg	$(Q)rm -rf $(objtree)/arch/i386
2540a6ef376SSam Ravnborg	$(Q)rm -rf $(objtree)/arch/x86_64
2550a6ef376SSam Ravnborg	$(Q)$(MAKE) $(clean)=$(boot)
256b2d668daSJarkko Sakkinen	$(Q)$(MAKE) $(clean)=arch/x86/tools
257b0108f9eSMichael Welling	$(Q)$(MAKE) $(clean)=arch/x86/purgatory
2580a6ef376SSam Ravnborg
2590a6ef376SSam Ravnborgdefine archhelp
2600a6ef376SSam Ravnborg  echo  '* bzImage      - Compressed kernel image (arch/x86/boot/bzImage)'
2610a6ef376SSam Ravnborg  echo  '  install      - Install kernel using'
262caa27b66SSam Ravnborg  echo  '                  (your) ~/bin/$(INSTALLKERNEL) or'
263caa27b66SSam Ravnborg  echo  '                  (distribution) /sbin/$(INSTALLKERNEL) or'
2640a6ef376SSam Ravnborg  echo  '                  install to $$(INSTALL_PATH) and run lilo'
26537f30e21SAndi Kleen  echo  '  fdimage      - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)'
26637f30e21SAndi Kleen  echo  '  fdimage144   - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)'
26737f30e21SAndi Kleen  echo  '  fdimage288   - Create 2.8MB boot floppy image (arch/x86/boot/fdimage)'
26837f30e21SAndi Kleen  echo  '  isoimage     - Create a boot CD-ROM image (arch/x86/boot/image.iso)'
26937f30e21SAndi Kleen  echo  '                  bzdisk/fdimage*/isoimage also accept:'
27037f30e21SAndi Kleen  echo  '                  FDARGS="..."  arguments for the booted kernel'
27137f30e21SAndi Kleen  echo  '                  FDINITRD=file initrd for the booted kernel'
2720a6ef376SSam Ravnborgendef
273