Angel Pons | 118a9c7 | 2020-04-02 23:48:34 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 2 | |
| 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 Werner | 52a9260 | 2015-09-11 16:17:50 -0700 | [diff] [blame] | 9 | * 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 Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 12 | */ |
Arthur Heymans | 8406fb4 | 2024-04-05 09:00:06 +0200 | [diff] [blame] | 13 | |
| 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 Werner | 52a9260 | 2015-09-11 16:17:50 -0700 | [diff] [blame] | 18 | .text . : { |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 19 | _program = .; |
| 20 | _text = .; |
Kyösti Mälkki | 2289a70 | 2019-12-21 10:17:56 +0200 | [diff] [blame] | 21 | #if !(ENV_X86 && ENV_BOOTBLOCK) |
Kyösti Mälkki | 7522a8f | 2020-11-20 16:47:38 +0200 | [diff] [blame] | 22 | *(.init._start); |
| 23 | *(.init); |
| 24 | *(.init.*); |
Kyösti Mälkki | 2289a70 | 2019-12-21 10:17:56 +0200 | [diff] [blame] | 25 | #endif |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 26 | *(.text._start); |
| 27 | *(.text.stage_entry); |
Julius Werner | fdabf3f | 2020-05-06 17:06:35 -0700 | [diff] [blame] | 28 | KEEP(*(.metadata_hash_anchor)); |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 29 | *(.text); |
| 30 | *(.text.*); |
Arthur Heymans | 8406fb4 | 2024-04-05 09:00:06 +0200 | [diff] [blame] | 31 | *(.ltext); |
| 32 | *(.ltext.*); |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 33 | |
Kyösti Mälkki | fa3bc04 | 2022-03-31 07:40:10 +0300 | [diff] [blame] | 34 | #if ENV_HAS_CBMEM |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 35 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 36 | _cbmem_init_hooks = .; |
Julius Werner | 913a47a | 2021-05-20 17:00:46 -0700 | [diff] [blame] | 37 | KEEP(*(.rodata.cbmem_init_hooks_early)); |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 38 | KEEP(*(.rodata.cbmem_init_hooks)); |
| 39 | _ecbmem_init_hooks = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 40 | RECORD_SIZE(cbmem_init_hooks) |
Stefan Reinauer | f6b1039 | 2016-05-20 15:17:17 -0700 | [diff] [blame] | 41 | #endif |
Lee Leahy | efcee9f | 2016-04-29 17:26:36 -0700 | [diff] [blame] | 42 | |
| 43 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 44 | _rsbe_init_begin = .; |
| 45 | KEEP(*(.rsbe_init)); |
| 46 | _ersbe_init_begin = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 47 | RECORD_SIZE(rsbe_init_begin) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 48 | |
Aaron Durbin | 83bc0db | 2015-09-06 10:45:18 -0500 | [diff] [blame] | 49 | #if ENV_RAMSTAGE |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 50 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 51 | _pci_drivers = .; |
| 52 | KEEP(*(.rodata.pci_driver)); |
| 53 | _epci_drivers = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 54 | RECORD_SIZE(pci_drivers) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 55 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 56 | _cpu_drivers = .; |
| 57 | KEEP(*(.rodata.cpu_driver)); |
| 58 | _ecpu_drivers = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 59 | RECORD_SIZE(cpu_drivers) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 60 | #endif |
| 61 | |
| 62 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 63 | *(.rodata); |
| 64 | *(.rodata.*); |
Arthur Heymans | 8406fb4 | 2024-04-05 09:00:06 +0200 | [diff] [blame] | 65 | *(.lrodata); |
| 66 | *(.lrodata.*); |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 67 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 68 | _etext = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 69 | RECORD_SIZE(text) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 70 | } : to_load |
| 71 | |
Harshit Sharma | 9c88fb8 | 2020-06-17 20:19:00 -0700 | [diff] [blame] | 72 | #if ENV_RAMSTAGE && (CONFIG(COVERAGE) || CONFIG(ASAN_IN_RAMSTAGE)) |
Julius Werner | 52a9260 | 2015-09-11 16:17:50 -0700 | [diff] [blame] | 73 | .ctors . : { |
Patrick Georgi | 9cc8e92 | 2015-09-27 13:45:17 +0200 | [diff] [blame] | 74 | . = ALIGN(0x100); |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 75 | __CTOR_LIST__ = .; |
| 76 | KEEP(*(.ctors)); |
| 77 | LONG(0); |
| 78 | LONG(0); |
| 79 | __CTOR_END__ = .; |
Arthur Heymans | 67166a7 | 2024-02-29 15:05:15 +0100 | [diff] [blame] | 80 | } : to_load |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 81 | #endif |
| 82 | |
| 83 | /* Include data, bss, and heap in that order. Not defined for all stages. */ |
Jeremy Compostella | b7832de | 2023-08-30 15:42:09 -0700 | [diff] [blame] | 84 | #if !ENV_SEPARATE_DATA_AND_BSS |
Julius Werner | 52a9260 | 2015-09-11 16:17:50 -0700 | [diff] [blame] | 85 | .data . : { |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 86 | . = ALIGN(ARCH_CACHELINE_ALIGN_SIZE); |
| 87 | _data = .; |
Aaron Durbin | dde7629 | 2015-09-05 12:59:26 -0500 | [diff] [blame] | 88 | |
Aaron Durbin | 7f8afe0 | 2016-03-18 12:21:23 -0500 | [diff] [blame] | 89 | /* |
| 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 Durbin | dde7629 | 2015-09-05 12:59:26 -0500 | [diff] [blame] | 97 | _rmodule_params = .; |
| 98 | KEEP(*(.module_parameters)); |
| 99 | _ermodule_params = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 100 | RECORD_SIZE(rmodule_params) |
Aaron Durbin | dde7629 | 2015-09-05 12:59:26 -0500 | [diff] [blame] | 101 | #endif |
| 102 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 103 | *(.data); |
| 104 | *(.data.*); |
Arthur Heymans | 8406fb4 | 2024-04-05 09:00:06 +0200 | [diff] [blame] | 105 | *(.ldata); |
| 106 | *(.ldata.*); |
Aaron Durbin | 9a2790e | 2016-10-28 12:24:48 -0500 | [diff] [blame] | 107 | *(.sdata); |
| 108 | *(.sdata.*); |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 109 | |
Kyösti Mälkki | e3acc8f | 2019-09-13 10:49:20 +0300 | [diff] [blame] | 110 | #if ENV_ROMSTAGE_OR_BEFORE |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 111 | PROVIDE(_preram_cbmem_console = .); |
| 112 | PROVIDE(_epreram_cbmem_console = _preram_cbmem_console); |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 113 | PROVIDE(_preram_cbmem_console_size = ABSOLUTE(0)); |
Aaron Durbin | 83bc0db | 2015-09-06 10:45:18 -0500 | [diff] [blame] | 114 | #elif ENV_RAMSTAGE |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 115 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 116 | _bs_init_begin = .; |
| 117 | KEEP(*(.bs_init)); |
| 118 | LONG(0); |
| 119 | LONG(0); |
| 120 | _ebs_init_begin = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 121 | RECORD_SIZE(bs_init_begin) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 122 | #endif |
| 123 | |
| 124 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 125 | _edata = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 126 | RECORD_SIZE(data) |
Arthur Heymans | 67166a7 | 2024-02-29 15:05:15 +0100 | [diff] [blame] | 127 | } : to_load |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 128 | #endif |
| 129 | |
Jeremy Compostella | b7832de | 2023-08-30 15:42:09 -0700 | [diff] [blame] | 130 | #if !ENV_SEPARATE_DATA_AND_BSS |
Arthur Heymans | 67166a7 | 2024-02-29 15:05:15 +0100 | [diff] [blame] | 131 | .bss . (NOLOAD) : { |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 132 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 133 | _bss = .; |
| 134 | *(.bss) |
| 135 | *(.bss.*) |
Arthur Heymans | 8406fb4 | 2024-04-05 09:00:06 +0200 | [diff] [blame] | 136 | *(.lbss) |
| 137 | *(.lbss.*) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 138 | *(.sbss) |
| 139 | *(.sbss.*) |
| 140 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 141 | _ebss = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 142 | RECORD_SIZE(bss) |
Arthur Heymans | 67166a7 | 2024-02-29 15:05:15 +0100 | [diff] [blame] | 143 | } : to_load |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 144 | #endif |
| 145 | |
Arthur Heymans | 6acc05e | 2022-05-12 18:01:13 +0200 | [diff] [blame] | 146 | #if ENV_HAS_HEAP_SECTION |
Arthur Heymans | 67166a7 | 2024-02-29 15:05:15 +0100 | [diff] [blame] | 147 | .heap . (NOLOAD) : { |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 148 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 149 | _heap = .; |
Arthur Heymans | 7fbef1b | 2024-02-22 15:01:04 +0100 | [diff] [blame] | 150 | . += CONFIG_HEAP_SIZE; |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 151 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 152 | _eheap = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 153 | RECORD_SIZE(heap) |
Arthur Heymans | 67166a7 | 2024-02-29 15:05:15 +0100 | [diff] [blame] | 154 | } : to_load |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 155 | #endif |
| 156 | |
Harshit Sharma | 9c88fb8 | 2020-06-17 20:19:00 -0700 | [diff] [blame] | 157 | #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 Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 162 | _eprogram = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 163 | RECORD_SIZE(program) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 164 | |
Patrick Georgi | ed0647a | 2023-12-13 17:57:34 +0100 | [diff] [blame] | 165 | /* 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 Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 174 | /* Discard the sections we don't need/want */ |
| 175 | |
Patrick Georgi | fab8ae7 | 2016-04-13 20:55:34 +0200 | [diff] [blame] | 176 | zeroptr = 0; |
Patrick Georgi | ff8076d | 2016-01-27 08:18:16 +0100 | [diff] [blame] | 177 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 178 | /DISCARD/ : { |
| 179 | *(.comment) |
| 180 | *(.comment.*) |
| 181 | *(.note) |
| 182 | *(.note.*) |
| 183 | *(.eh_frame); |
| 184 | } |