1# SPDX-License-Identifier: GPL-2.0+
2#
3# (C) Copyright 2000-2002
4# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5
6CONFIG_STANDALONE_LOAD_ADDR ?= 0x40000
7
8PLATFORM_CPPFLAGS += -fomit-frame-pointer
9PF_CPPFLAGS_X86   := $(call cc-option, -fno-toplevel-reorder, \
10		     $(call cc-option, -fno-unit-at-a-time))
11
12PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_X86)
13PLATFORM_CPPFLAGS += -fno-dwarf2-cfi-asm
14
15ifdef CONFIG_SPL_BUILD
16IS_32BIT := y
17else
18ifndef CONFIG_X86_64
19IS_32BIT := y
20endif
21endif
22
23ifeq ($(IS_32BIT),y)
24PLATFORM_CPPFLAGS += -march=i386 -m32
25else
26PLATFORM_CPPFLAGS += $(if $(CONFIG_SPL_BUILD),,-fpic) -fno-common -march=core2 -m64
27PLATFORM_CPPFLAGS += -mno-mmx -mno-sse
28endif
29
30PLATFORM_RELFLAGS += -fdata-sections -ffunction-sections -fvisibility=hidden
31
32KBUILD_LDFLAGS += -Bsymbolic -Bsymbolic-functions
33KBUILD_LDFLAGS += -m $(if $(IS_32BIT),elf_i386,elf_x86_64)
34
35# This is used in the top-level Makefile which does not include
36# KBUILD_LDFLAGS
37LDFLAGS_EFI_PAYLOAD := -Bsymbolic -Bsymbolic-functions -shared --no-undefined -s
38
39OBJCOPYFLAGS_EFI := -j .text -j .sdata -j .data -j .dynamic -j .dynsym \
40	-j .rel -j .rela -j .reloc
41
42# Compiler flags to be added when building UEFI applications
43CFLAGS_EFI := -fpic -fshort-wchar
44# Compiler flags to be removed when building UEFI applications
45CFLAGS_NON_EFI := -mregparm=3 -fstack-protector-strong
46
47ifeq ($(CONFIG_EFI_STUB_64BIT),)
48CFLAGS_EFI += $(call cc-option, -mno-red-zone)
49EFIARCH = ia32
50EFIPAYLOAD_BFDTARGET = elf32-i386
51else
52EFIARCH = x86_64
53EFIPAYLOAD_BFDTARGET = elf64-x86-64
54endif
55
56EFIPAYLOAD_BFDARCH = i386
57
58LDSCRIPT_EFI := $(srctree)/arch/x86/lib/elf_$(EFIARCH)_efi.lds
59EFISTUB := crt0_$(EFIARCH)_efi.o reloc_$(EFIARCH)_efi.o
60OBJCOPYFLAGS_EFI += --target=efi-app-$(EFIARCH)
61
62CPPFLAGS_REMOVE_crt0-efi-$(EFIARCH).o += $(CFLAGS_NON_EFI)
63CPPFLAGS_crt0-efi-$(EFIARCH).o += $(CFLAGS_EFI)
64
65ifeq ($(CONFIG_EFI_APP),y)
66
67PLATFORM_CPPFLAGS += $(CFLAGS_EFI)
68LDFLAGS_FINAL += -znocombreloc -shared -s
69LDSCRIPT := $(LDSCRIPT_EFI)
70
71else
72
73ifeq ($(IS_32BIT),y)
74PLATFORM_CPPFLAGS += -mregparm=3
75endif
76KBUILD_LDFLAGS += --emit-relocs
77LDFLAGS_FINAL += --gc-sections $(if $(CONFIG_SPL_BUILD),,-pie)
78
79endif
80
81ifdef CONFIG_X86_64
82ifndef CONFIG_SPL_BUILD
83PLATFORM_CPPFLAGS += -D__x86_64__
84else
85PLATFORM_CPPFLAGS += -D__I386__
86endif
87else
88PLATFORM_CPPFLAGS += -D__I386__
89endif
90
91ifdef CONFIG_EFI_STUB
92
93ifdef CONFIG_EFI_STUB_64BIT
94EFI_LDS := elf_x86_64_efi.lds
95EFI_CRT0 := crt0_x86_64_efi.o
96EFI_RELOC := reloc_x86_64_efi.o
97else
98EFI_LDS := elf_ia32_efi.lds
99EFI_CRT0 := crt0_ia32_efi.o
100EFI_RELOC := reloc_ia32_efi.o
101endif
102
103else
104
105ifdef CONFIG_X86_64
106EFI_LDS := elf_x86_64_efi.lds
107EFI_CRT0 := crt0_x86_64_efi.o
108EFI_RELOC := reloc_x86_64_efi.o
109else
110EFI_LDS := elf_ia32_efi.lds
111EFI_CRT0 := crt0_ia32_efi.o
112EFI_RELOC := reloc_ia32_efi.o
113endif
114
115endif
116
117ifdef CONFIG_X86_64
118EFI_TARGET := --target=efi-app-x86_64
119else
120EFI_TARGET := --target=efi-app-ia32
121endif
122