blob: a939c69d2913fdfc5a6a716491359e2f45f274c8 [file] [log] [blame]
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -07001/*
2 * Copyright (c) 2013-2014, Wind River Systems, Inc.
3 *
David B. Kinderac74d8b2017-01-18 17:01:01 -08004 * SPDX-License-Identifier: Apache-2.0
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -07005 */
6
7/*
Dan Kalowskyda67b292015-10-20 09:42:33 -07008 * 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 Nashifea0d0b22015-07-01 17:22:39 -040017 */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070018
19#ifndef _LINKERDEFS_H
20#define _LINKERDEFS_H
21
22#include <toolchain.h>
Anas Nashif397d29d2017-06-17 11:30:47 -040023#include <linker/sections.h>
Anas Nashif0a4808b2017-10-31 09:30:38 -040024#include <misc/util.h>
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070025
26/* include platform dependent linker-defs */
Anas Nashif77ba3c32015-10-09 06:20:52 -040027#ifdef CONFIG_X86
Andrew Boie327017f2016-10-21 09:29:09 -070028/* Nothing yet to include */
Anas Nashif274622e2015-06-05 22:27:08 -040029#elif defined(CONFIG_ARM)
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070030/* Nothing yet to include */
Anas Nashiff2520f82015-06-05 22:27:49 -040031#elif defined(CONFIG_ARC)
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070032/* Nothing yet to include */
Andrew Boie94338952016-04-21 14:47:09 -070033#elif defined(CONFIG_NIOS2)
34/* Nothing yet to include */
Jean-Paul Etiennecd83e852017-01-11 00:24:30 +010035#elif defined(CONFIG_RISCV32)
36/* Nothing yet to include */
Mazen NEIFER969f0002017-01-25 22:26:58 +010037#elif defined(CONFIG_XTENSA)
38/* Nothing yet to include */
Alberto Escolar Piedras76f764412017-10-03 16:31:55 +020039#elif defined(CONFIG_ARCH_POSIX)
40/* Nothing yet to include */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070041#else
42#error Arch not supported.
43#endif
44
45#ifdef _LINKER
Allan Stephensa860cb72015-10-14 11:17:20 -040046
Jithu Joseph592882e2016-04-08 12:38:57 -070047
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 Walshf6ca7de2016-11-08 10:36:50 -050054#define DEVICE_COUNT \
55 ((__device_init_end - __device_init_start) / _DEVICE_STRUCT_SIZE)
Jithu Joseph592882e2016-04-08 12:38:57 -070056#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 Stephensa860cb72015-10-14 11:17:20 -040066/*
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 Boie0b474ee2016-11-08 11:06:55 -080084 __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 Joseph592882e2016-04-08 12:38:57 -070089 __device_init_end = .; \
90 DEVICE_BUSY_BITFIELD() \
Allan Stephensa860cb72015-10-14 11:17:20 -040091
Dmitriy Korovkinfb6de2d2015-10-26 15:40:46 -040092
93/* define a section for undefined device initialization levels */
94#define DEVICE_INIT_UNDEFINED_SECTION() \
95 KEEP(*(SORT(.init_[_A-Z0-9]*))) \
96
Yael Avramovichd5db3522016-07-31 16:16:29 +030097/*
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 Nashif8d193152018-01-15 11:10:09 -0500102#define SHELL_INIT_SECTIONS() \
103 __shell_module_start = .; \
104 KEEP(*(".shell_module_*")); \
Anas Nashifd7777d32018-01-15 11:15:47 -0500105 __shell_module_end = .; \
106 __shell_cmd_start = .; \
107 KEEP(*(".shell_cmd_*")); \
108 __shell_cmd_end = .; \
Yael Avramovichd5db3522016-07-31 16:16:29 +0300109
Andrew Boief1ae5d42017-06-19 10:20:41 -0700110#ifdef CONFIG_APPLICATION_MEMORY
Anas Nashif0a4808b2017-10-31 09:30:38 -0400111
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øe1c2de102018-01-02 15:54:16 +0100121#define X(i, j) KERNEL_OBJECT_FILE_##i (j)
122#define Y(i, j) KERNEL_OBJECT_FILE_##i
Anas Nashif0a4808b2017-10-31 09:30:38 -0400123
124#define KERNEL_INPUT_SECTION(sect) \
125 UTIL_LISTIFY(NUM_KERNEL_OBJECT_FILES, X, sect)
Andrew Boie5f5f7c52017-08-01 14:43:24 -0700126#define APP_INPUT_SECTION(sect) \
Anas Nashif0a4808b2017-10-31 09:30:38 -0400127 *(EXCLUDE_FILE (UTIL_LISTIFY(NUM_KERNEL_OBJECT_FILES, Y, ~)) sect)
128
Andrew Boief1ae5d42017-06-19 10:20:41 -0700129#else
130#define KERNEL_INPUT_SECTION(sect) *(sect)
131#define APP_INPUT_SECTION(sect) *(sect)
132#endif
133
Yael Avramovichd5db3522016-07-31 16:16:29 +0300134
Anas Nashif77ba3c32015-10-09 06:20:52 -0400135#ifdef CONFIG_X86 /* LINKER FILES: defines used by linker script */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700136/* 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 Stephensa860cb72015-10-14 11:17:20 -0400156
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700157/* Assembly FILES: declaration defined by the linker script */
158GDATA(__bss_start)
159GDATA(__bss_num_words)
160#ifdef CONFIG_XIP
161GDATA(__data_rom_start)
162GDATA(__data_ram_start)
163GDATA(__data_num_words)
164#endif
165
Allan Stephensa860cb72015-10-14 11:17:20 -0400166#else /* ! _ASMLANGUAGE */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700167
Kumar Gala78908162017-04-19 10:32:08 -0500168#include <zephyr/types.h>
Andrew Boie1eaccb02017-06-14 13:31:11 -0700169
Andrew Boiebf5228e2017-06-19 11:13:19 -0700170#ifdef CONFIG_APPLICATION_MEMORY
Andrew Boie3876f532017-08-01 15:13:44 -0700171/* 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 Boiebf5228e2017-06-19 11:13:19 -0700177extern char __app_ram_start[];
178extern char __app_ram_end[];
Andrew Boie3876f532017-08-01 15:13:44 -0700179extern char __app_ram_size[];
Andrew Boiebf5228e2017-06-19 11:13:19 -0700180#endif
181
Andrew Boie3876f532017-08-01 15:13:44 -0700182/* 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 Boiebf5228e2017-06-19 11:13:19 -0700193extern char __kernel_ram_start[];
194extern char __kernel_ram_end[];
Andrew Boie3876f532017-08-01 15:13:44 -0700195extern char __kernel_ram_size[];
Andrew Boiebf5228e2017-06-19 11:13:19 -0700196
Andrew Boie1eaccb02017-06-14 13:31:11 -0700197/* Used by _bss_zero or arch-specific implementation */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700198extern char __bss_start[];
Andrew Boieef298122016-06-30 16:45:08 -0700199extern char __bss_end[];
Andrew Boiebf5228e2017-06-19 11:13:19 -0700200#ifdef CONFIG_APPLICATION_MEMORY
201extern char __app_bss_start[];
202extern char __app_bss_end[];
203#endif
Andrew Boie1eaccb02017-06-14 13:31:11 -0700204
205/* Used by _data_copy() or arch-specific implementation */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700206#ifdef CONFIG_XIP
207extern char __data_rom_start[];
208extern char __data_ram_start[];
Andrew Boieef298122016-06-30 16:45:08 -0700209extern char __data_ram_end[];
Andrew Boiebf5228e2017-06-19 11:13:19 -0700210#ifdef CONFIG_APPLICATION_MEMORY
211extern char __app_data_rom_start[];
212extern char __app_data_ram_start[];
213extern char __app_data_ram_end[];
214#endif /* CONFIG_APPLICATION_MEMORY */
215#endif /* CONFIG_XIP */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700216
Andrew Boieefee38d2017-07-11 08:58:43 -0700217/* Includes text and rodata */
Benjamin Walsh09303f72015-09-16 19:14:40 -0400218extern char _image_rom_start[];
219extern char _image_rom_end[];
Andrew Boieefee38d2017-07-11 08:58:43 -0700220extern char _image_rom_size[];
221
222/* datas, bss, noinit */
Benjamin Walsh09303f72015-09-16 19:14:40 -0400223extern char _image_ram_start[];
224extern char _image_ram_end[];
Andrew Boieefee38d2017-07-11 08:58:43 -0700225
Benjamin Walshc12c2342015-09-21 17:57:39 -0400226extern char _image_text_start[];
227extern char _image_text_end[];
Benjamin Walsh09303f72015-09-16 19:14:40 -0400228
Andrew Boieefee38d2017-07-11 08:58:43 -0700229extern char _image_rodata_start[];
230extern char _image_rodata_end[];
231
Xiaorui Hueb48a0a2017-06-23 11:02:50 +0800232extern char _vector_start[];
233extern char _vector_end[];
234
Andrew Boie1eaccb02017-06-14 13:31:11 -0700235/* end address of image, used by newlib for the heap */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700236extern char _end[];
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700237
Erwin Rol581446d2017-10-05 01:20:21 +0200238#ifdef CONFIG_CCM_BASE_ADDRESS
239extern char __ccm_data_rom_start[];
240extern char __ccm_start[];
241extern char __ccm_data_start[];
242extern char __ccm_data_end[];
243extern char __ccm_bss_start[];
244extern char __ccm_bss_end[];
245extern char __ccm_noinit_start[];
246extern char __ccm_noinit_end[];
247extern char __ccm_end[];
248#endif /* CONFIG_CCM_BASE_ADDRESS */
249
250
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700251#endif /* ! _ASMLANGUAGE */
252
253#endif /* _LINKERDEFS_H */