Zephyr Project API 4.2.1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
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 <zephyr/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. These are undefined at the end of the file.
32 */
33#ifdef ZTEST_UNITTEST
34#define DT_NODE_HAS_STATUS(node, status) 0
35#define DT_NODE_HAS_STATUS_OKAY(node) 0
36#else
37#include <zephyr/devicetree.h>
38#endif
39
40/* The GCC for Renesas RX processors adds leading underscores to C-symbols
41 * by default. As a workaroud for symbols defined in linker scripts to be
42 * available in C code, an alias with a leading underscore has to be provided.
43 */
44#if defined(CONFIG_RX)
45#define PLACE_SYMBOL_HERE(symbol) \
46 symbol = .; \
47 PROVIDE(_CONCAT(_, symbol) = symbol)
48#else
49#define PLACE_SYMBOL_HERE(symbol) symbol = .
50#endif
51
52#ifdef _LINKER
53/*
54 * generate a symbol to mark the start of the objects array for
55 * the specified object and level, then link all of those objects
56 * (sorted by priority). Ensure the objects aren't discarded if there is
57 * no direct reference to them
58 */
59
60/* clang-format off */
61#define CREATE_OBJ_LEVEL(object, level) \
62 PLACE_SYMBOL_HERE(__##object##_##level##_start);\
63 KEEP(*(SORT(.z_##object##_##level##_P_?_*))); \
64 KEEP(*(SORT(.z_##object##_##level##_P_??_*))); \
65 KEEP(*(SORT(.z_##object##_##level##_P_???_*)));
66/* clang-format on */
67
68/*
69 * link in shell initialization objects for all modules that use shell and
70 * their shell commands are automatically initialized by the kernel.
71 */
72
73#elif defined(_ASMLANGUAGE)
74
75/* Assembly FILES: declaration defined by the linker script */
76GDATA(__bss_start)
77GDATA(__bss_num_words)
78#ifdef CONFIG_XIP
79GDATA(__data_region_load_start)
80GDATA(__data_region_start)
81GDATA(__data_region_num_words)
82#endif
83
84#else /* ! _ASMLANGUAGE */
85
86#include <zephyr/types.h>
87/*
88 * Memory owned by the kernel, to be used as shared memory between
89 * application threads.
90 *
91 * The following are extern symbols from the linker. This enables
92 * the dynamic k_mem_domain and k_mem_partition creation and alignment
93 * to the section produced in the linker.
94
95 * The policy for this memory will be to initially configure all of it as
96 * kernel / supervisor thread accessible.
97 */
98extern char _app_smem_start[];
99extern char _app_smem_end[];
100extern char _app_smem_size[];
101extern char _app_smem_rom_start[];
102extern char _app_smem_num_words[];
103
104#ifdef CONFIG_LINKER_USE_PINNED_SECTION
105extern char _app_smem_pinned_start[];
106extern char _app_smem_pinned_end[];
107extern char _app_smem_pinned_size[];
108extern char _app_smem_pinned_num_words[];
109#endif
110
111/* Memory owned by the kernel. Start and end will be aligned for memory
112 * management/protection hardware for the target architecture.
113 *
114 * Consists of all kernel-side globals, all kernel objects, all thread stacks,
115 * and all currently unused RAM.
116 *
117 * Except for the stack of the currently executing thread, none of this memory
118 * is normally accessible to user threads unless specifically granted at
119 * runtime.
120 */
121extern char __kernel_ram_start[];
122extern char __kernel_ram_end[];
123extern char __kernel_ram_size[];
124
125/* Used by z_bss_zero or arch-specific implementation */
126extern char __bss_start[];
127extern char __bss_end[];
128
129/* Used by z_data_copy() or arch-specific implementation */
130#ifdef CONFIG_XIP
131extern char __data_region_load_start[];
132extern char __data_region_start[];
133extern char __data_region_end[];
134#endif /* CONFIG_XIP */
135
136#ifdef CONFIG_MMU
137/* Virtual addresses of page-aligned kernel image mapped into RAM at boot */
138extern char z_mapped_start[];
139extern char z_mapped_end[];
140#endif /* CONFIG_MMU */
141
142/* Includes text and rodata */
143extern char __rom_region_start[];
144extern char __rom_region_end[];
145extern char __rom_region_size[];
146
147/* Includes all ROMable data, i.e. the size of the output image file. */
148extern char _flash_used[];
149
150/* datas, bss, noinit */
151extern char _image_ram_start[];
152extern char _image_ram_end[];
153extern char _image_ram_size[];
154
155extern char __text_region_start[];
156extern char __text_region_end[];
157extern char __text_region_size[];
158
159extern char __rodata_region_start[];
160extern char __rodata_region_end[];
161extern char __rodata_region_size[];
162
163extern char _vector_start[];
164extern char _vector_end[];
165
166#ifdef CONFIG_SW_VECTOR_RELAY
167extern char __vector_relay_table[];
168#endif
169
170#ifdef CONFIG_SRAM_VECTOR_TABLE
171extern char _sram_vector_start[];
172extern char _sram_vector_end[];
173extern char _sram_vector_size[];
174#endif
175
176#ifdef CONFIG_COVERAGE_GCOV
177extern char __gcov_bss_start[];
178extern char __gcov_bss_end[];
179extern char __gcov_bss_size[];
180#endif /* CONFIG_COVERAGE_GCOV */
181
182/* end address of image, used by newlib for the heap */
183extern char _end[];
184
185#if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ccm)))
186extern char __ccm_data_load_start[];
187extern char __ccm_start[];
188extern char __ccm_data_start[];
189extern char __ccm_data_end[];
190extern char __ccm_bss_start[];
191extern char __ccm_bss_end[];
192extern char __ccm_noinit_start[];
193extern char __ccm_noinit_end[];
194extern char __ccm_end[];
195#endif
196
197#if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_itcm)))
198extern char __itcm_start[];
199extern char __itcm_end[];
200extern char __itcm_size[];
201extern char __itcm_load_start[];
202#endif
203
204#if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)))
205extern char __dtcm_data_start[];
206extern char __dtcm_data_end[];
207extern char __dtcm_bss_start[];
208extern char __dtcm_bss_end[];
209extern char __dtcm_noinit_start[];
210extern char __dtcm_noinit_end[];
211extern char __dtcm_data_load_start[];
212extern char __dtcm_start[];
213extern char __dtcm_end[];
214#endif
215
216#if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ocm)))
217extern char __ocm_data_start[];
218extern char __ocm_data_end[];
219extern char __ocm_bss_start[];
220extern char __ocm_bss_end[];
221extern char __ocm_start[];
222extern char __ocm_end[];
223extern char __ocm_size[];
224#endif
225
226/* Used by the Security Attribution Unit to configure the
227 * Non-Secure Callable region.
228 */
229#ifdef CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS
230extern char __sg_start[];
231extern char __sg_end[];
232extern char __sg_size[];
233#endif /* CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS */
234
235/*
236 * Non-cached kernel memory region, currently only available on ARM Cortex-M7
237 * with a MPU. Start and end will be aligned for memory management/protection
238 * hardware for the target architecture.
239 *
240 * All the variables with '__nocache' keyword will be placed into the nocache
241 * section, variables with '__nocache_load' keyword will be placed into the
242 * nocache section that is loaded from ROM.
243 */
244#ifdef CONFIG_NOCACHE_MEMORY
245extern char _nocache_ram_start[];
246extern char _nocache_ram_end[];
247extern char _nocache_ram_size[];
248extern char _nocache_noload_ram_start[];
249extern char _nocache_noload_ram_end[];
250extern char _nocache_noload_ram_size[];
251extern char _nocache_load_ram_start[];
252extern char _nocache_load_ram_end[];
253extern char _nocache_load_ram_size[];
254extern char _nocache_load_rom_start[];
255#endif /* CONFIG_NOCACHE_MEMORY */
256
257/* Memory owned by the kernel. Start and end will be aligned for memory
258 * management/protection hardware for the target architecture.
259 *
260 * All the functions with '__ramfunc' keyword will be placed into this
261 * section, stored in RAM instead of FLASH.
262 */
263#ifdef CONFIG_ARCH_HAS_RAMFUNC_SUPPORT
264extern char __ramfunc_region_start[];
265extern char __ramfunc_start[];
266extern char __ramfunc_end[];
267extern char __ramfunc_size[];
268extern char __ramfunc_load_start[];
269#endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */
270
271/* Memory owned by the kernel. Memory region for thread privilege stack buffers,
272 * currently only applicable on ARM Cortex-M architecture when building with
273 * support for User Mode.
274 *
275 * All thread privilege stack buffers will be placed into this section.
276 */
277#ifdef CONFIG_USERSPACE
278extern char z_priv_stacks_ram_start[];
279extern char z_priv_stacks_ram_end[];
280extern char z_user_stacks_start[];
281extern char z_user_stacks_end[];
282extern char z_kobject_data_begin[];
283#endif /* CONFIG_USERSPACE */
284
285#ifdef CONFIG_THREAD_LOCAL_STORAGE
286extern char __tdata_start[];
287extern char __tdata_end[];
288extern char __tdata_size[];
289extern char __tdata_align[];
290extern char __tbss_start[];
291extern char __tbss_end[];
292extern char __tbss_size[];
293extern char __tbss_align[];
294extern char __tls_start[];
295extern char __tls_end[];
296extern char __tls_size[];
297#endif /* CONFIG_THREAD_LOCAL_STORAGE */
298
299#ifdef CONFIG_LINKER_USE_BOOT_SECTION
300/* lnkr_boot_start[] and lnkr_boot_end[]
301 * must encapsulate all the boot sections.
302 */
303extern char lnkr_boot_start[];
304extern char lnkr_boot_end[];
305
306extern char lnkr_boot_text_start[];
307extern char lnkr_boot_text_end[];
308extern char lnkr_boot_text_size[];
309extern char lnkr_boot_data_start[];
310extern char lnkr_boot_data_end[];
311extern char lnkr_boot_data_size[];
312extern char lnkr_boot_rodata_start[];
313extern char lnkr_boot_rodata_end[];
314extern char lnkr_boot_rodata_size[];
315extern char lnkr_boot_bss_start[];
316extern char lnkr_boot_bss_end[];
317extern char lnkr_boot_bss_size[];
318extern char lnkr_boot_noinit_start[];
319extern char lnkr_boot_noinit_end[];
320extern char lnkr_boot_noinit_size[];
321#endif /* CONFIG_LINKER_USE_BOOT_SECTION */
322
323#ifdef CONFIG_LINKER_USE_PINNED_SECTION
324/* lnkr_pinned_start[] and lnkr_pinned_end[] must encapsulate
325 * all the pinned sections as these are used by
326 * the MMU code to mark the physical page frames with
327 * K_MEM_PAGE_FRAME_PINNED.
328 */
329extern char lnkr_pinned_start[];
330extern char lnkr_pinned_end[];
331
332extern char lnkr_pinned_text_start[];
333extern char lnkr_pinned_text_end[];
334extern char lnkr_pinned_text_size[];
335extern char lnkr_pinned_data_start[];
336extern char lnkr_pinned_data_end[];
337extern char lnkr_pinned_data_size[];
338extern char lnkr_pinned_rodata_start[];
339extern char lnkr_pinned_rodata_end[];
340extern char lnkr_pinned_rodata_size[];
341extern char lnkr_pinned_bss_start[];
342extern char lnkr_pinned_bss_end[];
343extern char lnkr_pinned_bss_size[];
344extern char lnkr_pinned_noinit_start[];
345extern char lnkr_pinned_noinit_end[];
346extern char lnkr_pinned_noinit_size[];
347
348__pinned_func
349static inline bool lnkr_is_pinned(uint8_t *addr)
350{
351 if ((addr >= (uint8_t *)lnkr_pinned_start) &&
352 (addr < (uint8_t *)lnkr_pinned_end)) {
353 return true;
354 } else {
355 return false;
356 }
357}
358
359__pinned_func
360static inline bool lnkr_is_region_pinned(uint8_t *addr, size_t sz)
361{
362 if ((addr >= (uint8_t *)lnkr_pinned_start) &&
363 ((addr + sz) < (uint8_t *)lnkr_pinned_end)) {
364 return true;
365 } else {
366 return false;
367 }
368}
369
370#endif /* CONFIG_LINKER_USE_PINNED_SECTION */
371
372#ifdef CONFIG_LINKER_USE_ONDEMAND_SECTION
373/* lnkr_ondemand_start[] and lnkr_ondemand_end[] must encapsulate
374 * all the on-demand sections as these are used by
375 * the MMU code to mark the virtual pages with the appropriate backing store
376 * location token to have them be paged in on demand.
377 */
378extern char lnkr_ondemand_start[];
379extern char lnkr_ondemand_end[];
380extern char lnkr_ondemand_load_start[];
381
382extern char lnkr_ondemand_text_start[];
383extern char lnkr_ondemand_text_end[];
384extern char lnkr_ondemand_text_size[];
385extern char lnkr_ondemand_rodata_start[];
386extern char lnkr_ondemand_rodata_end[];
387extern char lnkr_ondemand_rodata_size[];
388
389#endif /* CONFIG_LINKER_USE_ONDEMAND_SECTION */
390#endif /* ! _ASMLANGUAGE */
391
392#ifdef ZTEST_UNITTEST
393#undef DT_NODE_HAS_STATUS
394#undef DT_NODE_HAS_STATUS_OKAY
395#endif
396
397#endif /* ZEPHYR_INCLUDE_LINKER_LINKER_DEFS_H_ */
Devicetree main header.
Common toolchain abstraction.
Definitions of various linker Sections.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Misc utilities.
Macros to abstract toolchain specific capabilities.