Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013-2014, Wind River Systems, Inc. |
| 3 | * |
David B. Kinder | ac74d8b | 2017-01-18 17:01:01 -0800 | [diff] [blame] | 4 | * SPDX-License-Identifier: Apache-2.0 |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
Dan Kalowsky | da67b29 | 2015-10-20 09:42:33 -0700 | [diff] [blame] | 8 | * DESCRIPTION |
| 9 | * Platform independent, commonly used macros and defines related to linker |
| 10 | * script. |
| 11 | * |
| 12 | * This file may be included by: |
| 13 | * - Linker script files: for linker section declarations |
| 14 | * - C files: for external declaration of address or size of linker section |
| 15 | * - Assembly files: for external declaration of address or size of linker |
| 16 | * section |
Anas Nashif | ea0d0b2 | 2015-07-01 17:22:39 -0400 | [diff] [blame] | 17 | */ |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 18 | |
| 19 | #ifndef _LINKERDEFS_H |
| 20 | #define _LINKERDEFS_H |
| 21 | |
| 22 | #include <toolchain.h> |
Anas Nashif | 397d29d | 2017-06-17 11:30:47 -0400 | [diff] [blame] | 23 | #include <linker/sections.h> |
Anas Nashif | 0a4808b | 2017-10-31 09:30:38 -0400 | [diff] [blame] | 24 | #include <misc/util.h> |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 25 | |
| 26 | /* include platform dependent linker-defs */ |
Anas Nashif | 77ba3c3 | 2015-10-09 06:20:52 -0400 | [diff] [blame] | 27 | #ifdef CONFIG_X86 |
Andrew Boie | 327017f | 2016-10-21 09:29:09 -0700 | [diff] [blame] | 28 | /* Nothing yet to include */ |
Anas Nashif | 274622e | 2015-06-05 22:27:08 -0400 | [diff] [blame] | 29 | #elif defined(CONFIG_ARM) |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 30 | /* Nothing yet to include */ |
Anas Nashif | f2520f8 | 2015-06-05 22:27:49 -0400 | [diff] [blame] | 31 | #elif defined(CONFIG_ARC) |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 32 | /* Nothing yet to include */ |
Andrew Boie | 9433895 | 2016-04-21 14:47:09 -0700 | [diff] [blame] | 33 | #elif defined(CONFIG_NIOS2) |
| 34 | /* Nothing yet to include */ |
Jean-Paul Etienne | cd83e85 | 2017-01-11 00:24:30 +0100 | [diff] [blame] | 35 | #elif defined(CONFIG_RISCV32) |
| 36 | /* Nothing yet to include */ |
Mazen NEIFER | 969f000 | 2017-01-25 22:26:58 +0100 | [diff] [blame] | 37 | #elif defined(CONFIG_XTENSA) |
| 38 | /* Nothing yet to include */ |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 39 | #elif defined(CONFIG_ARCH_POSIX) |
| 40 | /* Nothing yet to include */ |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 41 | #else |
| 42 | #error Arch not supported. |
| 43 | #endif |
| 44 | |
| 45 | #ifdef _LINKER |
Allan Stephens | a860cb7 | 2015-10-14 11:17:20 -0400 | [diff] [blame] | 46 | |
Jithu Joseph | 592882e | 2016-04-08 12:38:57 -0700 | [diff] [blame] | 47 | |
| 48 | /* |
| 49 | * Space for storing per device busy bitmap. Since we do not know beforehand |
| 50 | * the number of devices, we go through the below mechanism to allocate the |
| 51 | * required space. |
| 52 | */ |
| 53 | #ifdef CONFIG_DEVICE_POWER_MANAGEMENT |
Benjamin Walsh | f6ca7de | 2016-11-08 10:36:50 -0500 | [diff] [blame] | 54 | #define DEVICE_COUNT \ |
| 55 | ((__device_init_end - __device_init_start) / _DEVICE_STRUCT_SIZE) |
Jithu Joseph | 592882e | 2016-04-08 12:38:57 -0700 | [diff] [blame] | 56 | #define DEV_BUSY_SZ (((DEVICE_COUNT + 31) / 32) * 4) |
| 57 | #define DEVICE_BUSY_BITFIELD() \ |
| 58 | FILL(0x00) ; \ |
| 59 | __device_busy_start = .; \ |
| 60 | . = . + DEV_BUSY_SZ; \ |
| 61 | __device_busy_end = .; |
| 62 | #else |
| 63 | #define DEVICE_BUSY_BITFIELD() |
| 64 | #endif |
| 65 | |
Allan Stephens | a860cb7 | 2015-10-14 11:17:20 -0400 | [diff] [blame] | 66 | /* |
| 67 | * generate a symbol to mark the start of the device initialization objects for |
| 68 | * the specified level, then link all of those objects (sorted by priority); |
| 69 | * ensure the objects aren't discarded if there is no direct reference to them |
| 70 | */ |
| 71 | |
| 72 | #define DEVICE_INIT_LEVEL(level) \ |
| 73 | __device_##level##_start = .; \ |
| 74 | KEEP(*(SORT(.init_##level[0-9]))); \ |
| 75 | KEEP(*(SORT(.init_##level[1-9][0-9]))); \ |
| 76 | |
| 77 | /* |
| 78 | * link in device initialization objects for all devices that are automatically |
| 79 | * initialized by the kernel; the objects are sorted in the order they will be |
| 80 | * initialized (i.e. ordered by level, sorted by priority within a level) |
| 81 | */ |
| 82 | |
| 83 | #define DEVICE_INIT_SECTIONS() \ |
Andrew Boie | 0b474ee | 2016-11-08 11:06:55 -0800 | [diff] [blame] | 84 | __device_init_start = .; \ |
| 85 | DEVICE_INIT_LEVEL(PRE_KERNEL_1) \ |
| 86 | DEVICE_INIT_LEVEL(PRE_KERNEL_2) \ |
| 87 | DEVICE_INIT_LEVEL(POST_KERNEL) \ |
| 88 | DEVICE_INIT_LEVEL(APPLICATION) \ |
Jithu Joseph | 592882e | 2016-04-08 12:38:57 -0700 | [diff] [blame] | 89 | __device_init_end = .; \ |
| 90 | DEVICE_BUSY_BITFIELD() \ |
Allan Stephens | a860cb7 | 2015-10-14 11:17:20 -0400 | [diff] [blame] | 91 | |
Dmitriy Korovkin | fb6de2d | 2015-10-26 15:40:46 -0400 | [diff] [blame] | 92 | |
| 93 | /* define a section for undefined device initialization levels */ |
| 94 | #define DEVICE_INIT_UNDEFINED_SECTION() \ |
| 95 | KEEP(*(SORT(.init_[_A-Z0-9]*))) \ |
| 96 | |
Yael Avramovich | d5db352 | 2016-07-31 16:16:29 +0300 | [diff] [blame] | 97 | /* |
| 98 | * link in shell initialization objects for all modules that use shell and |
| 99 | * their shell commands are automatically initialized by the kernel. |
| 100 | */ |
| 101 | |
Anas Nashif | 8d19315 | 2018-01-15 11:10:09 -0500 | [diff] [blame] | 102 | #define SHELL_INIT_SECTIONS() \ |
| 103 | __shell_module_start = .; \ |
| 104 | KEEP(*(".shell_module_*")); \ |
Anas Nashif | d7777d3 | 2018-01-15 11:15:47 -0500 | [diff] [blame] | 105 | __shell_module_end = .; \ |
| 106 | __shell_cmd_start = .; \ |
| 107 | KEEP(*(".shell_cmd_*")); \ |
| 108 | __shell_cmd_end = .; \ |
Yael Avramovich | d5db352 | 2016-07-31 16:16:29 +0300 | [diff] [blame] | 109 | |
Andrew Boie | f1ae5d4 | 2017-06-19 10:20:41 -0700 | [diff] [blame] | 110 | #ifdef CONFIG_APPLICATION_MEMORY |
Anas Nashif | 0a4808b | 2017-10-31 09:30:38 -0400 | [diff] [blame] | 111 | |
| 112 | #ifndef NUM_KERNEL_OBJECT_FILES |
| 113 | #error "Expected NUM_KERNEL_OBJECT_FILES to be defined" |
| 114 | #elif NUM_KERNEL_OBJECT_FILES > 19 |
| 115 | #error "Max supported kernel objects is 19." |
| 116 | /* TODO: Using the preprocessor to do this was a mistake. Rewrite to |
| 117 | scale better. e.g. by aggregating the kernel objects into two |
| 118 | archives like KBuild did.*/ |
| 119 | #endif |
| 120 | |
Sebastian Bøe | 1c2de10 | 2018-01-02 15:54:16 +0100 | [diff] [blame] | 121 | #define X(i, j) KERNEL_OBJECT_FILE_##i (j) |
| 122 | #define Y(i, j) KERNEL_OBJECT_FILE_##i |
Anas Nashif | 0a4808b | 2017-10-31 09:30:38 -0400 | [diff] [blame] | 123 | |
| 124 | #define KERNEL_INPUT_SECTION(sect) \ |
| 125 | UTIL_LISTIFY(NUM_KERNEL_OBJECT_FILES, X, sect) |
Andrew Boie | 5f5f7c5 | 2017-08-01 14:43:24 -0700 | [diff] [blame] | 126 | #define APP_INPUT_SECTION(sect) \ |
Anas Nashif | 0a4808b | 2017-10-31 09:30:38 -0400 | [diff] [blame] | 127 | *(EXCLUDE_FILE (UTIL_LISTIFY(NUM_KERNEL_OBJECT_FILES, Y, ~)) sect) |
| 128 | |
Andrew Boie | f1ae5d4 | 2017-06-19 10:20:41 -0700 | [diff] [blame] | 129 | #else |
| 130 | #define KERNEL_INPUT_SECTION(sect) *(sect) |
| 131 | #define APP_INPUT_SECTION(sect) *(sect) |
| 132 | #endif |
| 133 | |
Yael Avramovich | d5db352 | 2016-07-31 16:16:29 +0300 | [diff] [blame] | 134 | |
Anas Nashif | 77ba3c3 | 2015-10-09 06:20:52 -0400 | [diff] [blame] | 135 | #ifdef CONFIG_X86 /* LINKER FILES: defines used by linker script */ |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 136 | /* Should be moved to linker-common-defs.h */ |
| 137 | #if defined(CONFIG_XIP) |
| 138 | #define ROMABLE_REGION ROM |
| 139 | #else |
| 140 | #define ROMABLE_REGION RAM |
| 141 | #endif |
| 142 | #endif |
| 143 | |
| 144 | /* |
| 145 | * If image is loaded via kexec Linux system call, then program |
| 146 | * headers need to be page aligned. |
| 147 | * This can be done by section page aligning. |
| 148 | */ |
| 149 | #ifdef CONFIG_BOOTLOADER_KEXEC |
| 150 | #define KEXEC_PGALIGN_PAD(x) . = ALIGN(x); |
| 151 | #else |
| 152 | #define KEXEC_PGALIGN_PAD(x) |
| 153 | #endif |
| 154 | |
| 155 | #elif defined(_ASMLANGUAGE) |
Allan Stephens | a860cb7 | 2015-10-14 11:17:20 -0400 | [diff] [blame] | 156 | |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 157 | /* Assembly FILES: declaration defined by the linker script */ |
| 158 | GDATA(__bss_start) |
| 159 | GDATA(__bss_num_words) |
| 160 | #ifdef CONFIG_XIP |
| 161 | GDATA(__data_rom_start) |
| 162 | GDATA(__data_ram_start) |
| 163 | GDATA(__data_num_words) |
| 164 | #endif |
| 165 | |
Allan Stephens | a860cb7 | 2015-10-14 11:17:20 -0400 | [diff] [blame] | 166 | #else /* ! _ASMLANGUAGE */ |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 167 | |
Kumar Gala | 7890816 | 2017-04-19 10:32:08 -0500 | [diff] [blame] | 168 | #include <zephyr/types.h> |
Andrew Boie | 1eaccb0 | 2017-06-14 13:31:11 -0700 | [diff] [blame] | 169 | |
Andrew Boie | bf5228e | 2017-06-19 11:13:19 -0700 | [diff] [blame] | 170 | #ifdef CONFIG_APPLICATION_MEMORY |
Andrew Boie | 3876f53 | 2017-08-01 15:13:44 -0700 | [diff] [blame] | 171 | /* Memory owned by the application. Start and end will be aligned for memory |
| 172 | * management/protection hardware for the target architecture. |
| 173 | |
| 174 | * The policy for this memory will be to configure all of it as user thread |
| 175 | * accessible. It consists of all non-kernel globals. |
| 176 | */ |
Andrew Boie | bf5228e | 2017-06-19 11:13:19 -0700 | [diff] [blame] | 177 | extern char __app_ram_start[]; |
| 178 | extern char __app_ram_end[]; |
Andrew Boie | 3876f53 | 2017-08-01 15:13:44 -0700 | [diff] [blame] | 179 | extern char __app_ram_size[]; |
Andrew Boie | bf5228e | 2017-06-19 11:13:19 -0700 | [diff] [blame] | 180 | #endif |
| 181 | |
Andrew Boie | 3876f53 | 2017-08-01 15:13:44 -0700 | [diff] [blame] | 182 | /* Memory owned by the kernel. Start and end will be aligned for memory |
| 183 | * management/protection hardware for the target architecture.. |
| 184 | * |
| 185 | * Consists of all kernel-side globals, all kernel objects, all thread stacks, |
| 186 | * and all currently unused RAM. If CONFIG_APPLICATION_MEMORY is not enabled, |
| 187 | * has all globals, not just kernel side. |
| 188 | * |
| 189 | * Except for the stack of the currently executing thread, none of this memory |
| 190 | * is normally accessible to user threads unless specifically granted at |
| 191 | * runtime. |
| 192 | */ |
Andrew Boie | bf5228e | 2017-06-19 11:13:19 -0700 | [diff] [blame] | 193 | extern char __kernel_ram_start[]; |
| 194 | extern char __kernel_ram_end[]; |
Andrew Boie | 3876f53 | 2017-08-01 15:13:44 -0700 | [diff] [blame] | 195 | extern char __kernel_ram_size[]; |
Andrew Boie | bf5228e | 2017-06-19 11:13:19 -0700 | [diff] [blame] | 196 | |
Andrew Boie | 1eaccb0 | 2017-06-14 13:31:11 -0700 | [diff] [blame] | 197 | /* Used by _bss_zero or arch-specific implementation */ |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 198 | extern char __bss_start[]; |
Andrew Boie | ef29812 | 2016-06-30 16:45:08 -0700 | [diff] [blame] | 199 | extern char __bss_end[]; |
Andrew Boie | bf5228e | 2017-06-19 11:13:19 -0700 | [diff] [blame] | 200 | #ifdef CONFIG_APPLICATION_MEMORY |
| 201 | extern char __app_bss_start[]; |
| 202 | extern char __app_bss_end[]; |
| 203 | #endif |
Andrew Boie | 1eaccb0 | 2017-06-14 13:31:11 -0700 | [diff] [blame] | 204 | |
| 205 | /* Used by _data_copy() or arch-specific implementation */ |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 206 | #ifdef CONFIG_XIP |
| 207 | extern char __data_rom_start[]; |
| 208 | extern char __data_ram_start[]; |
Andrew Boie | ef29812 | 2016-06-30 16:45:08 -0700 | [diff] [blame] | 209 | extern char __data_ram_end[]; |
Andrew Boie | bf5228e | 2017-06-19 11:13:19 -0700 | [diff] [blame] | 210 | #ifdef CONFIG_APPLICATION_MEMORY |
| 211 | extern char __app_data_rom_start[]; |
| 212 | extern char __app_data_ram_start[]; |
| 213 | extern char __app_data_ram_end[]; |
| 214 | #endif /* CONFIG_APPLICATION_MEMORY */ |
| 215 | #endif /* CONFIG_XIP */ |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 216 | |
Andrew Boie | efee38d | 2017-07-11 08:58:43 -0700 | [diff] [blame] | 217 | /* Includes text and rodata */ |
Benjamin Walsh | 09303f7 | 2015-09-16 19:14:40 -0400 | [diff] [blame] | 218 | extern char _image_rom_start[]; |
| 219 | extern char _image_rom_end[]; |
Andrew Boie | efee38d | 2017-07-11 08:58:43 -0700 | [diff] [blame] | 220 | extern char _image_rom_size[]; |
| 221 | |
| 222 | /* datas, bss, noinit */ |
Benjamin Walsh | 09303f7 | 2015-09-16 19:14:40 -0400 | [diff] [blame] | 223 | extern char _image_ram_start[]; |
| 224 | extern char _image_ram_end[]; |
Andrew Boie | efee38d | 2017-07-11 08:58:43 -0700 | [diff] [blame] | 225 | |
Benjamin Walsh | c12c234 | 2015-09-21 17:57:39 -0400 | [diff] [blame] | 226 | extern char _image_text_start[]; |
| 227 | extern char _image_text_end[]; |
Benjamin Walsh | 09303f7 | 2015-09-16 19:14:40 -0400 | [diff] [blame] | 228 | |
Andrew Boie | efee38d | 2017-07-11 08:58:43 -0700 | [diff] [blame] | 229 | extern char _image_rodata_start[]; |
| 230 | extern char _image_rodata_end[]; |
| 231 | |
Xiaorui Hu | eb48a0a | 2017-06-23 11:02:50 +0800 | [diff] [blame] | 232 | extern char _vector_start[]; |
| 233 | extern char _vector_end[]; |
| 234 | |
Andrew Boie | 1eaccb0 | 2017-06-14 13:31:11 -0700 | [diff] [blame] | 235 | /* end address of image, used by newlib for the heap */ |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 236 | extern char _end[]; |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 237 | |
Erwin Rol | 581446d | 2017-10-05 01:20:21 +0200 | [diff] [blame] | 238 | #ifdef CONFIG_CCM_BASE_ADDRESS |
| 239 | extern char __ccm_data_rom_start[]; |
| 240 | extern char __ccm_start[]; |
| 241 | extern char __ccm_data_start[]; |
| 242 | extern char __ccm_data_end[]; |
| 243 | extern char __ccm_bss_start[]; |
| 244 | extern char __ccm_bss_end[]; |
| 245 | extern char __ccm_noinit_start[]; |
| 246 | extern char __ccm_noinit_end[]; |
| 247 | extern char __ccm_end[]; |
| 248 | #endif /* CONFIG_CCM_BASE_ADDRESS */ |
| 249 | |
| 250 | |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 251 | #endif /* ! _ASMLANGUAGE */ |
| 252 | |
| 253 | #endif /* _LINKERDEFS_H */ |