blob: b3ddc0b762bacb19b1d96cf7e45f3e0dd465aa8d [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 */
Arthur Heymans8406fb42024-04-05 09:00:06 +020013
14/* Starting with version 18 LLVM the combination -ffunction-section -mcmodel=large
15 * puts code and data in '.ltext, '.lrodata', '.ldata' and '.lbss'
16 */
17
Julius Werner52a92602015-09-11 16:17:50 -070018.text . : {
Aaron Durbin4de29d42015-09-03 22:49:36 -050019 _program = .;
20 _text = .;
Kyösti Mälkki2289a702019-12-21 10:17:56 +020021#if !(ENV_X86 && ENV_BOOTBLOCK)
Kyösti Mälkki7522a8f2020-11-20 16:47:38 +020022 *(.init._start);
23 *(.init);
24 *(.init.*);
Kyösti Mälkki2289a702019-12-21 10:17:56 +020025#endif
Aaron Durbin4de29d42015-09-03 22:49:36 -050026 *(.text._start);
27 *(.text.stage_entry);
Julius Wernerfdabf3f2020-05-06 17:06:35 -070028 KEEP(*(.metadata_hash_anchor));
Aaron Durbin4de29d42015-09-03 22:49:36 -050029 *(.text);
30 *(.text.*);
Arthur Heymans8406fb42024-04-05 09:00:06 +020031 *(.ltext);
32 *(.ltext.*);
Aaron Durbin4de29d42015-09-03 22:49:36 -050033
Kyösti Mälkkifa3bc042022-03-31 07:40:10 +030034#if ENV_HAS_CBMEM
Aaron Durbin4de29d42015-09-03 22:49:36 -050035 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
36 _cbmem_init_hooks = .;
Julius Werner913a47a2021-05-20 17:00:46 -070037 KEEP(*(.rodata.cbmem_init_hooks_early));
Aaron Durbin4de29d42015-09-03 22:49:36 -050038 KEEP(*(.rodata.cbmem_init_hooks));
39 _ecbmem_init_hooks = .;
Julius Werner82d16b12020-12-30 15:51:10 -080040 RECORD_SIZE(cbmem_init_hooks)
Stefan Reinauerf6b10392016-05-20 15:17:17 -070041#endif
Lee Leahyefcee9f2016-04-29 17:26:36 -070042
43 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
44 _rsbe_init_begin = .;
45 KEEP(*(.rsbe_init));
46 _ersbe_init_begin = .;
Julius Werner82d16b12020-12-30 15:51:10 -080047 RECORD_SIZE(rsbe_init_begin)
Aaron Durbin4de29d42015-09-03 22:49:36 -050048
Aaron Durbin83bc0db2015-09-06 10:45:18 -050049#if ENV_RAMSTAGE
Aaron Durbin4de29d42015-09-03 22:49:36 -050050 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
51 _pci_drivers = .;
52 KEEP(*(.rodata.pci_driver));
53 _epci_drivers = .;
Julius Werner82d16b12020-12-30 15:51:10 -080054 RECORD_SIZE(pci_drivers)
Aaron Durbin4de29d42015-09-03 22:49:36 -050055 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
56 _cpu_drivers = .;
57 KEEP(*(.rodata.cpu_driver));
58 _ecpu_drivers = .;
Julius Werner82d16b12020-12-30 15:51:10 -080059 RECORD_SIZE(cpu_drivers)
Aaron Durbin4de29d42015-09-03 22:49:36 -050060#endif
61
62 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
63 *(.rodata);
64 *(.rodata.*);
Arthur Heymans8406fb42024-04-05 09:00:06 +020065 *(.lrodata);
66 *(.lrodata.*);
Aaron Durbin4de29d42015-09-03 22:49:36 -050067 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
68 _etext = .;
Julius Werner82d16b12020-12-30 15:51:10 -080069 RECORD_SIZE(text)
Aaron Durbin4de29d42015-09-03 22:49:36 -050070} : to_load
71
Harshit Sharma9c88fb82020-06-17 20:19:00 -070072#if ENV_RAMSTAGE && (CONFIG(COVERAGE) || CONFIG(ASAN_IN_RAMSTAGE))
Julius Werner52a92602015-09-11 16:17:50 -070073.ctors . : {
Patrick Georgi9cc8e922015-09-27 13:45:17 +020074 . = ALIGN(0x100);
Aaron Durbin4de29d42015-09-03 22:49:36 -050075 __CTOR_LIST__ = .;
76 KEEP(*(.ctors));
77 LONG(0);
78 LONG(0);
79 __CTOR_END__ = .;
Arthur Heymans67166a72024-02-29 15:05:15 +010080} : to_load
Aaron Durbin4de29d42015-09-03 22:49:36 -050081#endif
82
83/* Include data, bss, and heap in that order. Not defined for all stages. */
Jeremy Compostellab7832de2023-08-30 15:42:09 -070084#if !ENV_SEPARATE_DATA_AND_BSS
Julius Werner52a92602015-09-11 16:17:50 -070085.data . : {
Aaron Durbin4de29d42015-09-03 22:49:36 -050086 . = ALIGN(ARCH_CACHELINE_ALIGN_SIZE);
87 _data = .;
Aaron Durbindde76292015-09-05 12:59:26 -050088
Aaron Durbin7f8afe02016-03-18 12:21:23 -050089/*
90 * The postcar phase uses a stack value that is located in the relocatable
91 * module section. While the postcar stage could be linked like smm and
92 * other rmodules the postcar stage needs similar semantics of the more
93 * traditional stages in the coreboot infrastructure. Therefore it's easier
94 * to specialize this case.
95 */
96#if ENV_RMODULE || ENV_POSTCAR
Aaron Durbindde76292015-09-05 12:59:26 -050097 _rmodule_params = .;
98 KEEP(*(.module_parameters));
99 _ermodule_params = .;
Julius Werner82d16b12020-12-30 15:51:10 -0800100 RECORD_SIZE(rmodule_params)
Aaron Durbindde76292015-09-05 12:59:26 -0500101#endif
102
Aaron Durbin4de29d42015-09-03 22:49:36 -0500103 *(.data);
104 *(.data.*);
Arthur Heymans8406fb42024-04-05 09:00:06 +0200105 *(.ldata);
106 *(.ldata.*);
Aaron Durbin9a2790e2016-10-28 12:24:48 -0500107 *(.sdata);
108 *(.sdata.*);
Aaron Durbin4de29d42015-09-03 22:49:36 -0500109
Kyösti Mälkkie3acc8f2019-09-13 10:49:20 +0300110#if ENV_ROMSTAGE_OR_BEFORE
Aaron Durbin4de29d42015-09-03 22:49:36 -0500111 PROVIDE(_preram_cbmem_console = .);
112 PROVIDE(_epreram_cbmem_console = _preram_cbmem_console);
Julius Werner82d16b12020-12-30 15:51:10 -0800113 PROVIDE(_preram_cbmem_console_size = ABSOLUTE(0));
Aaron Durbin83bc0db2015-09-06 10:45:18 -0500114#elif ENV_RAMSTAGE
Aaron Durbin4de29d42015-09-03 22:49:36 -0500115 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
116 _bs_init_begin = .;
117 KEEP(*(.bs_init));
118 LONG(0);
119 LONG(0);
120 _ebs_init_begin = .;
Julius Werner82d16b12020-12-30 15:51:10 -0800121 RECORD_SIZE(bs_init_begin)
Aaron Durbin4de29d42015-09-03 22:49:36 -0500122#endif
123
124 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
125 _edata = .;
Julius Werner82d16b12020-12-30 15:51:10 -0800126 RECORD_SIZE(data)
Arthur Heymans67166a72024-02-29 15:05:15 +0100127} : to_load
Aaron Durbin4de29d42015-09-03 22:49:36 -0500128#endif
129
Jeremy Compostellab7832de2023-08-30 15:42:09 -0700130#if !ENV_SEPARATE_DATA_AND_BSS
Arthur Heymans67166a72024-02-29 15:05:15 +0100131.bss . (NOLOAD) : {
Aaron Durbin4de29d42015-09-03 22:49:36 -0500132 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
133 _bss = .;
134 *(.bss)
135 *(.bss.*)
Arthur Heymans8406fb42024-04-05 09:00:06 +0200136 *(.lbss)
137 *(.lbss.*)
Aaron Durbin4de29d42015-09-03 22:49:36 -0500138 *(.sbss)
139 *(.sbss.*)
140 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
141 _ebss = .;
Julius Werner82d16b12020-12-30 15:51:10 -0800142 RECORD_SIZE(bss)
Arthur Heymans67166a72024-02-29 15:05:15 +0100143} : to_load
Aaron Durbin4de29d42015-09-03 22:49:36 -0500144#endif
145
Arthur Heymans6acc05e2022-05-12 18:01:13 +0200146#if ENV_HAS_HEAP_SECTION
Arthur Heymans67166a72024-02-29 15:05:15 +0100147.heap . (NOLOAD) : {
Aaron Durbin4de29d42015-09-03 22:49:36 -0500148 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
149 _heap = .;
Arthur Heymans7fbef1b2024-02-22 15:01:04 +0100150 . += CONFIG_HEAP_SIZE;
Aaron Durbin4de29d42015-09-03 22:49:36 -0500151 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
152 _eheap = .;
Julius Werner82d16b12020-12-30 15:51:10 -0800153 RECORD_SIZE(heap)
Arthur Heymans67166a72024-02-29 15:05:15 +0100154} : to_load
Aaron Durbin4de29d42015-09-03 22:49:36 -0500155#endif
156
Harshit Sharma9c88fb82020-06-17 20:19:00 -0700157#if ENV_RAMSTAGE && CONFIG(ASAN_IN_RAMSTAGE)
158 _shadow_size = (_eheap - _data) >> 3;
159 REGION(asan_shadow, ., _shadow_size, ARCH_POINTER_ALIGN_SIZE)
160#endif
161
Aaron Durbin4de29d42015-09-03 22:49:36 -0500162_eprogram = .;
Julius Werner82d16b12020-12-30 15:51:10 -0800163RECORD_SIZE(program)
Aaron Durbin4de29d42015-09-03 22:49:36 -0500164
Patrick Georgied0647a2023-12-13 17:57:34 +0100165/* The stage cache drops CONFIG_HEAP_SIZE bytes from the end of the in-memory
166 image of the ramstage, so ensure that when moving that many bytes backwards
167 from the program end, we're in the heap (or later), in some region that
168 doesn't contain initialized code or data. */
169#if ENV_RAMSTAGE
170_bogus = ASSERT(_eprogram - CONFIG_HEAP_SIZE >= _heap,
171 "HEAP_SIZE and heap misaligned");
172#endif
173
Aaron Durbin4de29d42015-09-03 22:49:36 -0500174/* Discard the sections we don't need/want */
175
Patrick Georgifab8ae72016-04-13 20:55:34 +0200176zeroptr = 0;
Patrick Georgiff8076d2016-01-27 08:18:16 +0100177
Aaron Durbin4de29d42015-09-03 22:49:36 -0500178/DISCARD/ : {
179 *(.comment)
180 *(.comment.*)
181 *(.note)
182 *(.note.*)
183 *(.eh_frame);
184}