Back to home page

LXR

 
 

    


0001 # Unified Makefile for i386 and x86_64
0002 
0003 # select defconfig based on actual architecture
0004 ifeq ($(ARCH),x86)
0005   ifeq ($(shell uname -m),x86_64)
0006         KBUILD_DEFCONFIG := x86_64_defconfig
0007   else
0008         KBUILD_DEFCONFIG := i386_defconfig
0009   endif
0010 else
0011         KBUILD_DEFCONFIG := $(ARCH)_defconfig
0012 endif
0013 
0014 # How to compile the 16-bit code.  Note we always compile for -march=i386;
0015 # that way we can complain to the user if the CPU is insufficient.
0016 #
0017 # The -m16 option is supported by GCC >= 4.9 and clang >= 3.5. For
0018 # older versions of GCC, include an *assembly* header to make sure that
0019 # gcc doesn't play any games behind our back.
0020 CODE16GCC_CFLAGS := -m32 -Wa,$(srctree)/arch/x86/boot/code16gcc.h
0021 M16_CFLAGS       := $(call cc-option, -m16, $(CODE16GCC_CFLAGS))
0022 
0023 REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -D__KERNEL__ \
0024                    -DDISABLE_BRANCH_PROFILING \
0025                    -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
0026                    -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
0027                    -mno-mmx -mno-sse \
0028                    $(call cc-option, -ffreestanding) \
0029                    $(call cc-option, -fno-stack-protector) \
0030                    $(call cc-option, -mpreferred-stack-boundary=2)
0031 export REALMODE_CFLAGS
0032 
0033 # BITS is used as extension for files which are available in a 32 bit
0034 # and a 64 bit version to simplify shared Makefiles.
0035 # e.g.: obj-y += foo_$(BITS).o
0036 export BITS
0037 
0038 ifdef CONFIG_X86_NEED_RELOCS
0039         LDFLAGS_vmlinux := --emit-relocs
0040 endif
0041 
0042 #
0043 # Prevent GCC from generating any FP code by mistake.
0044 #
0045 # This must happen before we try the -mpreferred-stack-boundary, see:
0046 #
0047 #    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383
0048 #
0049 KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow
0050 KBUILD_CFLAGS += $(call cc-option,-mno-avx,)
0051 
0052 ifeq ($(CONFIG_X86_32),y)
0053         BITS := 32
0054         UTS_MACHINE := i386
0055         CHECKFLAGS += -D__i386__
0056 
0057         biarch := $(call cc-option,-m32)
0058         KBUILD_AFLAGS += $(biarch)
0059         KBUILD_CFLAGS += $(biarch)
0060 
0061         KBUILD_CFLAGS += -msoft-float -mregparm=3 -freg-struct-return
0062 
0063         # Never want PIC in a 32-bit kernel, prevent breakage with GCC built
0064         # with nonstandard options
0065         KBUILD_CFLAGS += -fno-pic
0066 
0067         # prevent gcc from keeping the stack 16 byte aligned
0068         KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=2)
0069 
0070         # Disable unit-at-a-time mode on pre-gcc-4.0 compilers, it makes gcc use
0071         # a lot more stack due to the lack of sharing of stacklots:
0072         KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0400, \
0073                                 $(call cc-option,-fno-unit-at-a-time))
0074 
0075         # CPU-specific tuning. Anything which can be shared with UML should go here.
0076         include arch/x86/Makefile_32.cpu
0077         KBUILD_CFLAGS += $(cflags-y)
0078 
0079         # temporary until string.h is fixed
0080         KBUILD_CFLAGS += -ffreestanding
0081 else
0082         BITS := 64
0083         UTS_MACHINE := x86_64
0084         CHECKFLAGS += -D__x86_64__ -m64
0085 
0086         biarch := -m64
0087         KBUILD_AFLAGS += -m64
0088         KBUILD_CFLAGS += -m64
0089 
0090         # Align jump targets to 1 byte, not the default 16 bytes:
0091         KBUILD_CFLAGS += -falign-jumps=1
0092 
0093         # Pack loops tightly as well:
0094         KBUILD_CFLAGS += -falign-loops=1
0095 
0096         # Don't autogenerate traditional x87 instructions
0097         KBUILD_CFLAGS += $(call cc-option,-mno-80387)
0098         KBUILD_CFLAGS += $(call cc-option,-mno-fp-ret-in-387)
0099 
0100         # Use -mpreferred-stack-boundary=3 if supported.
0101         KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3)
0102 
0103         # Use -mskip-rax-setup if supported.
0104         KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)
0105 
0106         # FIXME - should be integrated in Makefile.cpu (Makefile_32.cpu)
0107         cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8)
0108         cflags-$(CONFIG_MPSC) += $(call cc-option,-march=nocona)
0109 
0110         cflags-$(CONFIG_MCORE2) += \
0111                 $(call cc-option,-march=core2,$(call cc-option,-mtune=generic))
0112         cflags-$(CONFIG_MATOM) += $(call cc-option,-march=atom) \
0113                 $(call cc-option,-mtune=atom,$(call cc-option,-mtune=generic))
0114         cflags-$(CONFIG_GENERIC_CPU) += $(call cc-option,-mtune=generic)
0115         KBUILD_CFLAGS += $(cflags-y)
0116 
0117         KBUILD_CFLAGS += -mno-red-zone
0118         KBUILD_CFLAGS += -mcmodel=kernel
0119 
0120         # -funit-at-a-time shrinks the kernel .text considerably
0121         # unfortunately it makes reading oopses harder.
0122         KBUILD_CFLAGS += $(call cc-option,-funit-at-a-time)
0123 
0124         # this works around some issues with generating unwind tables in older gccs
0125         # newer gccs do it by default
0126         KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
0127 endif
0128 
0129 ifdef CONFIG_X86_X32
0130         x32_ld_ok := $(call try-run,\
0131                         /bin/echo -e '1: .quad 1b' | \
0132                         $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" - && \
0133                         $(OBJCOPY) -O elf32-x86-64 "$$TMP" "$$TMPO" && \
0134                         $(LD) -m elf32_x86_64 "$$TMPO" -o "$$TMP",y,n)
0135         ifeq ($(x32_ld_ok),y)
0136                 CONFIG_X86_X32_ABI := y
0137                 KBUILD_AFLAGS += -DCONFIG_X86_X32_ABI
0138                 KBUILD_CFLAGS += -DCONFIG_X86_X32_ABI
0139         else
0140                 $(warning CONFIG_X86_X32 enabled but no binutils support)
0141         endif
0142 endif
0143 export CONFIG_X86_X32_ABI
0144 
0145 # Don't unroll struct assignments with kmemcheck enabled
0146 ifeq ($(CONFIG_KMEMCHECK),y)
0147         KBUILD_CFLAGS += $(call cc-option,-fno-builtin-memcpy)
0148 endif
0149 
0150 # Stackpointer is addressed different for 32 bit and 64 bit x86
0151 sp-$(CONFIG_X86_32) := esp
0152 sp-$(CONFIG_X86_64) := rsp
0153 
0154 # do binutils support CFI?
0155 cfi := $(call as-instr,.cfi_startproc\n.cfi_rel_offset $(sp-y)$(comma)0\n.cfi_endproc,-DCONFIG_AS_CFI=1)
0156 # is .cfi_signal_frame supported too?
0157 cfi-sigframe := $(call as-instr,.cfi_startproc\n.cfi_signal_frame\n.cfi_endproc,-DCONFIG_AS_CFI_SIGNAL_FRAME=1)
0158 cfi-sections := $(call as-instr,.cfi_sections .debug_frame,-DCONFIG_AS_CFI_SECTIONS=1)
0159 
0160 # does binutils support specific instructions?
0161 asinstr := $(call as-instr,fxsaveq (%rax),-DCONFIG_AS_FXSAVEQ=1)
0162 asinstr += $(call as-instr,pshufb %xmm0$(comma)%xmm0,-DCONFIG_AS_SSSE3=1)
0163 asinstr += $(call as-instr,crc32l %eax$(comma)%eax,-DCONFIG_AS_CRC32=1)
0164 avx_instr := $(call as-instr,vxorps %ymm0$(comma)%ymm1$(comma)%ymm2,-DCONFIG_AS_AVX=1)
0165 avx2_instr :=$(call as-instr,vpbroadcastb %xmm0$(comma)%ymm1,-DCONFIG_AS_AVX2=1)
0166 avx512_instr :=$(call as-instr,vpmovm2b %k1$(comma)%zmm5,-DCONFIG_AS_AVX512=1)
0167 sha1_ni_instr :=$(call as-instr,sha1msg1 %xmm0$(comma)%xmm1,-DCONFIG_AS_SHA1_NI=1)
0168 sha256_ni_instr :=$(call as-instr,sha256msg1 %xmm0$(comma)%xmm1,-DCONFIG_AS_SHA256_NI=1)
0169 
0170 KBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr)
0171 KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr)
0172 
0173 LDFLAGS := -m elf_$(UTS_MACHINE)
0174 
0175 # Speed up the build
0176 KBUILD_CFLAGS += -pipe
0177 # Workaround for a gcc prelease that unfortunately was shipped in a suse release
0178 KBUILD_CFLAGS += -Wno-sign-compare
0179 #
0180 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
0181 
0182 KBUILD_CFLAGS += $(mflags-y)
0183 KBUILD_AFLAGS += $(mflags-y)
0184 
0185 archscripts: scripts_basic
0186         $(Q)$(MAKE) $(build)=arch/x86/tools relocs
0187 
0188 ###
0189 # Syscall table generation
0190 
0191 archheaders:
0192         $(Q)$(MAKE) $(build)=arch/x86/entry/syscalls all
0193 
0194 archprepare:
0195 ifeq ($(CONFIG_KEXEC_FILE),y)
0196         $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
0197 endif
0198 
0199 ###
0200 # Kernel objects
0201 
0202 head-y := arch/x86/kernel/head_$(BITS).o
0203 head-y += arch/x86/kernel/head$(BITS).o
0204 head-y += arch/x86/kernel/ebda.o
0205 head-y += arch/x86/kernel/platform-quirks.o
0206 
0207 libs-y  += arch/x86/lib/
0208 
0209 # See arch/x86/Kbuild for content of core part of the kernel
0210 core-y += arch/x86/
0211 
0212 # drivers-y are linked after core-y
0213 drivers-$(CONFIG_MATH_EMULATION) += arch/x86/math-emu/
0214 drivers-$(CONFIG_PCI)            += arch/x86/pci/
0215 
0216 # must be linked after kernel/
0217 drivers-$(CONFIG_OPROFILE) += arch/x86/oprofile/
0218 
0219 # suspend and hibernation support
0220 drivers-$(CONFIG_PM) += arch/x86/power/
0221 
0222 drivers-$(CONFIG_FB) += arch/x86/video/
0223 
0224 drivers-$(CONFIG_RAS) += arch/x86/ras/
0225 
0226 ####
0227 # boot loader support. Several targets are kept for legacy purposes
0228 
0229 boot := arch/x86/boot
0230 
0231 BOOT_TARGETS = bzlilo bzdisk fdimage fdimage144 fdimage288 isoimage
0232 
0233 PHONY += bzImage $(BOOT_TARGETS)
0234 
0235 # Default kernel to build
0236 all: bzImage
0237 
0238 # KBUILD_IMAGE specify target image being built
0239 KBUILD_IMAGE := $(boot)/bzImage
0240 
0241 bzImage: vmlinux
0242 ifeq ($(CONFIG_X86_DECODER_SELFTEST),y)
0243         $(Q)$(MAKE) $(build)=arch/x86/tools posttest
0244 endif
0245         $(Q)$(MAKE) $(build)=$(boot) $(KBUILD_IMAGE)
0246         $(Q)mkdir -p $(objtree)/arch/$(UTS_MACHINE)/boot
0247         $(Q)ln -fsn ../../x86/boot/bzImage $(objtree)/arch/$(UTS_MACHINE)/boot/$@
0248 
0249 $(BOOT_TARGETS): vmlinux
0250         $(Q)$(MAKE) $(build)=$(boot) $@
0251 
0252 PHONY += install
0253 install:
0254         $(Q)$(MAKE) $(build)=$(boot) $@
0255 
0256 PHONY += vdso_install
0257 vdso_install:
0258         $(Q)$(MAKE) $(build)=arch/x86/entry/vdso $@
0259 
0260 archclean:
0261         $(Q)rm -rf $(objtree)/arch/i386
0262         $(Q)rm -rf $(objtree)/arch/x86_64
0263         $(Q)$(MAKE) $(clean)=$(boot)
0264         $(Q)$(MAKE) $(clean)=arch/x86/tools
0265         $(Q)$(MAKE) $(clean)=arch/x86/purgatory
0266 
0267 define archhelp
0268   echo  '* bzImage      - Compressed kernel image (arch/x86/boot/bzImage)'
0269   echo  '  install      - Install kernel using'
0270   echo  '                  (your) ~/bin/$(INSTALLKERNEL) or'
0271   echo  '                  (distribution) /sbin/$(INSTALLKERNEL) or'
0272   echo  '                  install to $$(INSTALL_PATH) and run lilo'
0273   echo  '  fdimage      - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)'
0274   echo  '  fdimage144   - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)'
0275   echo  '  fdimage288   - Create 2.8MB boot floppy image (arch/x86/boot/fdimage)'
0276   echo  '  isoimage     - Create a boot CD-ROM image (arch/x86/boot/image.iso)'
0277   echo  '                  bzdisk/fdimage*/isoimage also accept:'
0278   echo  '                  FDARGS="..."  arguments for the booted kernel'
0279   echo  '                  FDINITRD=file initrd for the booted kernel'
0280 endef