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