blob: 68bcab6405a2e7b43ea48f92eeaa543bccc5d36b [file] [log] [blame]
Angel Pons118a9c72020-04-02 23:48:34 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin4de29d42015-09-03 22:49:36 -05002
3#include <memlayout.h>
4
5/* This file is included inside a SECTIONS block */
6
7/* First we place the code and read only data (typically const declared).
8 * This could theoretically be placed in rom.
Julius Werner52a92602015-09-11 16:17:50 -07009 * The '.' in '.text . : {' is actually significant to prevent missing some
10 * SoC's entry points due to artificial alignment restrictions, see
11 * https://sourceware.org/binutils/docs/ld/Output-Section-Address.html
Aaron Durbin4de29d42015-09-03 22:49:36 -050012 */
Julius Werner52a92602015-09-11 16:17:50 -070013.text . : {
Aaron Durbin4de29d42015-09-03 22:49:36 -050014 _program = .;
15 _text = .;
Kyösti Mälkki2289a702019-12-21 10:17:56 +020016#if !(ENV_X86 && ENV_BOOTBLOCK)
Kyösti Mälkki7522a8f2020-11-20 16:47:38 +020017 *(.init._start);
18 *(.init);
19 *(.init.*);
Kyösti Mälkki2289a702019-12-21 10:17:56 +020020#endif
Aaron Durbin4de29d42015-09-03 22:49:36 -050021 *(.text._start);
22 *(.text.stage_entry);
Julius Wernerfdabf3f2020-05-06 17:06:35 -070023 KEEP(*(.metadata_hash_anchor));
Aaron Durbin4de29d42015-09-03 22:49:36 -050024 *(.text);
25 *(.text.*);
26
Kyösti Mälkkifa3bc042022-03-31 07:40:10 +030027#if ENV_HAS_CBMEM
Aaron Durbin4de29d42015-09-03 22:49:36 -050028 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
29 _cbmem_init_hooks = .;
Julius Werner913a47a2021-05-20 17:00:46 -070030 KEEP(*(.rodata.cbmem_init_hooks_early));
Aaron Durbin4de29d42015-09-03 22:49:36 -050031 KEEP(*(.rodata.cbmem_init_hooks));
32 _ecbmem_init_hooks = .;
Julius Werner82d16b12020-12-30 15:51:10 -080033 RECORD_SIZE(cbmem_init_hooks)
Stefan Reinauerf6b10392016-05-20 15:17:17 -070034#endif
Lee Leahyefcee9f2016-04-29 17:26:36 -070035
36 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
37 _rsbe_init_begin = .;
38 KEEP(*(.rsbe_init));
39 _ersbe_init_begin = .;
Julius Werner82d16b12020-12-30 15:51:10 -080040 RECORD_SIZE(rsbe_init_begin)
Aaron Durbin4de29d42015-09-03 22:49:36 -050041
Aaron Durbin83bc0db2015-09-06 10:45:18 -050042#if ENV_RAMSTAGE
Aaron Durbin4de29d42015-09-03 22:49:36 -050043 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
44 _pci_drivers = .;
45 KEEP(*(.rodata.pci_driver));
46 _epci_drivers = .;
Julius Werner82d16b12020-12-30 15:51:10 -080047 RECORD_SIZE(pci_drivers)
Aaron Durbin4de29d42015-09-03 22:49:36 -050048 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
49 _cpu_drivers = .;
50 KEEP(*(.rodata.cpu_driver));
51 _ecpu_drivers = .;
Julius Werner82d16b12020-12-30 15:51:10 -080052 RECORD_SIZE(cpu_drivers)
Aaron Durbin4de29d42015-09-03 22:49:36 -050053#endif
54
55 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
56 *(.rodata);
57 *(.rodata.*);
58 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
59 _etext = .;
Julius Werner82d16b12020-12-30 15:51:10 -080060 RECORD_SIZE(text)
Aaron Durbin4de29d42015-09-03 22:49:36 -050061} : to_load
62
Harshit Sharma9c88fb82020-06-17 20:19:00 -070063#if ENV_RAMSTAGE && (CONFIG(COVERAGE) || CONFIG(ASAN_IN_RAMSTAGE))
Julius Werner52a92602015-09-11 16:17:50 -070064.ctors . : {
Patrick Georgi9cc8e922015-09-27 13:45:17 +020065 . = ALIGN(0x100);
Aaron Durbin4de29d42015-09-03 22:49:36 -050066 __CTOR_LIST__ = .;
67 KEEP(*(.ctors));
68 LONG(0);
69 LONG(0);
70 __CTOR_END__ = .;
71}
72#endif
73
74/* Include data, bss, and heap in that order. Not defined for all stages. */
Jeremy Compostellab7832de2023-08-30 15:42:09 -070075#if !ENV_SEPARATE_DATA_AND_BSS
Julius Werner52a92602015-09-11 16:17:50 -070076.data . : {
Aaron Durbin4de29d42015-09-03 22:49:36 -050077 . = ALIGN(ARCH_CACHELINE_ALIGN_SIZE);
78 _data = .;
Aaron Durbindde76292015-09-05 12:59:26 -050079
Aaron Durbin7f8afe02016-03-18 12:21:23 -050080/*
81 * The postcar phase uses a stack value that is located in the relocatable
82 * module section. While the postcar stage could be linked like smm and
83 * other rmodules the postcar stage needs similar semantics of the more
84 * traditional stages in the coreboot infrastructure. Therefore it's easier
85 * to specialize this case.
86 */
87#if ENV_RMODULE || ENV_POSTCAR
Aaron Durbindde76292015-09-05 12:59:26 -050088 _rmodule_params = .;
89 KEEP(*(.module_parameters));
90 _ermodule_params = .;
Julius Werner82d16b12020-12-30 15:51:10 -080091 RECORD_SIZE(rmodule_params)
Aaron Durbindde76292015-09-05 12:59:26 -050092#endif
93
Aaron Durbin4de29d42015-09-03 22:49:36 -050094 *(.data);
95 *(.data.*);
Aaron Durbin9a2790e2016-10-28 12:24:48 -050096 *(.sdata);
97 *(.sdata.*);
Aaron Durbin4de29d42015-09-03 22:49:36 -050098
Kyösti Mälkkie3acc8f2019-09-13 10:49:20 +030099#if ENV_ROMSTAGE_OR_BEFORE
Aaron Durbin4de29d42015-09-03 22:49:36 -0500100 PROVIDE(_preram_cbmem_console = .);
101 PROVIDE(_epreram_cbmem_console = _preram_cbmem_console);
Julius Werner82d16b12020-12-30 15:51:10 -0800102 PROVIDE(_preram_cbmem_console_size = ABSOLUTE(0));
Aaron Durbin83bc0db2015-09-06 10:45:18 -0500103#elif ENV_RAMSTAGE
Aaron Durbin4de29d42015-09-03 22:49:36 -0500104 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
105 _bs_init_begin = .;
106 KEEP(*(.bs_init));
107 LONG(0);
108 LONG(0);
109 _ebs_init_begin = .;
Julius Werner82d16b12020-12-30 15:51:10 -0800110 RECORD_SIZE(bs_init_begin)
Aaron Durbin4de29d42015-09-03 22:49:36 -0500111#endif
112
113 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
114 _edata = .;
Julius Werner82d16b12020-12-30 15:51:10 -0800115 RECORD_SIZE(data)
Aaron Durbin4de29d42015-09-03 22:49:36 -0500116}
117#endif
118
Jeremy Compostellab7832de2023-08-30 15:42:09 -0700119#if !ENV_SEPARATE_DATA_AND_BSS
Julius Werner52a92602015-09-11 16:17:50 -0700120.bss . : {
Aaron Durbin4de29d42015-09-03 22:49:36 -0500121 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
122 _bss = .;
123 *(.bss)
124 *(.bss.*)
125 *(.sbss)
126 *(.sbss.*)
127 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
128 _ebss = .;
Julius Werner82d16b12020-12-30 15:51:10 -0800129 RECORD_SIZE(bss)
Aaron Durbin4de29d42015-09-03 22:49:36 -0500130}
131#endif
132
Arthur Heymans6acc05e2022-05-12 18:01:13 +0200133#if ENV_HAS_HEAP_SECTION
Julius Werner52a92602015-09-11 16:17:50 -0700134.heap . : {
Aaron Durbin4de29d42015-09-03 22:49:36 -0500135 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
136 _heap = .;
Aaron Durbindde76292015-09-05 12:59:26 -0500137 . += (ENV_RMODULE ? __heap_size : CONFIG_HEAP_SIZE);
Aaron Durbin4de29d42015-09-03 22:49:36 -0500138 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
139 _eheap = .;
Julius Werner82d16b12020-12-30 15:51:10 -0800140 RECORD_SIZE(heap)
Aaron Durbin4de29d42015-09-03 22:49:36 -0500141}
142#endif
143
Harshit Sharma9c88fb82020-06-17 20:19:00 -0700144#if ENV_RAMSTAGE && CONFIG(ASAN_IN_RAMSTAGE)
145 _shadow_size = (_eheap - _data) >> 3;
146 REGION(asan_shadow, ., _shadow_size, ARCH_POINTER_ALIGN_SIZE)
147#endif
148
Aaron Durbin4de29d42015-09-03 22:49:36 -0500149_eprogram = .;
Julius Werner82d16b12020-12-30 15:51:10 -0800150RECORD_SIZE(program)
Aaron Durbin4de29d42015-09-03 22:49:36 -0500151
Patrick Georgied0647a2023-12-13 17:57:34 +0100152/* The stage cache drops CONFIG_HEAP_SIZE bytes from the end of the in-memory
153 image of the ramstage, so ensure that when moving that many bytes backwards
154 from the program end, we're in the heap (or later), in some region that
155 doesn't contain initialized code or data. */
156#if ENV_RAMSTAGE
157_bogus = ASSERT(_eprogram - CONFIG_HEAP_SIZE >= _heap,
158 "HEAP_SIZE and heap misaligned");
159#endif
160
Aaron Durbin4de29d42015-09-03 22:49:36 -0500161/* Discard the sections we don't need/want */
162
Patrick Georgifab8ae72016-04-13 20:55:34 +0200163zeroptr = 0;
Patrick Georgiff8076d2016-01-27 08:18:16 +0100164
Aaron Durbin4de29d42015-09-03 22:49:36 -0500165/DISCARD/ : {
166 *(.comment)
167 *(.comment.*)
168 *(.note)
169 *(.note.*)
170 *(.eh_frame);
171}