xref: /aosp_15_r20/external/coreboot/src/arch/x86/Makefile.mk (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1## SPDX-License-Identifier: GPL-2.0-only
2
3ifeq ($(CONFIG_POSTCAR_STAGE),y)
4$(eval $(call init_standard_toolchain,postcar))
5endif
6
7################################################################################
8# i386 specific tools
9NVRAMTOOL:=$(objutil)/nvramtool/nvramtool
10
11OPTION_TABLE_H:=
12ifeq ($(CONFIG_HAVE_OPTION_TABLE),y)
13
14CMOS_LAYOUT_FILE := $(top)/$(call strip_quotes,$(CONFIG_CMOS_LAYOUT_FILE))
15
16cbfs-files-y += cmos_layout.bin
17cmos_layout.bin-file = $(obj)/cmos_layout.bin
18cmos_layout.bin-type = cmos_layout
19
20$(obj)/cmos_layout.bin: $(NVRAMTOOL) $(CMOS_LAYOUT_FILE)
21	@printf "    OPTION     $(subst $(obj)/,,$(@))\n"
22	$(NVRAMTOOL) -y $(CMOS_LAYOUT_FILE) -L $@
23
24OPTION_TABLE_H:=$(obj)/option_table.h
25
26$(OPTION_TABLE_H): $(NVRAMTOOL) $(CMOS_LAYOUT_FILE)
27	@printf "    OPTION     $(subst $(obj)/,,$(@))\n"
28	$(NVRAMTOOL) -y $(CMOS_LAYOUT_FILE) -H $@
29endif # CONFIG_HAVE_OPTION_TABLE
30
31stripped_vgabios_id = $(call strip_quotes,$(CONFIG_VGA_BIOS_ID))
32cbfs-files-$(CONFIG_VGA_BIOS) += pci$(stripped_vgabios_id).rom
33pci$(stripped_vgabios_id).rom-file := $(call strip_quotes,$(CONFIG_VGA_BIOS_FILE))
34pci$(stripped_vgabios_id).rom-type := optionrom
35
36stripped_second_vbios_id = $(call strip_quotes,$(CONFIG_VGA_BIOS_SECOND_ID))
37cbfs-files-$(CONFIG_VGA_BIOS_SECOND) += pci$(stripped_second_vbios_id).rom
38pci$(stripped_second_vbios_id).rom-file := $(call strip_quotes,$(CONFIG_VGA_BIOS_SECOND_FILE))
39pci$(stripped_second_vbios_id).rom-type := optionrom
40
41stripped_vgabios_dgpu_id = $(call strip_quotes,$(CONFIG_VGA_BIOS_DGPU_ID))
42cbfs-files-$(CONFIG_VGA_BIOS_DGPU) += pci$(stripped_vgabios_dgpu_id).rom
43pci$(stripped_vgabios_dgpu_id).rom-file := $(call strip_quotes,$(CONFIG_VGA_BIOS_DGPU_FILE))
44pci$(stripped_vgabios_dgpu_id).rom-type := optionrom
45
46# The AMD LPC SPI DMA controller requires source files to be 64 byte aligned.
47ifeq ($(CONFIG_SOC_AMD_COMMON_BLOCK_LPC_SPI_DMA),y)
48pci$(stripped_vgabios_id).rom-align := 64
49pci$(stripped_second_vbios_id).rom-align := 64
50pci$(stripped_vgabios_dgpu_id).rom-align := 64
51endif # CONFIG_SOC_AMD_COMMON_BLOCK_LPC_SPI_DMA
52
53###############################################################################
54# common support for early assembly includes
55###############################################################################
56
57define early_x86_stage
58# $1 stage name
59# $2 oformat
60
61# The '.' include path is needed for the generated assembly.inc file.
62$(1)-S-ccopts += -I.
63
64$$(objcbfs)/$(1).debug: $$$$($(1)-libs) $$$$($(1)-objs)
65	@printf "    LINK       $$(subst $$(obj)/,,$$(@))\n"
66	$$(LD_$(1)) $$(LDFLAGS_$(1)) -o $$@ -L$$(obj) $$(COMPILER_RT_FLAGS_$(1)) --whole-archive --start-group $$(filter-out %.ld,$$($(1)-objs)) $$($(1)-libs) --no-whole-archive $$(COMPILER_RT_$(1)) --end-group -T $(call src-to-obj,$(1),$(CONFIG_MEMLAYOUT_LD_FILE)) --oformat $(2)
67endef
68
69###############################################################################
70# bootblock
71###############################################################################
72
73ifeq ($(CONFIG_ARCH_BOOTBLOCK_X86_32)$(CONFIG_ARCH_BOOTBLOCK_X86_64),y)
74
75bootblock-y += boot.c
76bootblock-$(CONFIG_DEBUG_HW_BREAKPOINTS_IN_ALL_STAGES) += breakpoint.c
77bootblock-y += post.c
78bootblock-y += cpu_common.c
79bootblock-$(CONFIG_IDT_IN_EVERY_STAGE) += exception.c
80bootblock-$(CONFIG_IDT_IN_EVERY_STAGE) += idt.S
81bootblock-y += memcpy.c
82bootblock-y += memset.c
83bootblock-$(CONFIG_ARCH_BOOTBLOCK_X86_32) += memmove_32.c
84bootblock-$(CONFIG_ARCH_BOOTBLOCK_X86_64) += memmove_64.S
85bootblock-$(CONFIG_COLLECT_TIMESTAMPS_TSC) += timestamp.c
86bootblock-$(CONFIG_X86_TOP4G_BOOTMEDIA_MAP) += mmap_boot.c
87bootblock-$(CONFIG_DEBUG_NULL_DEREF_BREAKPOINTS_IN_ALL_STAGES) += null_breakpoint.c
88bootblock-$(CONFIG_BOOTBLOCK_NORMAL) += bootblock_normal.c
89bootblock-y += gdt_init.S
90bootblock-y += id.S
91bootblock-$(CONFIG_HAVE_CF9_RESET) += cf9_reset.c
92bootblock-y += bootblock.ld
93bootblock-y += car.ld
94
95$(call src-to-obj,bootblock,$(dir)/id.S): $(obj)/build.h
96
97ifeq ($(CONFIG_ARCH_BOOTBLOCK_X86_32),y)
98$(eval $(call early_x86_stage,bootblock,elf32-i386))
99else
100$(eval $(call early_x86_stage,bootblock,elf64-x86-64))
101endif
102
103ifeq ($(CONFIG_BOOTBLOCK_IN_CBFS),y)
104add_bootblock = \
105	$(CBFSTOOL) $(1) add -f $(2) -n bootblock -t bootblock $(TXTIBB) \
106	-b -$(call file-size,$(2)) \
107	$(cbfs-autogen-attributes) $(TS_OPTIONS) $(CBFSTOOL_ADD_CMD_OPTIONS)
108endif
109
110ifneq ($(CONFIG_CBFS_VERIFICATION),y)
111$(call src-to-obj,bootblock,$(dir)/walkcbfs.S): $(obj)/fmap_config.h
112bootblock-y += walkcbfs.S
113endif
114
115endif # CONFIG_ARCH_BOOTBLOCK_X86_32 / CONFIG_ARCH_BOOTBLOCK_X86_64
116
117###############################################################################
118# verstage
119###############################################################################
120
121ifeq ($(CONFIG_ARCH_VERSTAGE_X86_32)$(CONFIG_ARCH_VERSTAGE_X86_64),y)
122
123verstage-$(CONFIG_VBOOT_SEPARATE_VERSTAGE) += assembly_entry.S
124verstage-y += boot.c
125verstage-$(CONFIG_DEBUG_HW_BREAKPOINTS_IN_ALL_STAGES) += breakpoint.c
126verstage-y += post.c
127verstage-$(CONFIG_VBOOT_SEPARATE_VERSTAGE) += gdt_init.S
128verstage-$(CONFIG_IDT_IN_EVERY_STAGE) += exception.c
129verstage-$(CONFIG_IDT_IN_EVERY_STAGE) += idt.S
130verstage-$(CONFIG_HAVE_CF9_RESET) += cf9_reset.c
131
132verstage-y += cpu_common.c
133verstage-y += memset.c
134verstage-y += memcpy.c
135verstage-$(CONFIG_ARCH_VERSTAGE_X86_32) += memmove_32.c
136verstage-$(CONFIG_ARCH_VERSTAGE_X86_64) += memmove_64.S
137verstage-$(CONFIG_X86_TOP4G_BOOTMEDIA_MAP) += mmap_boot.c
138verstage-$(CONFIG_DEBUG_NULL_DEREF_BREAKPOINTS_IN_ALL_STAGES) += null_breakpoint.c
139# If verstage is a separate stage it means there's no need
140# for a chipset-specific car_stage_entry() so use the generic one
141# which just calls verstage().
142verstage-$(CONFIG_VBOOT_SEPARATE_VERSTAGE) += verstage.c
143
144verstage-$(CONFIG_COLLECT_TIMESTAMPS_TSC) += timestamp.c
145
146verstage-y += car.ld
147
148verstage-libs ?=
149
150ifeq ($(CONFIG_ARCH_VERSTAGE_X86_32),y)
151$(eval $(call early_x86_stage,verstage,elf32-i386))
152else
153$(eval $(call early_x86_stage,verstage,elf64-x86-64))
154endif
155
156endif # CONFIG_ARCH_VERSTAGE_X86_32 / CONFIG_ARCH_VERSTAGE_X86_64
157
158###############################################################################
159# romstage
160###############################################################################
161
162ifeq ($(CONFIG_ARCH_ROMSTAGE_X86_32)$(CONFIG_ARCH_ROMSTAGE_X86_64),y)
163
164romstage-$(CONFIG_SEPARATE_ROMSTAGE) += assembly_entry.S
165romstage-$(CONFIG_SEPARATE_ROMSTAGE) += romstage.c
166romstage-y += boot.c
167romstage-$(CONFIG_DEBUG_HW_BREAKPOINTS_IN_ALL_STAGES) += breakpoint.c
168romstage-y += post.c
169romstage-$(CONFIG_SEPARATE_ROMSTAGE) += gdt_init.S
170romstage-y += cpu_common.c
171romstage-$(CONFIG_IDT_IN_EVERY_STAGE) += exception.c
172romstage-$(CONFIG_IDT_IN_EVERY_STAGE) += idt.S
173romstage-y += memcpy.c
174romstage-$(CONFIG_ARCH_ROMSTAGE_X86_32) += memmove_32.c
175romstage-$(CONFIG_ARCH_ROMSTAGE_X86_64) += memmove_64.S
176romstage-y += memset.c
177romstage-$(CONFIG_X86_TOP4G_BOOTMEDIA_MAP) += mmap_boot.c
178romstage-$(CONFIG_DEBUG_NULL_DEREF_BREAKPOINTS_IN_ALL_STAGES) += null_breakpoint.c
179romstage-y += postcar_loader.c
180romstage-$(CONFIG_COLLECT_TIMESTAMPS_TSC) += timestamp.c
181romstage-$(CONFIG_HAVE_CF9_RESET) += cf9_reset.c
182romstage-$(CONFIG_COOP_MULTITASKING) += thread.c
183romstage-$(CONFIG_COOP_MULTITASKING) += thread_switch.S
184romstage-y += car.ld
185
186romstage-srcs += $(wildcard $(src)/mainboard/$(MAINBOARDDIR)/romstage.c)
187romstage-libs ?=
188
189ifeq ($(CONFIG_ARCH_ROMSTAGE_X86_32),y)
190$(eval $(call early_x86_stage,romstage,elf32-i386))
191else
192$(eval $(call early_x86_stage,romstage,elf64-x86-64))
193endif
194
195# Compiling crt0 with -g seems to trigger https://sourceware.org/bugzilla/show_bug.cgi?id=6428
196romstage-S-ccopts += -g0
197
198endif # CONFIG_ARCH_ROMSTAGE_X86_32 / CONFIG_ARCH_ROMSTAGE_X86_64
199
200###############################################################################
201# postcar
202###############################################################################
203
204ifeq ($(CONFIG_ARCH_POSTCAR_X86_32),y)
205$(eval $(call create_class_compiler,postcar,x86_32))
206else
207$(eval $(call create_class_compiler,postcar,x86_64))
208endif
209postcar-generic-ccopts += -D__POSTCAR__
210
211postcar-y += boot.c
212postcar-$(CONFIG_DEBUG_HW_BREAKPOINTS_IN_ALL_STAGES) += breakpoint.c
213postcar-y += post.c
214postcar-y += gdt_init.S
215postcar-y += cpu_common.c
216postcar-$(CONFIG_IDT_IN_EVERY_STAGE) += exception.c
217postcar-$(CONFIG_IDT_IN_EVERY_STAGE) += idt.S
218postcar-y += exit_car.S
219postcar-y += memcpy.c
220postcar-$(CONFIG_ARCH_POSTCAR_X86_32) += memmove_32.c
221postcar-$(CONFIG_ARCH_POSTCAR_X86_64) += memmove_64.S
222postcar-y += memset.c
223postcar-$(CONFIG_X86_TOP4G_BOOTMEDIA_MAP) += mmap_boot.c
224postcar-$(CONFIG_DEBUG_NULL_DEREF_BREAKPOINTS_IN_ALL_STAGES) += null_breakpoint.c
225postcar-y += postcar.c
226postcar-$(CONFIG_COLLECT_TIMESTAMPS_TSC) += timestamp.c
227postcar-$(CONFIG_HAVE_CF9_RESET) += cf9_reset.c
228
229LDFLAGS_postcar += -Map $(objcbfs)/postcar.map
230
231$(objcbfs)/postcar.debug: $$(postcar-objs)
232	@printf "    LINK       $(subst $(obj)/,,$(@))\n"
233	$(LD_postcar) $(LDFLAGS_postcar) -o $@ -L$(obj) $(COMPILER_RT_FLAGS_postcar) --whole-archive --start-group $(filter-out %.ld,$^) --no-whole-archive $(COMPILER_RT_postcar) --end-group -T $(call src-to-obj,postcar,$(CONFIG_MEMLAYOUT_LD_FILE))
234
235$(objcbfs)/postcar.elf: $(objcbfs)/postcar.debug.rmod
236	cp $< $@
237
238# Add postcar to CBFS
239cbfs-files-$(CONFIG_POSTCAR_STAGE)  += $(CONFIG_CBFS_PREFIX)/postcar
240$(CONFIG_CBFS_PREFIX)/postcar-file := $(objcbfs)/postcar.elf
241$(CONFIG_CBFS_PREFIX)/postcar-type := stage
242$(CONFIG_CBFS_PREFIX)/postcar-compression := none
243
244###############################################################################
245# ramstage
246###############################################################################
247
248ifeq ($(CONFIG_ARCH_RAMSTAGE_X86_32)$(CONFIG_ARCH_RAMSTAGE_X86_64),y)
249
250ramstage-y += acpi.c
251ramstage-$(CONFIG_HAVE_ACPI_RESUME) += acpi_s3.c
252ramstage-$(CONFIG_ACPI_BERT) += acpi_bert_storage.c
253ramstage-y += boot.c
254ramstage-y += post.c
255ramstage-y += c_start.S
256ramstage-y += cpu.c
257ramstage-y += cpu_common.c
258ramstage-$(CONFIG_DEBUG_HW_BREAKPOINTS) += breakpoint.c
259ramstage-y += ebda.c
260ramstage-y += exception.c
261ramstage-y += idt.S
262ramstage-$(CONFIG_IOAPIC) += ioapic.c
263ramstage-y += dma.c
264ramstage-y += memcpy.c
265ramstage-$(CONFIG_ARCH_RAMSTAGE_X86_32) += memmove_32.c
266ramstage-$(CONFIG_ARCH_RAMSTAGE_X86_64) += memmove_64.S
267ramstage-y += memset.c
268ramstage-$(CONFIG_X86_TOP4G_BOOTMEDIA_MAP) += mmap_boot.c
269ramstage-$(CONFIG_GENERATE_MP_TABLE) += mpspec.c
270ramstage-$(CONFIG_DEBUG_NULL_DEREF_BREAKPOINTS) += null_breakpoint.c
271ramstage-$(CONFIG_GENERATE_PIRQ_TABLE) += pirq_routing.c
272ramstage-y += rdrand.c
273ramstage-$(CONFIG_GENERATE_SMBIOS_TABLES) += smbios.c
274ramstage-y += tables.c
275ramstage-$(CONFIG_COOP_MULTITASKING) += thread.c
276ramstage-$(CONFIG_COOP_MULTITASKING) += thread_switch.S
277ramstage-$(CONFIG_COLLECT_TIMESTAMPS_TSC) += timestamp.c
278ramstage-$(CONFIG_HAVE_ACPI_RESUME) += wakeup.S
279ramstage-$(CONFIG_HAVE_CF9_RESET) += cf9_reset.c
280
281rmodules_x86_32-y += memcpy.c
282rmodules_x86_32-y += memmove_32.c
283rmodules_x86_32-y += memset.c
284
285rmodules_x86_64-y += memcpy.c
286rmodules_x86_64-y += memmove_64.S
287rmodules_x86_64-y += memset.c
288
289ifeq ($(CONFIG_ARCH_RAMSTAGE_X86_32),y)
290target-objcopy=-O elf32-i386 -B i386
291LD_MACHINE =-m elf_i386
292endif
293ifeq ($(CONFIG_ARCH_RAMSTAGE_X86_64),y)
294target-objcopy=-O elf64-x86-64 -B i386:x86-64
295LD_MACHINE =-m elf_x86_64
296endif
297
298# Make sure generated code does not use XMMx and MMx registers
299CFLAGS_x86_32 += -mno-mmx -mno-sse
300CFLAGS_x86_64 += -mno-mmx -mno-sse
301
302ramstage-srcs += $(wildcard src/mainboard/$(MAINBOARDDIR)/mainboard.c)
303ifeq ($(CONFIG_GENERATE_MP_TABLE),y)
304ifneq ($(wildcard src/mainboard/$(MAINBOARDDIR)/mptable.c),)
305ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/mptable.c
306endif
307endif
308ifeq ($(CONFIG_GENERATE_PIRQ_TABLE),y)
309ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/irq_tables.c
310endif
311
312ramstage-libs ?=
313
314# The rmodule_link definition creates an elf file with .rmod extension.
315$(objcbfs)/ramstage.elf: $(objcbfs)/ramstage.debug.rmod
316	cp $< $@
317
318$(objcbfs)/ramstage.debug: $(objgenerated)/ramstage.o $(call src-to-obj,ramstage,$(CONFIG_MEMLAYOUT_LD_FILE))
319	@printf "    CC         $(subst $(obj)/,,$(@))\n"
320	$(LD_ramstage) $(LDFLAGS_ramstage) -o $@ -L$(obj) $< -T $(call src-to-obj,ramstage,$(CONFIG_MEMLAYOUT_LD_FILE))
321
322$(objgenerated)/ramstage.o: $$(ramstage-objs) $(COMPILER_RT_ramstage) $$(ramstage-libs)
323	@printf "    CC         $(subst $(obj)/,,$(@))\n"
324	$(LD_ramstage) $(LD_MACHINE) -r -o $@ $(COMPILER_RT_FLAGS_ramstage) --whole-archive --start-group $(filter-out %.ld,$(ramstage-objs)) $(ramstage-libs) --no-whole-archive $(COMPILER_RT_ramstage) --end-group
325
326endif # CONFIG_ARCH_RAMSTAGE_X86_32 / CONFIG_ARCH_RAMSTAGE_X86_64
327
328smm-$(CONFIG_DEBUG_HW_BREAKPOINTS_IN_ALL_STAGES) += breakpoint.c
329smm-$(CONFIG_IDT_IN_EVERY_STAGE) += exception.c
330smm-$(CONFIG_IDT_IN_EVERY_STAGE) += idt.S
331smm-y += memcpy.c
332smm-$(CONFIG_ARCH_RAMSTAGE_X86_32) += memmove_32.c
333smm-$(CONFIG_ARCH_RAMSTAGE_X86_64) += memmove_64.S
334smm-y += memset.c
335smm-$(CONFIG_X86_TOP4G_BOOTMEDIA_MAP) += mmap_boot.c
336smm-$(CONFIG_DEBUG_NULL_DEREF_BREAKPOINTS_IN_ALL_STAGES) += null_breakpoint.c
337
338smm-srcs += $(wildcard src/mainboard/$(MAINBOARDDIR)/smihandler.c)
339
340ifneq ($(CONFIG_HAVE_CONFIGURABLE_APMC_SMI_PORT),y)
341ramstage-y += apmc_smi_port.c
342smm-y += apmc_smi_port.c
343endif
344