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> |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 24 | |
| 25 | /* include platform dependent linker-defs */ |
Anas Nashif | 77ba3c3 | 2015-10-09 06:20:52 -0400 | [diff] [blame] | 26 | #ifdef CONFIG_X86 |
Andrew Boie | 327017f | 2016-10-21 09:29:09 -0700 | [diff] [blame] | 27 | /* Nothing yet to include */ |
Anas Nashif | 274622e | 2015-06-05 22:27:08 -0400 | [diff] [blame] | 28 | #elif defined(CONFIG_ARM) |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 29 | /* Nothing yet to include */ |
Anas Nashif | f2520f8 | 2015-06-05 22:27:49 -0400 | [diff] [blame] | 30 | #elif defined(CONFIG_ARC) |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 31 | /* Nothing yet to include */ |
Andrew Boie | 9433895 | 2016-04-21 14:47:09 -0700 | [diff] [blame] | 32 | #elif defined(CONFIG_NIOS2) |
| 33 | /* Nothing yet to include */ |
Jean-Paul Etienne | cd83e85 | 2017-01-11 00:24:30 +0100 | [diff] [blame] | 34 | #elif defined(CONFIG_RISCV32) |
| 35 | /* Nothing yet to include */ |
Mazen NEIFER | 969f000 | 2017-01-25 22:26:58 +0100 | [diff] [blame] | 36 | #elif defined(CONFIG_XTENSA) |
| 37 | /* Nothing yet to include */ |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 38 | #else |
| 39 | #error Arch not supported. |
| 40 | #endif |
| 41 | |
| 42 | #ifdef _LINKER |
Allan Stephens | a860cb7 | 2015-10-14 11:17:20 -0400 | [diff] [blame] | 43 | |
Jithu Joseph | 592882e | 2016-04-08 12:38:57 -0700 | [diff] [blame] | 44 | |
| 45 | /* |
| 46 | * Space for storing per device busy bitmap. Since we do not know beforehand |
| 47 | * the number of devices, we go through the below mechanism to allocate the |
| 48 | * required space. |
| 49 | */ |
| 50 | #ifdef CONFIG_DEVICE_POWER_MANAGEMENT |
Benjamin Walsh | f6ca7de | 2016-11-08 10:36:50 -0500 | [diff] [blame] | 51 | #define DEVICE_COUNT \ |
| 52 | ((__device_init_end - __device_init_start) / _DEVICE_STRUCT_SIZE) |
Jithu Joseph | 592882e | 2016-04-08 12:38:57 -0700 | [diff] [blame] | 53 | #define DEV_BUSY_SZ (((DEVICE_COUNT + 31) / 32) * 4) |
| 54 | #define DEVICE_BUSY_BITFIELD() \ |
| 55 | FILL(0x00) ; \ |
| 56 | __device_busy_start = .; \ |
| 57 | . = . + DEV_BUSY_SZ; \ |
| 58 | __device_busy_end = .; |
| 59 | #else |
| 60 | #define DEVICE_BUSY_BITFIELD() |
| 61 | #endif |
| 62 | |
Allan Stephens | a860cb7 | 2015-10-14 11:17:20 -0400 | [diff] [blame] | 63 | /* |
| 64 | * generate a symbol to mark the start of the device initialization objects for |
| 65 | * the specified level, then link all of those objects (sorted by priority); |
| 66 | * ensure the objects aren't discarded if there is no direct reference to them |
| 67 | */ |
| 68 | |
| 69 | #define DEVICE_INIT_LEVEL(level) \ |
| 70 | __device_##level##_start = .; \ |
| 71 | KEEP(*(SORT(.init_##level[0-9]))); \ |
| 72 | KEEP(*(SORT(.init_##level[1-9][0-9]))); \ |
| 73 | |
| 74 | /* |
| 75 | * link in device initialization objects for all devices that are automatically |
| 76 | * initialized by the kernel; the objects are sorted in the order they will be |
| 77 | * initialized (i.e. ordered by level, sorted by priority within a level) |
| 78 | */ |
| 79 | |
| 80 | #define DEVICE_INIT_SECTIONS() \ |
Andrew Boie | 0b474ee | 2016-11-08 11:06:55 -0800 | [diff] [blame] | 81 | __device_init_start = .; \ |
| 82 | DEVICE_INIT_LEVEL(PRE_KERNEL_1) \ |
| 83 | DEVICE_INIT_LEVEL(PRE_KERNEL_2) \ |
| 84 | DEVICE_INIT_LEVEL(POST_KERNEL) \ |
| 85 | DEVICE_INIT_LEVEL(APPLICATION) \ |
Jithu Joseph | 592882e | 2016-04-08 12:38:57 -0700 | [diff] [blame] | 86 | __device_init_end = .; \ |
| 87 | DEVICE_BUSY_BITFIELD() \ |
Allan Stephens | a860cb7 | 2015-10-14 11:17:20 -0400 | [diff] [blame] | 88 | |
Dmitriy Korovkin | fb6de2d | 2015-10-26 15:40:46 -0400 | [diff] [blame] | 89 | |
| 90 | /* define a section for undefined device initialization levels */ |
| 91 | #define DEVICE_INIT_UNDEFINED_SECTION() \ |
| 92 | KEEP(*(SORT(.init_[_A-Z0-9]*))) \ |
| 93 | |
Yael Avramovich | d5db352 | 2016-07-31 16:16:29 +0300 | [diff] [blame] | 94 | /* |
| 95 | * link in shell initialization objects for all modules that use shell and |
| 96 | * their shell commands are automatically initialized by the kernel. |
| 97 | */ |
| 98 | |
| 99 | #define SHELL_INIT_SECTIONS() \ |
| 100 | __shell_cmd_start = .; \ |
| 101 | KEEP(*(".shell_*")); \ |
| 102 | __shell_cmd_end = .; |
| 103 | |
Andrew Boie | f1ae5d4 | 2017-06-19 10:20:41 -0700 | [diff] [blame] | 104 | #ifdef CONFIG_APPLICATION_MEMORY |
| 105 | #define KERNEL_INPUT_SECTION(sect) libzephyr.a (sect) kernel/lib.a (sect) |
Andrew Boie | 5f5f7c5 | 2017-08-01 14:43:24 -0700 | [diff] [blame] | 106 | #define APP_INPUT_SECTION(sect) \ |
| 107 | *(EXCLUDE_FILE (*libzephyr.a *kernel/lib.a) sect) |
Andrew Boie | f1ae5d4 | 2017-06-19 10:20:41 -0700 | [diff] [blame] | 108 | #else |
| 109 | #define KERNEL_INPUT_SECTION(sect) *(sect) |
| 110 | #define APP_INPUT_SECTION(sect) *(sect) |
| 111 | #endif |
| 112 | |
Yael Avramovich | d5db352 | 2016-07-31 16:16:29 +0300 | [diff] [blame] | 113 | |
Anas Nashif | 77ba3c3 | 2015-10-09 06:20:52 -0400 | [diff] [blame] | 114 | #ifdef CONFIG_X86 /* LINKER FILES: defines used by linker script */ |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 115 | /* Should be moved to linker-common-defs.h */ |
| 116 | #if defined(CONFIG_XIP) |
| 117 | #define ROMABLE_REGION ROM |
| 118 | #else |
| 119 | #define ROMABLE_REGION RAM |
| 120 | #endif |
| 121 | #endif |
| 122 | |
| 123 | /* |
| 124 | * If image is loaded via kexec Linux system call, then program |
| 125 | * headers need to be page aligned. |
| 126 | * This can be done by section page aligning. |
| 127 | */ |
| 128 | #ifdef CONFIG_BOOTLOADER_KEXEC |
| 129 | #define KEXEC_PGALIGN_PAD(x) . = ALIGN(x); |
| 130 | #else |
| 131 | #define KEXEC_PGALIGN_PAD(x) |
| 132 | #endif |
| 133 | |
| 134 | #elif defined(_ASMLANGUAGE) |
Allan Stephens | a860cb7 | 2015-10-14 11:17:20 -0400 | [diff] [blame] | 135 | |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 136 | /* Assembly FILES: declaration defined by the linker script */ |
| 137 | GDATA(__bss_start) |
| 138 | GDATA(__bss_num_words) |
| 139 | #ifdef CONFIG_XIP |
| 140 | GDATA(__data_rom_start) |
| 141 | GDATA(__data_ram_start) |
| 142 | GDATA(__data_num_words) |
| 143 | #endif |
| 144 | |
Allan Stephens | a860cb7 | 2015-10-14 11:17:20 -0400 | [diff] [blame] | 145 | #else /* ! _ASMLANGUAGE */ |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 146 | |
Kumar Gala | 7890816 | 2017-04-19 10:32:08 -0500 | [diff] [blame] | 147 | #include <zephyr/types.h> |
Andrew Boie | 1eaccb0 | 2017-06-14 13:31:11 -0700 | [diff] [blame] | 148 | |
Andrew Boie | bf5228e | 2017-06-19 11:13:19 -0700 | [diff] [blame] | 149 | #ifdef CONFIG_APPLICATION_MEMORY |
Andrew Boie | 3876f53 | 2017-08-01 15:13:44 -0700 | [diff] [blame^] | 150 | /* Memory owned by the application. Start and end will be aligned for memory |
| 151 | * management/protection hardware for the target architecture. |
| 152 | |
| 153 | * The policy for this memory will be to configure all of it as user thread |
| 154 | * accessible. It consists of all non-kernel globals. |
| 155 | */ |
Andrew Boie | bf5228e | 2017-06-19 11:13:19 -0700 | [diff] [blame] | 156 | extern char __app_ram_start[]; |
| 157 | extern char __app_ram_end[]; |
Andrew Boie | 3876f53 | 2017-08-01 15:13:44 -0700 | [diff] [blame^] | 158 | extern char __app_ram_size[]; |
Andrew Boie | bf5228e | 2017-06-19 11:13:19 -0700 | [diff] [blame] | 159 | #endif |
| 160 | |
Andrew Boie | 3876f53 | 2017-08-01 15:13:44 -0700 | [diff] [blame^] | 161 | /* Memory owned by the kernel. Start and end will be aligned for memory |
| 162 | * management/protection hardware for the target architecture.. |
| 163 | * |
| 164 | * Consists of all kernel-side globals, all kernel objects, all thread stacks, |
| 165 | * and all currently unused RAM. If CONFIG_APPLICATION_MEMORY is not enabled, |
| 166 | * has all globals, not just kernel side. |
| 167 | * |
| 168 | * Except for the stack of the currently executing thread, none of this memory |
| 169 | * is normally accessible to user threads unless specifically granted at |
| 170 | * runtime. |
| 171 | */ |
Andrew Boie | bf5228e | 2017-06-19 11:13:19 -0700 | [diff] [blame] | 172 | extern char __kernel_ram_start[]; |
| 173 | extern char __kernel_ram_end[]; |
Andrew Boie | 3876f53 | 2017-08-01 15:13:44 -0700 | [diff] [blame^] | 174 | extern char __kernel_ram_size[]; |
Andrew Boie | bf5228e | 2017-06-19 11:13:19 -0700 | [diff] [blame] | 175 | |
Andrew Boie | 1eaccb0 | 2017-06-14 13:31:11 -0700 | [diff] [blame] | 176 | /* Used by _bss_zero or arch-specific implementation */ |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 177 | extern char __bss_start[]; |
Andrew Boie | ef29812 | 2016-06-30 16:45:08 -0700 | [diff] [blame] | 178 | extern char __bss_end[]; |
Andrew Boie | bf5228e | 2017-06-19 11:13:19 -0700 | [diff] [blame] | 179 | #ifdef CONFIG_APPLICATION_MEMORY |
| 180 | extern char __app_bss_start[]; |
| 181 | extern char __app_bss_end[]; |
| 182 | #endif |
Andrew Boie | 1eaccb0 | 2017-06-14 13:31:11 -0700 | [diff] [blame] | 183 | |
| 184 | /* Used by _data_copy() or arch-specific implementation */ |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 185 | #ifdef CONFIG_XIP |
| 186 | extern char __data_rom_start[]; |
| 187 | extern char __data_ram_start[]; |
Andrew Boie | ef29812 | 2016-06-30 16:45:08 -0700 | [diff] [blame] | 188 | extern char __data_ram_end[]; |
Andrew Boie | bf5228e | 2017-06-19 11:13:19 -0700 | [diff] [blame] | 189 | #ifdef CONFIG_APPLICATION_MEMORY |
| 190 | extern char __app_data_rom_start[]; |
| 191 | extern char __app_data_ram_start[]; |
| 192 | extern char __app_data_ram_end[]; |
| 193 | #endif /* CONFIG_APPLICATION_MEMORY */ |
| 194 | #endif /* CONFIG_XIP */ |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 195 | |
Andrew Boie | efee38d | 2017-07-11 08:58:43 -0700 | [diff] [blame] | 196 | /* Includes text and rodata */ |
Benjamin Walsh | 09303f7 | 2015-09-16 19:14:40 -0400 | [diff] [blame] | 197 | extern char _image_rom_start[]; |
| 198 | extern char _image_rom_end[]; |
Andrew Boie | efee38d | 2017-07-11 08:58:43 -0700 | [diff] [blame] | 199 | extern char _image_rom_size[]; |
| 200 | |
| 201 | /* datas, bss, noinit */ |
Benjamin Walsh | 09303f7 | 2015-09-16 19:14:40 -0400 | [diff] [blame] | 202 | extern char _image_ram_start[]; |
| 203 | extern char _image_ram_end[]; |
Andrew Boie | efee38d | 2017-07-11 08:58:43 -0700 | [diff] [blame] | 204 | |
Benjamin Walsh | c12c234 | 2015-09-21 17:57:39 -0400 | [diff] [blame] | 205 | extern char _image_text_start[]; |
| 206 | extern char _image_text_end[]; |
Benjamin Walsh | 09303f7 | 2015-09-16 19:14:40 -0400 | [diff] [blame] | 207 | |
Andrew Boie | efee38d | 2017-07-11 08:58:43 -0700 | [diff] [blame] | 208 | extern char _image_rodata_start[]; |
| 209 | extern char _image_rodata_end[]; |
| 210 | |
Andrew Boie | 1eaccb0 | 2017-06-14 13:31:11 -0700 | [diff] [blame] | 211 | /* end address of image, used by newlib for the heap */ |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 212 | extern char _end[]; |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 213 | |
| 214 | #endif /* ! _ASMLANGUAGE */ |
| 215 | |
| 216 | #endif /* _LINKERDEFS_H */ |