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 | */ |
Julius Werner | 52a9260 | 2015-09-11 16:17:50 -0700 | [diff] [blame] | 13 | .text . : { |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 14 | _program = .; |
| 15 | _text = .; |
Kyösti Mälkki | 2289a70 | 2019-12-21 10:17:56 +0200 | [diff] [blame] | 16 | #if !(ENV_X86 && ENV_BOOTBLOCK) |
Kyösti Mälkki | 7522a8f | 2020-11-20 16:47:38 +0200 | [diff] [blame] | 17 | *(.init._start); |
| 18 | *(.init); |
| 19 | *(.init.*); |
Kyösti Mälkki | 2289a70 | 2019-12-21 10:17:56 +0200 | [diff] [blame] | 20 | #endif |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 21 | *(.text._start); |
| 22 | *(.text.stage_entry); |
Julius Werner | fdabf3f | 2020-05-06 17:06:35 -0700 | [diff] [blame] | 23 | KEEP(*(.metadata_hash_anchor)); |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 24 | *(.text); |
| 25 | *(.text.*); |
| 26 | |
Kyösti Mälkki | fa3bc04 | 2022-03-31 07:40:10 +0300 | [diff] [blame] | 27 | #if ENV_HAS_CBMEM |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 28 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 29 | _cbmem_init_hooks = .; |
Julius Werner | 913a47a | 2021-05-20 17:00:46 -0700 | [diff] [blame] | 30 | KEEP(*(.rodata.cbmem_init_hooks_early)); |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 31 | KEEP(*(.rodata.cbmem_init_hooks)); |
| 32 | _ecbmem_init_hooks = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 33 | RECORD_SIZE(cbmem_init_hooks) |
Stefan Reinauer | f6b1039 | 2016-05-20 15:17:17 -0700 | [diff] [blame] | 34 | #endif |
Lee Leahy | efcee9f | 2016-04-29 17:26:36 -0700 | [diff] [blame] | 35 | |
| 36 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 37 | _rsbe_init_begin = .; |
| 38 | KEEP(*(.rsbe_init)); |
| 39 | _ersbe_init_begin = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 40 | RECORD_SIZE(rsbe_init_begin) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 41 | |
Aaron Durbin | 83bc0db | 2015-09-06 10:45:18 -0500 | [diff] [blame] | 42 | #if ENV_RAMSTAGE |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 43 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 44 | _pci_drivers = .; |
| 45 | KEEP(*(.rodata.pci_driver)); |
| 46 | _epci_drivers = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 47 | RECORD_SIZE(pci_drivers) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 48 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 49 | _cpu_drivers = .; |
| 50 | KEEP(*(.rodata.cpu_driver)); |
| 51 | _ecpu_drivers = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 52 | RECORD_SIZE(cpu_drivers) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 53 | #endif |
| 54 | |
| 55 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 56 | *(.rodata); |
| 57 | *(.rodata.*); |
| 58 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 59 | _etext = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 60 | RECORD_SIZE(text) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 61 | } : to_load |
| 62 | |
Harshit Sharma | 9c88fb8 | 2020-06-17 20:19:00 -0700 | [diff] [blame] | 63 | #if ENV_RAMSTAGE && (CONFIG(COVERAGE) || CONFIG(ASAN_IN_RAMSTAGE)) |
Julius Werner | 52a9260 | 2015-09-11 16:17:50 -0700 | [diff] [blame] | 64 | .ctors . : { |
Patrick Georgi | 9cc8e92 | 2015-09-27 13:45:17 +0200 | [diff] [blame] | 65 | . = ALIGN(0x100); |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 66 | __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 Compostella | b7832de | 2023-08-30 15:42:09 -0700 | [diff] [blame] | 75 | #if !ENV_SEPARATE_DATA_AND_BSS |
Julius Werner | 52a9260 | 2015-09-11 16:17:50 -0700 | [diff] [blame] | 76 | .data . : { |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 77 | . = ALIGN(ARCH_CACHELINE_ALIGN_SIZE); |
| 78 | _data = .; |
Aaron Durbin | dde7629 | 2015-09-05 12:59:26 -0500 | [diff] [blame] | 79 | |
Aaron Durbin | 7f8afe0 | 2016-03-18 12:21:23 -0500 | [diff] [blame] | 80 | /* |
| 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 Durbin | dde7629 | 2015-09-05 12:59:26 -0500 | [diff] [blame] | 88 | _rmodule_params = .; |
| 89 | KEEP(*(.module_parameters)); |
| 90 | _ermodule_params = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 91 | RECORD_SIZE(rmodule_params) |
Aaron Durbin | dde7629 | 2015-09-05 12:59:26 -0500 | [diff] [blame] | 92 | #endif |
| 93 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 94 | *(.data); |
| 95 | *(.data.*); |
Aaron Durbin | 9a2790e | 2016-10-28 12:24:48 -0500 | [diff] [blame] | 96 | *(.sdata); |
| 97 | *(.sdata.*); |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 98 | |
Kyösti Mälkki | e3acc8f | 2019-09-13 10:49:20 +0300 | [diff] [blame] | 99 | #if ENV_ROMSTAGE_OR_BEFORE |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 100 | PROVIDE(_preram_cbmem_console = .); |
| 101 | PROVIDE(_epreram_cbmem_console = _preram_cbmem_console); |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 102 | PROVIDE(_preram_cbmem_console_size = ABSOLUTE(0)); |
Aaron Durbin | 83bc0db | 2015-09-06 10:45:18 -0500 | [diff] [blame] | 103 | #elif ENV_RAMSTAGE |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 104 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 105 | _bs_init_begin = .; |
| 106 | KEEP(*(.bs_init)); |
| 107 | LONG(0); |
| 108 | LONG(0); |
| 109 | _ebs_init_begin = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 110 | RECORD_SIZE(bs_init_begin) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 111 | #endif |
| 112 | |
| 113 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 114 | _edata = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 115 | RECORD_SIZE(data) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 116 | } |
| 117 | #endif |
| 118 | |
Jeremy Compostella | b7832de | 2023-08-30 15:42:09 -0700 | [diff] [blame] | 119 | #if !ENV_SEPARATE_DATA_AND_BSS |
Julius Werner | 52a9260 | 2015-09-11 16:17:50 -0700 | [diff] [blame] | 120 | .bss . : { |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 121 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 122 | _bss = .; |
| 123 | *(.bss) |
| 124 | *(.bss.*) |
| 125 | *(.sbss) |
| 126 | *(.sbss.*) |
| 127 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 128 | _ebss = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 129 | RECORD_SIZE(bss) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 130 | } |
| 131 | #endif |
| 132 | |
Arthur Heymans | 6acc05e | 2022-05-12 18:01:13 +0200 | [diff] [blame] | 133 | #if ENV_HAS_HEAP_SECTION |
Julius Werner | 52a9260 | 2015-09-11 16:17:50 -0700 | [diff] [blame] | 134 | .heap . : { |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 135 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 136 | _heap = .; |
Aaron Durbin | dde7629 | 2015-09-05 12:59:26 -0500 | [diff] [blame] | 137 | . += (ENV_RMODULE ? __heap_size : CONFIG_HEAP_SIZE); |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 138 | . = ALIGN(ARCH_POINTER_ALIGN_SIZE); |
| 139 | _eheap = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 140 | RECORD_SIZE(heap) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 141 | } |
| 142 | #endif |
| 143 | |
Harshit Sharma | 9c88fb8 | 2020-06-17 20:19:00 -0700 | [diff] [blame] | 144 | #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 Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 149 | _eprogram = .; |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 150 | RECORD_SIZE(program) |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 151 | |
Patrick Georgi | ed0647a | 2023-12-13 17:57:34 +0100 | [diff] [blame] | 152 | /* 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 Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 161 | /* Discard the sections we don't need/want */ |
| 162 | |
Patrick Georgi | fab8ae7 | 2016-04-13 20:55:34 +0200 | [diff] [blame] | 163 | zeroptr = 0; |
Patrick Georgi | ff8076d | 2016-01-27 08:18:16 +0100 | [diff] [blame] | 164 | |
Aaron Durbin | 4de29d4 | 2015-09-03 22:49:36 -0500 | [diff] [blame] | 165 | /DISCARD/ : { |
| 166 | *(.comment) |
| 167 | *(.comment.*) |
| 168 | *(.note) |
| 169 | *(.note.*) |
| 170 | *(.eh_frame); |
| 171 | } |