]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/x86/Makefile
f1791addf7fcd46f103a17e919283c5fcf04b5e1
[karo-tx-linux.git] / arch / x86 / Makefile
1 # Unified Makefile for i386 and x86_64
2
3 # select defconfig based on actual architecture
4 ifeq ($(ARCH),x86)
5   ifeq ($(shell uname -m),x86_64)
6         KBUILD_DEFCONFIG := x86_64_defconfig
7   else
8         KBUILD_DEFCONFIG := i386_defconfig
9   endif
10 else
11         KBUILD_DEFCONFIG := $(ARCH)_defconfig
12 endif
13
14 # How to compile the 16-bit code.  Note we always compile for -march=i386;
15 # that way we can complain to the user if the CPU is insufficient.
16 #
17 # The -m16 option is supported by GCC >= 4.9 and clang >= 3.5. For
18 # older versions of GCC, include an *assembly* header to make sure that
19 # gcc doesn't play any games behind our back.
20 CODE16GCC_CFLAGS := -m32 -Wa,$(srctree)/arch/x86/boot/code16gcc.h
21 M16_CFLAGS       := $(call cc-option, -m16, $(CODE16GCC_CFLAGS))
22
23 REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -D__KERNEL__ \
24                    -DDISABLE_BRANCH_PROFILING \
25                    -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
26                    -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
27                    -mno-mmx -mno-sse
28
29 REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding)
30 REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -fno-stack-protector)
31 REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -mpreferred-stack-boundary=2)
32 export REALMODE_CFLAGS
33
34 # BITS is used as extension for files which are available in a 32 bit
35 # and a 64 bit version to simplify shared Makefiles.
36 # e.g.: obj-y += foo_$(BITS).o
37 export BITS
38
39 ifdef CONFIG_X86_NEED_RELOCS
40         LDFLAGS_vmlinux := --emit-relocs
41 endif
42
43 #
44 # Prevent GCC from generating any FP code by mistake.
45 #
46 # This must happen before we try the -mpreferred-stack-boundary, see:
47 #
48 #    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383
49 #
50 KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow
51 KBUILD_CFLAGS += $(call cc-option,-mno-avx,)
52
53 ifeq ($(CONFIG_X86_32),y)
54         BITS := 32
55         UTS_MACHINE := i386
56         CHECKFLAGS += -D__i386__
57
58         biarch := $(call cc-option,-m32)
59         KBUILD_AFLAGS += $(biarch)
60         KBUILD_CFLAGS += $(biarch)
61
62         KBUILD_CFLAGS += -msoft-float -mregparm=3 -freg-struct-return
63
64         # Never want PIC in a 32-bit kernel, prevent breakage with GCC built
65         # with nonstandard options
66         KBUILD_CFLAGS += -fno-pic
67
68         # prevent gcc from keeping the stack 16 byte aligned
69         KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=2)
70
71         # Disable unit-at-a-time mode on pre-gcc-4.0 compilers, it makes gcc use
72         # a lot more stack due to the lack of sharing of stacklots:
73         KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0400, \
74                                 $(call cc-option,-fno-unit-at-a-time))
75
76         # CPU-specific tuning. Anything which can be shared with UML should go here.
77         include arch/x86/Makefile_32.cpu
78         KBUILD_CFLAGS += $(cflags-y)
79
80         # temporary until string.h is fixed
81         KBUILD_CFLAGS += -ffreestanding
82 else
83         BITS := 64
84         UTS_MACHINE := x86_64
85         CHECKFLAGS += -D__x86_64__ -m64
86
87         biarch := -m64
88         KBUILD_AFLAGS += -m64
89         KBUILD_CFLAGS += -m64
90
91         # Align jump targets to 1 byte, not the default 16 bytes:
92         KBUILD_CFLAGS += $(call cc-option,-falign-jumps=1)
93
94         # Pack loops tightly as well:
95         KBUILD_CFLAGS += $(call cc-option,-falign-loops=1)
96
97         # Don't autogenerate traditional x87 instructions
98         KBUILD_CFLAGS += $(call cc-option,-mno-80387)
99         KBUILD_CFLAGS += $(call cc-option,-mno-fp-ret-in-387)
100
101         # Use -mpreferred-stack-boundary=3 if supported.
102         KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3)
103
104         # Use -mskip-rax-setup if supported.
105         KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)
106
107         # FIXME - should be integrated in Makefile.cpu (Makefile_32.cpu)
108         cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8)
109         cflags-$(CONFIG_MPSC) += $(call cc-option,-march=nocona)
110
111         cflags-$(CONFIG_MCORE2) += \
112                 $(call cc-option,-march=core2,$(call cc-option,-mtune=generic))
113         cflags-$(CONFIG_MATOM) += $(call cc-option,-march=atom) \
114                 $(call cc-option,-mtune=atom,$(call cc-option,-mtune=generic))
115         cflags-$(CONFIG_GENERIC_CPU) += $(call cc-option,-mtune=generic)
116         KBUILD_CFLAGS += $(cflags-y)
117
118         KBUILD_CFLAGS += -mno-red-zone
119         KBUILD_CFLAGS += -mcmodel=kernel
120
121         # -funit-at-a-time shrinks the kernel .text considerably
122         # unfortunately it makes reading oopses harder.
123         KBUILD_CFLAGS += $(call cc-option,-funit-at-a-time)
124 endif
125
126 ifdef CONFIG_X86_X32
127         x32_ld_ok := $(call try-run,\
128                         /bin/echo -e '1: .quad 1b' | \
129                         $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" - && \
130                         $(OBJCOPY) -O elf32-x86-64 "$$TMP" "$$TMPO" && \
131                         $(LD) -m elf32_x86_64 "$$TMPO" -o "$$TMP",y,n)
132         ifeq ($(x32_ld_ok),y)
133                 CONFIG_X86_X32_ABI := y
134                 KBUILD_AFLAGS += -DCONFIG_X86_X32_ABI
135                 KBUILD_CFLAGS += -DCONFIG_X86_X32_ABI
136         else
137                 $(warning CONFIG_X86_X32 enabled but no binutils support)
138         endif
139 endif
140 export CONFIG_X86_X32_ABI
141
142 # Don't unroll struct assignments with kmemcheck enabled
143 ifeq ($(CONFIG_KMEMCHECK),y)
144         KBUILD_CFLAGS += $(call cc-option,-fno-builtin-memcpy)
145 endif
146
147 #
148 # If the function graph tracer is used with mcount instead of fentry,
149 # '-maccumulate-outgoing-args' is needed to prevent a GCC bug
150 # (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42109)
151 #
152 ifdef CONFIG_FUNCTION_GRAPH_TRACER
153   ifndef CONFIG_HAVE_FENTRY
154         ACCUMULATE_OUTGOING_ARGS := 1
155   else
156     ifeq ($(call cc-option-yn, -mfentry), n)
157         ACCUMULATE_OUTGOING_ARGS := 1
158
159         # GCC ignores '-maccumulate-outgoing-args' when used with '-Os'.
160         # If '-Os' is enabled, disable it and print a warning.
161         ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
162           undefine CONFIG_CC_OPTIMIZE_FOR_SIZE
163           $(warning Disabling CONFIG_CC_OPTIMIZE_FOR_SIZE.  Your compiler does not have -mfentry so you cannot optimize for size with CONFIG_FUNCTION_GRAPH_TRACER.)
164         endif
165
166     endif
167   endif
168 endif
169
170 #
171 # Jump labels need '-maccumulate-outgoing-args' for gcc < 4.5.2 to prevent a
172 # GCC bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46226).  There's no way
173 # to test for this bug at compile-time because the test case needs to execute,
174 # which is a no-go for cross compilers.  So check the GCC version instead.
175 #
176 ifdef CONFIG_JUMP_LABEL
177   ifneq ($(ACCUMULATE_OUTGOING_ARGS), 1)
178         ACCUMULATE_OUTGOING_ARGS = $(call cc-if-fullversion, -lt, 040502, 1)
179   endif
180 endif
181
182 ifeq ($(ACCUMULATE_OUTGOING_ARGS), 1)
183         # This compiler flag is not supported by Clang:
184         KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args,)
185 endif
186
187 # Stackpointer is addressed different for 32 bit and 64 bit x86
188 sp-$(CONFIG_X86_32) := esp
189 sp-$(CONFIG_X86_64) := rsp
190
191 # do binutils support CFI?
192 cfi := $(call as-instr,.cfi_startproc\n.cfi_rel_offset $(sp-y)$(comma)0\n.cfi_endproc,-DCONFIG_AS_CFI=1)
193 # is .cfi_signal_frame supported too?
194 cfi-sigframe := $(call as-instr,.cfi_startproc\n.cfi_signal_frame\n.cfi_endproc,-DCONFIG_AS_CFI_SIGNAL_FRAME=1)
195 cfi-sections := $(call as-instr,.cfi_sections .debug_frame,-DCONFIG_AS_CFI_SECTIONS=1)
196
197 # does binutils support specific instructions?
198 asinstr := $(call as-instr,fxsaveq (%rax),-DCONFIG_AS_FXSAVEQ=1)
199 asinstr += $(call as-instr,pshufb %xmm0$(comma)%xmm0,-DCONFIG_AS_SSSE3=1)
200 asinstr += $(call as-instr,crc32l %eax$(comma)%eax,-DCONFIG_AS_CRC32=1)
201 avx_instr := $(call as-instr,vxorps %ymm0$(comma)%ymm1$(comma)%ymm2,-DCONFIG_AS_AVX=1)
202 avx2_instr :=$(call as-instr,vpbroadcastb %xmm0$(comma)%ymm1,-DCONFIG_AS_AVX2=1)
203 avx512_instr :=$(call as-instr,vpmovm2b %k1$(comma)%zmm5,-DCONFIG_AS_AVX512=1)
204 sha1_ni_instr :=$(call as-instr,sha1msg1 %xmm0$(comma)%xmm1,-DCONFIG_AS_SHA1_NI=1)
205 sha256_ni_instr :=$(call as-instr,sha256msg1 %xmm0$(comma)%xmm1,-DCONFIG_AS_SHA256_NI=1)
206
207 KBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr)
208 KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr)
209
210 LDFLAGS := -m elf_$(UTS_MACHINE)
211
212 # Speed up the build
213 KBUILD_CFLAGS += -pipe
214 # Workaround for a gcc prelease that unfortunately was shipped in a suse release
215 KBUILD_CFLAGS += -Wno-sign-compare
216 #
217 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
218
219 KBUILD_CFLAGS += $(mflags-y)
220 KBUILD_AFLAGS += $(mflags-y)
221
222 archscripts: scripts_basic
223         $(Q)$(MAKE) $(build)=arch/x86/tools relocs
224
225 ###
226 # Syscall table generation
227
228 archheaders:
229         $(Q)$(MAKE) $(build)=arch/x86/entry/syscalls all
230
231 archprepare:
232 ifeq ($(CONFIG_KEXEC_FILE),y)
233         $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
234 endif
235
236 ###
237 # Kernel objects
238
239 head-y := arch/x86/kernel/head_$(BITS).o
240 head-y += arch/x86/kernel/head$(BITS).o
241 head-y += arch/x86/kernel/ebda.o
242 head-y += arch/x86/kernel/platform-quirks.o
243
244 libs-y  += arch/x86/lib/
245
246 # See arch/x86/Kbuild for content of core part of the kernel
247 core-y += arch/x86/
248
249 # drivers-y are linked after core-y
250 drivers-$(CONFIG_MATH_EMULATION) += arch/x86/math-emu/
251 drivers-$(CONFIG_PCI)            += arch/x86/pci/
252
253 # must be linked after kernel/
254 drivers-$(CONFIG_OPROFILE) += arch/x86/oprofile/
255
256 # suspend and hibernation support
257 drivers-$(CONFIG_PM) += arch/x86/power/
258
259 drivers-$(CONFIG_FB) += arch/x86/video/
260
261 drivers-$(CONFIG_RAS) += arch/x86/ras/
262
263 ####
264 # boot loader support. Several targets are kept for legacy purposes
265
266 boot := arch/x86/boot
267
268 BOOT_TARGETS = bzlilo bzdisk fdimage fdimage144 fdimage288 isoimage
269
270 PHONY += bzImage $(BOOT_TARGETS)
271
272 # Default kernel to build
273 all: bzImage
274
275 # KBUILD_IMAGE specify target image being built
276 KBUILD_IMAGE := $(boot)/bzImage
277
278 bzImage: vmlinux
279 ifeq ($(CONFIG_X86_DECODER_SELFTEST),y)
280         $(Q)$(MAKE) $(build)=arch/x86/tools posttest
281 endif
282         $(Q)$(MAKE) $(build)=$(boot) $(KBUILD_IMAGE)
283         $(Q)mkdir -p $(objtree)/arch/$(UTS_MACHINE)/boot
284         $(Q)ln -fsn ../../x86/boot/bzImage $(objtree)/arch/$(UTS_MACHINE)/boot/$@
285
286 $(BOOT_TARGETS): vmlinux
287         $(Q)$(MAKE) $(build)=$(boot) $@
288
289 PHONY += install
290 install:
291         $(Q)$(MAKE) $(build)=$(boot) $@
292
293 PHONY += vdso_install
294 vdso_install:
295         $(Q)$(MAKE) $(build)=arch/x86/entry/vdso $@
296
297 archclean:
298         $(Q)rm -rf $(objtree)/arch/i386
299         $(Q)rm -rf $(objtree)/arch/x86_64
300         $(Q)$(MAKE) $(clean)=$(boot)
301         $(Q)$(MAKE) $(clean)=arch/x86/tools
302         $(Q)$(MAKE) $(clean)=arch/x86/purgatory
303
304 define archhelp
305   echo  '* bzImage      - Compressed kernel image (arch/x86/boot/bzImage)'
306   echo  '  install      - Install kernel using'
307   echo  '                  (your) ~/bin/$(INSTALLKERNEL) or'
308   echo  '                  (distribution) /sbin/$(INSTALLKERNEL) or'
309   echo  '                  install to $$(INSTALL_PATH) and run lilo'
310   echo  '  fdimage      - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)'
311   echo  '  fdimage144   - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)'
312   echo  '  fdimage288   - Create 2.8MB boot floppy image (arch/x86/boot/fdimage)'
313   echo  '  isoimage     - Create a boot CD-ROM image (arch/x86/boot/image.iso)'
314   echo  '                  bzdisk/fdimage*/isoimage also accept:'
315   echo  '                  FDARGS="..."  arguments for the booted kernel'
316   echo  '                  FDINITRD=file initrd for the booted kernel'
317 endef