blob: 49a3a635e4f9de25af850628f0b7d7e38c8fa25a [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>
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070024
25/* include platform dependent linker-defs */
Anas Nashif77ba3c32015-10-09 06:20:52 -040026#ifdef CONFIG_X86
Andrew Boie327017f2016-10-21 09:29:09 -070027/* Nothing yet to include */
Anas Nashif274622e2015-06-05 22:27:08 -040028#elif defined(CONFIG_ARM)
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070029/* Nothing yet to include */
Anas Nashiff2520f82015-06-05 22:27:49 -040030#elif defined(CONFIG_ARC)
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070031/* Nothing yet to include */
Andrew Boie94338952016-04-21 14:47:09 -070032#elif defined(CONFIG_NIOS2)
33/* Nothing yet to include */
Jean-Paul Etiennecd83e852017-01-11 00:24:30 +010034#elif defined(CONFIG_RISCV32)
35/* Nothing yet to include */
Mazen NEIFER969f0002017-01-25 22:26:58 +010036#elif defined(CONFIG_XTENSA)
37/* Nothing yet to include */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070038#else
39#error Arch not supported.
40#endif
41
42#ifdef _LINKER
Allan Stephensa860cb72015-10-14 11:17:20 -040043
Jithu Joseph592882e2016-04-08 12:38:57 -070044
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 Walshf6ca7de2016-11-08 10:36:50 -050051#define DEVICE_COUNT \
52 ((__device_init_end - __device_init_start) / _DEVICE_STRUCT_SIZE)
Jithu Joseph592882e2016-04-08 12:38:57 -070053#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 Stephensa860cb72015-10-14 11:17:20 -040063/*
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 Boie0b474ee2016-11-08 11:06:55 -080081 __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 Joseph592882e2016-04-08 12:38:57 -070086 __device_init_end = .; \
87 DEVICE_BUSY_BITFIELD() \
Allan Stephensa860cb72015-10-14 11:17:20 -040088
Dmitriy Korovkinfb6de2d2015-10-26 15:40:46 -040089
90/* define a section for undefined device initialization levels */
91#define DEVICE_INIT_UNDEFINED_SECTION() \
92 KEEP(*(SORT(.init_[_A-Z0-9]*))) \
93
Yael Avramovichd5db3522016-07-31 16:16:29 +030094/*
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 Boief1ae5d42017-06-19 10:20:41 -0700104#ifdef CONFIG_APPLICATION_MEMORY
105#define KERNEL_INPUT_SECTION(sect) libzephyr.a (sect) kernel/lib.a (sect)
Andrew Boie5f5f7c52017-08-01 14:43:24 -0700106#define APP_INPUT_SECTION(sect) \
107 *(EXCLUDE_FILE (*libzephyr.a *kernel/lib.a) sect)
Andrew Boief1ae5d42017-06-19 10:20:41 -0700108#else
109#define KERNEL_INPUT_SECTION(sect) *(sect)
110#define APP_INPUT_SECTION(sect) *(sect)
111#endif
112
Yael Avramovichd5db3522016-07-31 16:16:29 +0300113
Anas Nashif77ba3c32015-10-09 06:20:52 -0400114#ifdef CONFIG_X86 /* LINKER FILES: defines used by linker script */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700115/* 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 Stephensa860cb72015-10-14 11:17:20 -0400135
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700136/* Assembly FILES: declaration defined by the linker script */
137GDATA(__bss_start)
138GDATA(__bss_num_words)
139#ifdef CONFIG_XIP
140GDATA(__data_rom_start)
141GDATA(__data_ram_start)
142GDATA(__data_num_words)
143#endif
144
Allan Stephensa860cb72015-10-14 11:17:20 -0400145#else /* ! _ASMLANGUAGE */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700146
Kumar Gala78908162017-04-19 10:32:08 -0500147#include <zephyr/types.h>
Andrew Boie1eaccb02017-06-14 13:31:11 -0700148
Andrew Boiebf5228e2017-06-19 11:13:19 -0700149#ifdef CONFIG_APPLICATION_MEMORY
Andrew Boie3876f532017-08-01 15:13:44 -0700150/* 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 Boiebf5228e2017-06-19 11:13:19 -0700156extern char __app_ram_start[];
157extern char __app_ram_end[];
Andrew Boie3876f532017-08-01 15:13:44 -0700158extern char __app_ram_size[];
Andrew Boiebf5228e2017-06-19 11:13:19 -0700159#endif
160
Andrew Boie3876f532017-08-01 15:13:44 -0700161/* 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 Boiebf5228e2017-06-19 11:13:19 -0700172extern char __kernel_ram_start[];
173extern char __kernel_ram_end[];
Andrew Boie3876f532017-08-01 15:13:44 -0700174extern char __kernel_ram_size[];
Andrew Boiebf5228e2017-06-19 11:13:19 -0700175
Andrew Boie1eaccb02017-06-14 13:31:11 -0700176/* Used by _bss_zero or arch-specific implementation */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700177extern char __bss_start[];
Andrew Boieef298122016-06-30 16:45:08 -0700178extern char __bss_end[];
Andrew Boiebf5228e2017-06-19 11:13:19 -0700179#ifdef CONFIG_APPLICATION_MEMORY
180extern char __app_bss_start[];
181extern char __app_bss_end[];
182#endif
Andrew Boie1eaccb02017-06-14 13:31:11 -0700183
184/* Used by _data_copy() or arch-specific implementation */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700185#ifdef CONFIG_XIP
186extern char __data_rom_start[];
187extern char __data_ram_start[];
Andrew Boieef298122016-06-30 16:45:08 -0700188extern char __data_ram_end[];
Andrew Boiebf5228e2017-06-19 11:13:19 -0700189#ifdef CONFIG_APPLICATION_MEMORY
190extern char __app_data_rom_start[];
191extern char __app_data_ram_start[];
192extern char __app_data_ram_end[];
193#endif /* CONFIG_APPLICATION_MEMORY */
194#endif /* CONFIG_XIP */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700195
Andrew Boieefee38d2017-07-11 08:58:43 -0700196/* Includes text and rodata */
Benjamin Walsh09303f72015-09-16 19:14:40 -0400197extern char _image_rom_start[];
198extern char _image_rom_end[];
Andrew Boieefee38d2017-07-11 08:58:43 -0700199extern char _image_rom_size[];
200
201/* datas, bss, noinit */
Benjamin Walsh09303f72015-09-16 19:14:40 -0400202extern char _image_ram_start[];
203extern char _image_ram_end[];
Andrew Boieefee38d2017-07-11 08:58:43 -0700204
Benjamin Walshc12c2342015-09-21 17:57:39 -0400205extern char _image_text_start[];
206extern char _image_text_end[];
Benjamin Walsh09303f72015-09-16 19:14:40 -0400207
Andrew Boieefee38d2017-07-11 08:58:43 -0700208extern char _image_rodata_start[];
209extern char _image_rodata_end[];
210
Andrew Boie1eaccb02017-06-14 13:31:11 -0700211/* end address of image, used by newlib for the heap */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700212extern char _end[];
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -0700213
214#endif /* ! _ASMLANGUAGE */
215
216#endif /* _LINKERDEFS_H */