174b469f2SSam Ravnborg# Unified Makefile for i386 and x86_64 274b469f2SSam Ravnborg 32266cfd5SSam Ravnborg# select defconfig based on actual architecture 4d746d647SSam Ravnborgifeq ($(ARCH),x86) 5d746d647SSam Ravnborg KBUILD_DEFCONFIG := i386_defconfig 6d746d647SSam Ravnborgelse 72266cfd5SSam Ravnborg KBUILD_DEFCONFIG := $(ARCH)_defconfig 8d746d647SSam Ravnborgendif 92266cfd5SSam Ravnborg 100a6ef376SSam Ravnborg# BITS is used as extension for files which are available in a 32 bit 110a6ef376SSam Ravnborg# and a 64 bit version to simplify shared Makefiles. 120a6ef376SSam Ravnborg# e.g.: obj-y += foo_$(BITS).o 130a6ef376SSam Ravnborgexport BITS 1474b469f2SSam Ravnborg 15d746d647SSam Ravnborgifeq ($(CONFIG_X86_32),y) 160a6ef376SSam Ravnborg BITS := 32 178c6531f7SAndreas Herrmann UTS_MACHINE := i386 184ba7e5cdSSam Ravnborg CHECKFLAGS += -D__i386__ 190a6ef376SSam Ravnborg 204ba7e5cdSSam Ravnborg biarch := $(call cc-option,-m32) 214ba7e5cdSSam Ravnborg KBUILD_AFLAGS += $(biarch) 224ba7e5cdSSam Ravnborg KBUILD_CFLAGS += $(biarch) 230a6ef376SSam Ravnborg 240a6ef376SSam Ravnborg ifdef CONFIG_RELOCATABLE 250a6ef376SSam Ravnborg LDFLAGS_vmlinux := --emit-relocs 260a6ef376SSam Ravnborg endif 270a6ef376SSam Ravnborg 280a6ef376SSam Ravnborg KBUILD_CFLAGS += -msoft-float -mregparm=3 -freg-struct-return 290a6ef376SSam Ravnborg 300a6ef376SSam Ravnborg # prevent gcc from keeping the stack 16 byte aligned 310a6ef376SSam Ravnborg KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=2) 320a6ef376SSam Ravnborg 330a6ef376SSam Ravnborg # Disable unit-at-a-time mode on pre-gcc-4.0 compilers, it makes gcc use 340a6ef376SSam Ravnborg # a lot more stack due to the lack of sharing of stacklots: 35c7bd0414SFrans Pop KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0400, \ 36c7bd0414SFrans Pop $(call cc-option,-fno-unit-at-a-time)) 370a6ef376SSam Ravnborg 380a6ef376SSam Ravnborg # CPU-specific tuning. Anything which can be shared with UML should go here. 390a6ef376SSam Ravnborg include $(srctree)/arch/x86/Makefile_32.cpu 400a6ef376SSam Ravnborg KBUILD_CFLAGS += $(cflags-y) 410a6ef376SSam Ravnborg 420a6ef376SSam Ravnborg # temporary until string.h is fixed 430a6ef376SSam Ravnborg KBUILD_CFLAGS += -ffreestanding 440a6ef376SSam Ravnborgelse 450a6ef376SSam Ravnborg BITS := 64 460a6ef376SSam Ravnborg UTS_MACHINE := x86_64 470a6ef376SSam Ravnborg CHECKFLAGS += -D__x86_64__ -m64 480a6ef376SSam Ravnborg 490a6ef376SSam Ravnborg KBUILD_AFLAGS += -m64 500a6ef376SSam Ravnborg KBUILD_CFLAGS += -m64 510a6ef376SSam Ravnborg 520a6ef376SSam Ravnborg # FIXME - should be integrated in Makefile.cpu (Makefile_32.cpu) 530a6ef376SSam Ravnborg cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8) 540a6ef376SSam Ravnborg cflags-$(CONFIG_MPSC) += $(call cc-option,-march=nocona) 550a6ef376SSam Ravnborg 560a6ef376SSam Ravnborg cflags-$(CONFIG_MCORE2) += \ 570a6ef376SSam Ravnborg $(call cc-option,-march=core2,$(call cc-option,-mtune=generic)) 58366d19e1STobias Doerffel cflags-$(CONFIG_MATOM) += $(call cc-option,-march=atom) \ 59366d19e1STobias Doerffel $(call cc-option,-mtune=atom,$(call cc-option,-mtune=generic)) 600a6ef376SSam Ravnborg cflags-$(CONFIG_GENERIC_CPU) += $(call cc-option,-mtune=generic) 610a6ef376SSam Ravnborg KBUILD_CFLAGS += $(cflags-y) 620a6ef376SSam Ravnborg 630a6ef376SSam Ravnborg KBUILD_CFLAGS += -mno-red-zone 640a6ef376SSam Ravnborg KBUILD_CFLAGS += -mcmodel=kernel 650a6ef376SSam Ravnborg 660a6ef376SSam Ravnborg # -funit-at-a-time shrinks the kernel .text considerably 670a6ef376SSam Ravnborg # unfortunately it makes reading oopses harder. 680a6ef376SSam Ravnborg KBUILD_CFLAGS += $(call cc-option,-funit-at-a-time) 690a6ef376SSam Ravnborg 700a6ef376SSam Ravnborg # this works around some issues with generating unwind tables in older gccs 710a6ef376SSam Ravnborg # newer gccs do it by default 720a6ef376SSam Ravnborg KBUILD_CFLAGS += -maccumulate-outgoing-args 735d707e9cSTejun Heoendif 740a6ef376SSam Ravnborg 755d707e9cSTejun Heoifdef CONFIG_CC_STACKPROTECTOR 765d707e9cSTejun Heo cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh 7708c2b394Sbasile@opensource.dyc.edu ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y) 785d707e9cSTejun Heo stackp-y := -fstack-protector 790a6ef376SSam Ravnborg KBUILD_CFLAGS += $(stackp-y) 805d707e9cSTejun Heo else 815d707e9cSTejun Heo $(warning stack protector enabled but no compiler support) 825d707e9cSTejun Heo endif 830a6ef376SSam Ravnborgendif 840a6ef376SSam Ravnborg 850bf62763SH. Peter Anvinifdef CONFIG_X86_X32 860bf62763SH. Peter Anvin x32_ld_ok := $(call try-run,\ 870bf62763SH. Peter Anvin /bin/echo -e '1: .quad 1b' | \ 880bf62763SH. Peter Anvin $(CC) $(KBUILD_AFLAGS) -c -xassembler -o "$$TMP" - && \ 890bf62763SH. Peter Anvin $(OBJCOPY) -O elf32-x86-64 "$$TMP" "$$TMPO" && \ 900bf62763SH. Peter Anvin $(LD) -m elf32_x86_64 "$$TMPO" -o "$$TMP",y,n) 910bf62763SH. Peter Anvin ifeq ($(x32_ld_ok),y) 920bf62763SH. Peter Anvin CONFIG_X86_X32_ABI := y 930bf62763SH. Peter Anvin KBUILD_AFLAGS += -DCONFIG_X86_X32_ABI 940bf62763SH. Peter Anvin KBUILD_CFLAGS += -DCONFIG_X86_X32_ABI 950bf62763SH. Peter Anvin else 960bf62763SH. Peter Anvin $(warning CONFIG_X86_X32 enabled but no binutils support) 970bf62763SH. Peter Anvin endif 980bf62763SH. Peter Anvinendif 990bf62763SH. Peter Anvinexport CONFIG_X86_X32_ABI 1000bf62763SH. Peter Anvin 101dfec072eSVegard Nossum# Don't unroll struct assignments with kmemcheck enabled 102dfec072eSVegard Nossumifeq ($(CONFIG_KMEMCHECK),y) 103dfec072eSVegard Nossum KBUILD_CFLAGS += $(call cc-option,-fno-builtin-memcpy) 104dfec072eSVegard Nossumendif 105dfec072eSVegard Nossum 1060a6ef376SSam Ravnborg# Stackpointer is addressed different for 32 bit and 64 bit x86 1070a6ef376SSam Ravnborgsp-$(CONFIG_X86_32) := esp 1080a6ef376SSam Ravnborgsp-$(CONFIG_X86_64) := rsp 1090a6ef376SSam Ravnborg 1100a6ef376SSam Ravnborg# do binutils support CFI? 1110a6ef376SSam Ravnborgcfi := $(call as-instr,.cfi_startproc\n.cfi_rel_offset $(sp-y)$(comma)0\n.cfi_endproc,-DCONFIG_AS_CFI=1) 1120a6ef376SSam Ravnborg# is .cfi_signal_frame supported too? 1130a6ef376SSam Ravnborgcfi-sigframe := $(call as-instr,.cfi_startproc\n.cfi_signal_frame\n.cfi_endproc,-DCONFIG_AS_CFI_SIGNAL_FRAME=1) 1149e565292SRoland McGrathcfi-sections := $(call as-instr,.cfi_sections .debug_frame,-DCONFIG_AS_CFI_SECTIONS=1) 115d7acb92fSH. Peter Anvin 116d7acb92fSH. Peter Anvin# does binutils support specific instructions? 117d7acb92fSH. Peter Anvinasinstr := $(call as-instr,fxsaveq (%rax),-DCONFIG_AS_FXSAVEQ=1) 118d7acb92fSH. Peter Anvin 119d7acb92fSH. Peter AnvinKBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) 120d7acb92fSH. Peter AnvinKBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) 1210a6ef376SSam Ravnborg 1220a6ef376SSam RavnborgLDFLAGS := -m elf_$(UTS_MACHINE) 12325dfeeb7SSam Ravnborg 12425dfeeb7SSam Ravnborg# Speed up the build 1250a6ef376SSam RavnborgKBUILD_CFLAGS += -pipe 12625dfeeb7SSam Ravnborg# Workaround for a gcc prelease that unfortunately was shipped in a suse release 12725dfeeb7SSam RavnborgKBUILD_CFLAGS += -Wno-sign-compare 12825dfeeb7SSam Ravnborg# 12925dfeeb7SSam RavnborgKBUILD_CFLAGS += -fno-asynchronous-unwind-tables 13025dfeeb7SSam Ravnborg# prevent gcc from generating any FP code by mistake 13125dfeeb7SSam RavnborgKBUILD_CFLAGS += $(call cc-option,-mno-sse -mno-mmx -mno-sse2 -mno-3dnow,) 132c0e9afc0SAndi KleenKBUILD_CFLAGS += $(call cc-option,-mno-avx,) 1330a6ef376SSam Ravnborg 1340a6ef376SSam RavnborgKBUILD_CFLAGS += $(mflags-y) 1350a6ef376SSam RavnborgKBUILD_AFLAGS += $(mflags-y) 1360a6ef376SSam Ravnborg 1376520fe55SH. Peter Anvinarchscripts: 1386520fe55SH. Peter Anvin $(Q)$(MAKE) $(build)=arch/x86/tools relocs 1396520fe55SH. Peter Anvin 1400a6ef376SSam Ravnborg### 141303395acSH. Peter Anvin# Syscall table generation 142303395acSH. Peter Anvin 143303395acSH. Peter Anvinarchheaders: 144303395acSH. Peter Anvin $(Q)$(MAKE) $(build)=arch/x86/syscalls all 145303395acSH. Peter Anvin 146303395acSH. Peter Anvin### 1470a6ef376SSam Ravnborg# Kernel objects 1480a6ef376SSam Ravnborg 1490a6ef376SSam Ravnborghead-y := arch/x86/kernel/head_$(BITS).o 150700efc1bSEric W. Biedermanhead-y += arch/x86/kernel/head$(BITS).o 1510c51a965SHuang, Yinghead-y += arch/x86/kernel/head.o 1520a6ef376SSam Ravnborghead-y += arch/x86/kernel/init_task.o 1530a6ef376SSam Ravnborg 1540a6ef376SSam Ravnborglibs-y += arch/x86/lib/ 1550a6ef376SSam Ravnborg 156d1f0ae5eSSam Ravnborg# See arch/x86/Kbuild for content of core part of the kernel 157d1f0ae5eSSam Ravnborgcore-y += arch/x86/ 1580a6ef376SSam Ravnborg 1590a6ef376SSam Ravnborg# drivers-y are linked after core-y 1600a6ef376SSam Ravnborgdrivers-$(CONFIG_MATH_EMULATION) += arch/x86/math-emu/ 1610a6ef376SSam Ravnborgdrivers-$(CONFIG_PCI) += arch/x86/pci/ 1620a6ef376SSam Ravnborg 1630a6ef376SSam Ravnborg# must be linked after kernel/ 1640a6ef376SSam Ravnborgdrivers-$(CONFIG_OPROFILE) += arch/x86/oprofile/ 1650a6ef376SSam Ravnborg 166cf7700feSRafael J. Wysocki# suspend and hibernation support 1670a6ef376SSam Ravnborgdrivers-$(CONFIG_PM) += arch/x86/power/ 168cf7700feSRafael J. Wysocki 1690a6ef376SSam Ravnborgdrivers-$(CONFIG_FB) += arch/x86/video/ 1700a6ef376SSam Ravnborg 1710a6ef376SSam Ravnborg#### 1720a6ef376SSam Ravnborg# boot loader support. Several targets are kept for legacy purposes 1730a6ef376SSam Ravnborg 1740a6ef376SSam Ravnborgboot := arch/x86/boot 1750a6ef376SSam Ravnborg 1761648e4f8SH. Peter AnvinBOOT_TARGETS = bzlilo bzdisk fdimage fdimage144 fdimage288 isoimage 177f9c5107cSH. Peter Anvin 178f9c5107cSH. Peter AnvinPHONY += bzImage $(BOOT_TARGETS) 1790a6ef376SSam Ravnborg 1800a6ef376SSam Ravnborg# Default kernel to build 1810a6ef376SSam Ravnborgall: bzImage 1820a6ef376SSam Ravnborg 1830a6ef376SSam Ravnborg# KBUILD_IMAGE specify target image being built 1840a6ef376SSam RavnborgKBUILD_IMAGE := $(boot)/bzImage 1850a6ef376SSam Ravnborg 186f9c5107cSH. Peter AnvinbzImage: vmlinux 187ca0e9badSMasami Hiramatsuifeq ($(CONFIG_X86_DECODER_SELFTEST),y) 188ca0e9badSMasami Hiramatsu $(Q)$(MAKE) $(build)=arch/x86/tools posttest 189ca0e9badSMasami Hiramatsuendif 1900a6ef376SSam Ravnborg $(Q)$(MAKE) $(build)=$(boot) $(KBUILD_IMAGE) 1910a6ef376SSam Ravnborg $(Q)mkdir -p $(objtree)/arch/$(UTS_MACHINE)/boot 19241b3eae6SJan Beulich $(Q)ln -fsn ../../x86/boot/bzImage $(objtree)/arch/$(UTS_MACHINE)/boot/$@ 1930a6ef376SSam Ravnborg 194f9c5107cSH. Peter Anvin$(BOOT_TARGETS): vmlinux 195f9c5107cSH. Peter Anvin $(Q)$(MAKE) $(build)=$(boot) $@ 1960a6ef376SSam Ravnborg 1971648e4f8SH. Peter AnvinPHONY += install 1981648e4f8SH. Peter Anvininstall: 1991648e4f8SH. Peter Anvin $(Q)$(MAKE) $(build)=$(boot) $@ 2001648e4f8SH. Peter Anvin 2010a6ef376SSam RavnborgPHONY += vdso_install 2020a6ef376SSam Ravnborgvdso_install: 2030a6ef376SSam Ravnborg $(Q)$(MAKE) $(build)=arch/x86/vdso $@ 2040a6ef376SSam Ravnborg 2050a6ef376SSam Ravnborgarchclean: 2060a6ef376SSam Ravnborg $(Q)rm -rf $(objtree)/arch/i386 2070a6ef376SSam Ravnborg $(Q)rm -rf $(objtree)/arch/x86_64 2080a6ef376SSam Ravnborg $(Q)$(MAKE) $(clean)=$(boot) 209*b2d668daSJarkko Sakkinen $(Q)$(MAKE) $(clean)=arch/x86/tools 2100a6ef376SSam Ravnborg 2110a6ef376SSam Ravnborgdefine archhelp 2120a6ef376SSam Ravnborg echo '* bzImage - Compressed kernel image (arch/x86/boot/bzImage)' 2130a6ef376SSam Ravnborg echo ' install - Install kernel using' 214caa27b66SSam Ravnborg echo ' (your) ~/bin/$(INSTALLKERNEL) or' 215caa27b66SSam Ravnborg echo ' (distribution) /sbin/$(INSTALLKERNEL) or' 2160a6ef376SSam Ravnborg echo ' install to $$(INSTALL_PATH) and run lilo' 21737f30e21SAndi Kleen echo ' fdimage - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)' 21837f30e21SAndi Kleen echo ' fdimage144 - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)' 21937f30e21SAndi Kleen echo ' fdimage288 - Create 2.8MB boot floppy image (arch/x86/boot/fdimage)' 22037f30e21SAndi Kleen echo ' isoimage - Create a boot CD-ROM image (arch/x86/boot/image.iso)' 22137f30e21SAndi Kleen echo ' bzdisk/fdimage*/isoimage also accept:' 22237f30e21SAndi Kleen echo ' FDARGS="..." arguments for the booted kernel' 22337f30e21SAndi Kleen echo ' FDINITRD=file initrd for the booted kernel' 2240a6ef376SSam Ravnborgendef 225