Zephyr Project API  3.4.0
A Scalable Open Source RTOS
linker-defs.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-2014, Wind River Systems, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7/*
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
17 */
18
19#ifndef ZEPHYR_INCLUDE_LINKER_LINKER_DEFS_H_
20#define ZEPHYR_INCLUDE_LINKER_LINKER_DEFS_H_
21
22#include <zephyr/toolchain.h>
25#include <zephyr/sys/util.h>
26#include <offsets.h>
27
28/* We need to dummy out DT_NODE_HAS_STATUS when building the unittests.
29 * Including devicetree.h would require generating dummy header files
30 * to match what gen_defines creates, so it's easier to just dummy out
31 * DT_NODE_HAS_STATUS.
32 */
33#ifdef ZTEST_UNITTEST
34#define DT_NODE_HAS_STATUS(node, status) 0
35#else
36#include <zephyr/devicetree.h>
37#endif
38
39#ifdef _LINKER
40/*
41 * generate a symbol to mark the start of the objects array for
42 * the specified object and level, then link all of those objects
43 * (sorted by priority). Ensure the objects aren't discarded if there is
44 * no direct reference to them
45 */
46#define CREATE_OBJ_LEVEL(object, level) \
47 __##object##_##level##_start = .; \
48 KEEP(*(SORT(.z_##object##_##level?_*))); \
49 KEEP(*(SORT(.z_##object##_##level??_*)));
50
51/*
52 * link in shell initialization objects for all modules that use shell and
53 * their shell commands are automatically initialized by the kernel.
54 */
55
56#elif defined(_ASMLANGUAGE)
57
58/* Assembly FILES: declaration defined by the linker script */
59GDATA(__bss_start)
60GDATA(__bss_num_words)
61#ifdef CONFIG_XIP
62GDATA(__data_region_load_start)
63GDATA(__data_region_start)
64GDATA(__data_region_num_words)
65#endif
66
67#else /* ! _ASMLANGUAGE */
68
69#include <zephyr/types.h>
70/*
71 * Memory owned by the kernel, to be used as shared memory between
72 * application threads.
73 *
74 * The following are extern symbols from the linker. This enables
75 * the dynamic k_mem_domain and k_mem_partition creation and alignment
76 * to the section produced in the linker.
77
78 * The policy for this memory will be to initially configure all of it as
79 * kernel / supervisor thread accessible.
80 */
81extern char _app_smem_start[];
82extern char _app_smem_end[];
83extern char _app_smem_size[];
84extern char _app_smem_rom_start[];
85extern char _app_smem_num_words[];
86
87#ifdef CONFIG_LINKER_USE_PINNED_SECTION
88extern char _app_smem_pinned_start[];
89extern char _app_smem_pinned_end[];
90extern char _app_smem_pinned_size[];
91extern char _app_smem_pinned_num_words[];
92#endif
93
94/* Memory owned by the kernel. Start and end will be aligned for memory
95 * management/protection hardware for the target architecture.
96 *
97 * Consists of all kernel-side globals, all kernel objects, all thread stacks,
98 * and all currently unused RAM.
99 *
100 * Except for the stack of the currently executing thread, none of this memory
101 * is normally accessible to user threads unless specifically granted at
102 * runtime.
103 */
104extern char __kernel_ram_start[];
105extern char __kernel_ram_end[];
106extern char __kernel_ram_size[];
107
108/* Used by z_bss_zero or arch-specific implementation */
109extern char __bss_start[];
110extern char __bss_end[];
111
112/* Used by z_data_copy() or arch-specific implementation */
113#ifdef CONFIG_XIP
114extern char __data_region_load_start[];
115extern char __data_region_start[];
116extern char __data_region_end[];
117#endif /* CONFIG_XIP */
118
119#ifdef CONFIG_MMU
120/* Virtual addresses of page-aligned kernel image mapped into RAM at boot */
121extern char z_mapped_start[];
122extern char z_mapped_end[];
123#endif /* CONFIG_MMU */
124
125/* Includes text and rodata */
126extern char __rom_region_start[];
127extern char __rom_region_end[];
128extern char __rom_region_size[];
129
130/* Includes all ROMable data, i.e. the size of the output image file. */
131extern char _flash_used[];
132
133/* datas, bss, noinit */
134extern char _image_ram_start[];
135extern char _image_ram_end[];
136
137extern char __text_region_start[];
138extern char __text_region_end[];
139extern char __text_region_size[];
140
141extern char __rodata_region_start[];
142extern char __rodata_region_end[];
143extern char __rodata_region_size[];
144
145extern char _vector_start[];
146extern char _vector_end[];
147
148#ifdef CONFIG_SW_VECTOR_RELAY
149extern char __vector_relay_table[];
150#endif
151
152#ifdef CONFIG_COVERAGE_GCOV
153extern char __gcov_bss_start[];
154extern char __gcov_bss_end[];
155extern char __gcov_bss_size[];
156#endif /* CONFIG_COVERAGE_GCOV */
157
158/* end address of image, used by newlib for the heap */
159extern char _end[];
160
161#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ccm), okay)
162extern char __ccm_data_rom_start[];
163extern char __ccm_start[];
164extern char __ccm_data_start[];
165extern char __ccm_data_end[];
166extern char __ccm_bss_start[];
167extern char __ccm_bss_end[];
168extern char __ccm_noinit_start[];
169extern char __ccm_noinit_end[];
170extern char __ccm_end[];
171#endif
172
173#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay)
174extern char __itcm_start[];
175extern char __itcm_end[];
176extern char __itcm_size[];
177extern char __itcm_load_start[];
178#endif
179
180#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay)
181extern char __dtcm_data_start[];
182extern char __dtcm_data_end[];
183extern char __dtcm_bss_start[];
184extern char __dtcm_bss_end[];
185extern char __dtcm_noinit_start[];
186extern char __dtcm_noinit_end[];
187extern char __dtcm_data_load_start[];
188extern char __dtcm_start[];
189extern char __dtcm_end[];
190#endif
191
192#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ocm), okay)
193extern char __ocm_data_start[];
194extern char __ocm_data_end[];
195extern char __ocm_bss_start[];
196extern char __ocm_bss_end[];
197extern char __ocm_start[];
198extern char __ocm_end[];
199extern char __ocm_size[];
200#endif
201
202/* Used by the Security Attribution Unit to configure the
203 * Non-Secure Callable region.
204 */
205#ifdef CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS
206extern char __sg_start[];
207extern char __sg_end[];
208extern char __sg_size[];
209#endif /* CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS */
210
211/*
212 * Non-cached kernel memory region, currently only available on ARM Cortex-M7
213 * with a MPU. Start and end will be aligned for memory management/protection
214 * hardware for the target architecture.
215 *
216 * All the functions with '__nocache' keyword will be placed into this
217 * section.
218 */
219#ifdef CONFIG_NOCACHE_MEMORY
220extern char _nocache_ram_start[];
221extern char _nocache_ram_end[];
222extern char _nocache_ram_size[];
223#endif /* CONFIG_NOCACHE_MEMORY */
224
225/* Memory owned by the kernel. Start and end will be aligned for memory
226 * management/protection hardware for the target architecture.
227 *
228 * All the functions with '__ramfunc' keyword will be placed into this
229 * section, stored in RAM instead of FLASH.
230 */
231#ifdef CONFIG_ARCH_HAS_RAMFUNC_SUPPORT
232extern char __ramfunc_start[];
233extern char __ramfunc_end[];
234extern char __ramfunc_size[];
235extern char __ramfunc_load_start[];
236#endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */
237
238/* Memory owned by the kernel. Memory region for thread privilege stack buffers,
239 * currently only applicable on ARM Cortex-M architecture when building with
240 * support for User Mode.
241 *
242 * All thread privilege stack buffers will be placed into this section.
243 */
244#ifdef CONFIG_USERSPACE
245extern char z_priv_stacks_ram_start[];
246extern char z_priv_stacks_ram_end[];
247extern char z_user_stacks_start[];
248extern char z_user_stacks_end[];
249extern char z_kobject_data_begin[];
250#endif /* CONFIG_USERSPACE */
251
252#ifdef CONFIG_THREAD_LOCAL_STORAGE
253extern char __tdata_start[];
254extern char __tdata_end[];
255extern char __tdata_size[];
256extern char __tdata_align[];
257extern char __tbss_start[];
258extern char __tbss_end[];
259extern char __tbss_size[];
260extern char __tbss_align[];
261extern char __tls_start[];
262extern char __tls_end[];
263extern char __tls_size[];
264#endif /* CONFIG_THREAD_LOCAL_STORAGE */
265
266#ifdef CONFIG_LINKER_USE_BOOT_SECTION
267/* lnkr_boot_start[] and lnkr_boot_end[]
268 * must encapsulate all the boot sections.
269 */
270extern char lnkr_boot_start[];
271extern char lnkr_boot_end[];
272
273extern char lnkr_boot_text_start[];
274extern char lnkr_boot_text_end[];
275extern char lnkr_boot_text_size[];
276extern char lnkr_boot_data_start[];
277extern char lnkr_boot_data_end[];
278extern char lnkr_boot_data_size[];
279extern char lnkr_boot_rodata_start[];
280extern char lnkr_boot_rodata_end[];
281extern char lnkr_boot_rodata_size[];
282extern char lnkr_boot_bss_start[];
283extern char lnkr_boot_bss_end[];
284extern char lnkr_boot_bss_size[];
285extern char lnkr_boot_noinit_start[];
286extern char lnkr_boot_noinit_end[];
287extern char lnkr_boot_noinit_size[];
288#endif /* CONFIG_LINKER_USE_BOOT_SECTION */
289
290#ifdef CONFIG_LINKER_USE_PINNED_SECTION
291/* lnkr_pinned_start[] and lnkr_pinned_end[] must encapsulate
292 * all the pinned sections as these are used by
293 * the MMU code to mark the physical page frames with
294 * Z_PAGE_FRAME_PINNED.
295 */
296extern char lnkr_pinned_start[];
297extern char lnkr_pinned_end[];
298
299extern char lnkr_pinned_text_start[];
300extern char lnkr_pinned_text_end[];
301extern char lnkr_pinned_text_size[];
302extern char lnkr_pinned_data_start[];
303extern char lnkr_pinned_data_end[];
304extern char lnkr_pinned_data_size[];
305extern char lnkr_pinned_rodata_start[];
306extern char lnkr_pinned_rodata_end[];
307extern char lnkr_pinned_rodata_size[];
308extern char lnkr_pinned_bss_start[];
309extern char lnkr_pinned_bss_end[];
310extern char lnkr_pinned_bss_size[];
311extern char lnkr_pinned_noinit_start[];
312extern char lnkr_pinned_noinit_end[];
313extern char lnkr_pinned_noinit_size[];
314
315__pinned_func
316static inline bool lnkr_is_pinned(uint8_t *addr)
317{
318 if ((addr >= (uint8_t *)lnkr_pinned_start) &&
319 (addr < (uint8_t *)lnkr_pinned_end)) {
320 return true;
321 } else {
322 return false;
323 }
324}
325
326__pinned_func
327static inline bool lnkr_is_region_pinned(uint8_t *addr, size_t sz)
328{
329 if ((addr >= (uint8_t *)lnkr_pinned_start) &&
330 ((addr + sz) < (uint8_t *)lnkr_pinned_end)) {
331 return true;
332 } else {
333 return false;
334 }
335}
336
337#endif /* CONFIG_LINKER_USE_PINNED_SECTION */
338
339#endif /* ! _ASMLANGUAGE */
340
341#endif /* ZEPHYR_INCLUDE_LINKER_LINKER_DEFS_H_ */
Common toolchain abstraction.
Devicetree main header.
Definitions of various linker Sections.
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
Macros to abstract toolchain specific capabilities.
Misc utilities.