blob: 8180d9f1dcd4a694ae560de4e80558049bda9bb0 [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
Aaron Durbin1e9a9142016-09-16 16:23:21 -050027#if ENV_RAMSTAGE || ENV_ROMSTAGE || ENV_POSTCAR
Aaron Durbin4de29d42015-09-03 22:49:36 -050028 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
29 _cbmem_init_hooks = .;
30 KEEP(*(.rodata.cbmem_init_hooks));
31 _ecbmem_init_hooks = .;
Julius Werner82d16b12020-12-30 15:51:10 -080032 RECORD_SIZE(cbmem_init_hooks)
Stefan Reinauerf6b10392016-05-20 15:17:17 -070033#endif
Lee Leahyefcee9f2016-04-29 17:26:36 -070034
35 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
36 _rsbe_init_begin = .;
37 KEEP(*(.rsbe_init));
38 _ersbe_init_begin = .;
Julius Werner82d16b12020-12-30 15:51:10 -080039 RECORD_SIZE(rsbe_init_begin)
Aaron Durbin4de29d42015-09-03 22:49:36 -050040
Aaron Durbin83bc0db2015-09-06 10:45:18 -050041#if ENV_RAMSTAGE
Aaron Durbin4de29d42015-09-03 22:49:36 -050042 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
43 _pci_drivers = .;
44 KEEP(*(.rodata.pci_driver));
45 _epci_drivers = .;
Julius Werner82d16b12020-12-30 15:51:10 -080046 RECORD_SIZE(pci_drivers)
Aaron Durbin4de29d42015-09-03 22:49:36 -050047 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
48 _cpu_drivers = .;
49 KEEP(*(.rodata.cpu_driver));
50 _ecpu_drivers = .;
Julius Werner82d16b12020-12-30 15:51:10 -080051 RECORD_SIZE(cpu_drivers)
Aaron Durbin4de29d42015-09-03 22:49:36 -050052#endif
53
54 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
55 *(.rodata);
56 *(.rodata.*);
57 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
58 _etext = .;
Julius Werner82d16b12020-12-30 15:51:10 -080059 RECORD_SIZE(text)
Aaron Durbin4de29d42015-09-03 22:49:36 -050060} : to_load
61
Harshit Sharma9c88fb82020-06-17 20:19:00 -070062#if ENV_RAMSTAGE && (CONFIG(COVERAGE) || CONFIG(ASAN_IN_RAMSTAGE))
Julius Werner52a92602015-09-11 16:17:50 -070063.ctors . : {
Patrick Georgi9cc8e922015-09-27 13:45:17 +020064 . = ALIGN(0x100);
Aaron Durbin4de29d42015-09-03 22:49:36 -050065 __CTOR_LIST__ = .;
66 KEEP(*(.ctors));
67 LONG(0);
68 LONG(0);
69 __CTOR_END__ = .;
70}
71#endif
72
73/* Include data, bss, and heap in that order. Not defined for all stages. */
Kyösti Mälkkif2cc52b2019-08-21 07:15:38 +030074#if ENV_STAGE_HAS_DATA_SECTION
Julius Werner52a92602015-09-11 16:17:50 -070075.data . : {
Aaron Durbin4de29d42015-09-03 22:49:36 -050076 . = ALIGN(ARCH_CACHELINE_ALIGN_SIZE);
77 _data = .;
Aaron Durbindde76292015-09-05 12:59:26 -050078
Aaron Durbin7f8afe02016-03-18 12:21:23 -050079/*
80 * The postcar phase uses a stack value that is located in the relocatable
81 * module section. While the postcar stage could be linked like smm and
82 * other rmodules the postcar stage needs similar semantics of the more
83 * traditional stages in the coreboot infrastructure. Therefore it's easier
84 * to specialize this case.
85 */
86#if ENV_RMODULE || ENV_POSTCAR
Aaron Durbindde76292015-09-05 12:59:26 -050087 _rmodule_params = .;
88 KEEP(*(.module_parameters));
89 _ermodule_params = .;
Julius Werner82d16b12020-12-30 15:51:10 -080090 RECORD_SIZE(rmodule_params)
Aaron Durbindde76292015-09-05 12:59:26 -050091#endif
92
Aaron Durbin4de29d42015-09-03 22:49:36 -050093 *(.data);
94 *(.data.*);
Aaron Durbin9a2790e2016-10-28 12:24:48 -050095 *(.sdata);
96 *(.sdata.*);
Aaron Durbin4de29d42015-09-03 22:49:36 -050097
Kyösti Mälkkie3acc8f2019-09-13 10:49:20 +030098#if ENV_ROMSTAGE_OR_BEFORE
Aaron Durbin4de29d42015-09-03 22:49:36 -050099 PROVIDE(_preram_cbmem_console = .);
100 PROVIDE(_epreram_cbmem_console = _preram_cbmem_console);
Julius Werner82d16b12020-12-30 15:51:10 -0800101 PROVIDE(_preram_cbmem_console_size = ABSOLUTE(0));
Aaron Durbin83bc0db2015-09-06 10:45:18 -0500102#elif ENV_RAMSTAGE
Aaron Durbin4de29d42015-09-03 22:49:36 -0500103 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
104 _bs_init_begin = .;
105 KEEP(*(.bs_init));
106 LONG(0);
107 LONG(0);
108 _ebs_init_begin = .;
Julius Werner82d16b12020-12-30 15:51:10 -0800109 RECORD_SIZE(bs_init_begin)
Aaron Durbin4de29d42015-09-03 22:49:36 -0500110#endif
111
112 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
113 _edata = .;
Julius Werner82d16b12020-12-30 15:51:10 -0800114 RECORD_SIZE(data)
Aaron Durbin4de29d42015-09-03 22:49:36 -0500115}
116#endif
117
Kyösti Mälkkifcbbb912020-04-20 10:21:39 +0300118#if !ENV_CACHE_AS_RAM
Julius Werner52a92602015-09-11 16:17:50 -0700119.bss . : {
Aaron Durbin4de29d42015-09-03 22:49:36 -0500120 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
121 _bss = .;
122 *(.bss)
123 *(.bss.*)
124 *(.sbss)
125 *(.sbss.*)
126 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
127 _ebss = .;
Julius Werner82d16b12020-12-30 15:51:10 -0800128 RECORD_SIZE(bss)
Aaron Durbin4de29d42015-09-03 22:49:36 -0500129}
130#endif
131
Kyösti Mälkkif2cc52b2019-08-21 07:15:38 +0300132#if ENV_STAGE_HAS_HEAP_SECTION
Julius Werner52a92602015-09-11 16:17:50 -0700133.heap . : {
Aaron Durbin4de29d42015-09-03 22:49:36 -0500134 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
135 _heap = .;
Aaron Durbindde76292015-09-05 12:59:26 -0500136 . += (ENV_RMODULE ? __heap_size : CONFIG_HEAP_SIZE);
Aaron Durbin4de29d42015-09-03 22:49:36 -0500137 . = ALIGN(ARCH_POINTER_ALIGN_SIZE);
138 _eheap = .;
Julius Werner82d16b12020-12-30 15:51:10 -0800139 RECORD_SIZE(heap)
Aaron Durbin4de29d42015-09-03 22:49:36 -0500140}
141#endif
142
Harshit Sharma9c88fb82020-06-17 20:19:00 -0700143#if ENV_RAMSTAGE && CONFIG(ASAN_IN_RAMSTAGE)
144 _shadow_size = (_eheap - _data) >> 3;
145 REGION(asan_shadow, ., _shadow_size, ARCH_POINTER_ALIGN_SIZE)
146#endif
147
Aaron Durbin4de29d42015-09-03 22:49:36 -0500148_eprogram = .;
Julius Werner82d16b12020-12-30 15:51:10 -0800149RECORD_SIZE(program)
Aaron Durbin4de29d42015-09-03 22:49:36 -0500150
151/* Discard the sections we don't need/want */
152
Patrick Georgifab8ae72016-04-13 20:55:34 +0200153zeroptr = 0;
Patrick Georgiff8076d2016-01-27 08:18:16 +0100154
Aaron Durbin4de29d42015-09-03 22:49:36 -0500155/DISCARD/ : {
156 *(.comment)
157 *(.comment.*)
158 *(.note)
159 *(.note.*)
160 *(.eh_frame);
161}