Zephyr API Documentation 4.3.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 arch_bss_zero or arch-specific implementation */
135extern char __bss_start[];
136extern char __bss_end[];
137
138/* Used by arch_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_itcm)))
195extern char __itcm_start[];
196extern char __itcm_end[];
197extern char __itcm_size[];
198extern char __itcm_load_start[];
199#endif
200
201#if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)))
202extern char __dtcm_data_start[];
203extern char __dtcm_data_end[];
204extern char __dtcm_bss_start[];
205extern char __dtcm_bss_end[];
206extern char __dtcm_noinit_start[];
207extern char __dtcm_noinit_end[];
208extern char __dtcm_data_load_start[];
209extern char __dtcm_start[];
210extern char __dtcm_end[];
211#endif
212
213#if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ocm)))
214extern char __ocm_data_start[];
215extern char __ocm_data_end[];
216extern char __ocm_bss_start[];
217extern char __ocm_bss_end[];
218extern char __ocm_start[];
219extern char __ocm_end[];
220extern char __ocm_size[];
221#endif
222
223/* Used by the Security Attribution Unit to configure the
224 * Non-Secure Callable region.
225 */
226#ifdef CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS
227extern char __sg_start[];
228extern char __sg_end[];
229extern char __sg_size[];
230#endif /* CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS */
231
232/*
233 * Non-cached kernel memory region, currently only available on ARM Cortex-M7
234 * with a MPU. Start and end will be aligned for memory management/protection
235 * hardware for the target architecture.
236 *
237 * All the variables with '__nocache' keyword will be placed into the nocache
238 * section, variables with '__nocache_load' keyword will be placed into the
239 * nocache section that is loaded from ROM.
240 */
241#ifdef CONFIG_NOCACHE_MEMORY
242extern char _nocache_ram_start[];
243extern char _nocache_ram_end[];
244extern char _nocache_ram_size[];
245extern char _nocache_noload_ram_start[];
246extern char _nocache_noload_ram_end[];
247extern char _nocache_noload_ram_size[];
248extern char _nocache_load_ram_start[];
249extern char _nocache_load_ram_end[];
250extern char _nocache_load_ram_size[];
251extern char _nocache_load_rom_start[];
252#endif /* CONFIG_NOCACHE_MEMORY */
253
254/* Memory owned by the kernel. Start and end will be aligned for memory
255 * management/protection hardware for the target architecture.
256 *
257 * All the functions with '__ramfunc' keyword will be placed into this
258 * section, stored in RAM instead of FLASH.
259 */
260#ifdef CONFIG_ARCH_HAS_RAMFUNC_SUPPORT
261extern char __ramfunc_region_start[];
262extern char __ramfunc_start[];
263extern char __ramfunc_end[];
264extern char __ramfunc_size[];
265extern char __ramfunc_load_start[];
266#endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */
267
268/* Memory owned by the kernel. Memory region for thread privilege stack buffers,
269 * currently only applicable on ARM Cortex-M architecture when building with
270 * support for User Mode.
271 *
272 * All thread privilege stack buffers will be placed into this section.
273 */
274#ifdef CONFIG_USERSPACE
275extern char z_priv_stacks_ram_start[];
276extern char z_priv_stacks_ram_end[];
277extern char z_user_stacks_start[];
278extern char z_user_stacks_end[];
279extern char z_kobject_data_begin[];
280#endif /* CONFIG_USERSPACE */
281
282#ifdef CONFIG_THREAD_LOCAL_STORAGE
283extern char __tdata_start[];
284extern char __tdata_end[];
285extern char __tdata_size[];
286extern char __tdata_align[];
287extern char __tbss_start[];
288extern char __tbss_end[];
289extern char __tbss_size[];
290extern char __tbss_align[];
291extern char __tls_start[];
292extern char __tls_end[];
293extern char __tls_size[];
294#endif /* CONFIG_THREAD_LOCAL_STORAGE */
295
296#ifdef CONFIG_LINKER_USE_BOOT_SECTION
297/* lnkr_boot_start[] and lnkr_boot_end[]
298 * must encapsulate all the boot sections.
299 */
300extern char lnkr_boot_start[];
301extern char lnkr_boot_end[];
302
303extern char lnkr_boot_text_start[];
304extern char lnkr_boot_text_end[];
305extern char lnkr_boot_text_size[];
306extern char lnkr_boot_data_start[];
307extern char lnkr_boot_data_end[];
308extern char lnkr_boot_data_size[];
309extern char lnkr_boot_rodata_start[];
310extern char lnkr_boot_rodata_end[];
311extern char lnkr_boot_rodata_size[];
312extern char lnkr_boot_bss_start[];
313extern char lnkr_boot_bss_end[];
314extern char lnkr_boot_bss_size[];
315extern char lnkr_boot_noinit_start[];
316extern char lnkr_boot_noinit_end[];
317extern char lnkr_boot_noinit_size[];
318#endif /* CONFIG_LINKER_USE_BOOT_SECTION */
319
320#ifdef CONFIG_LINKER_USE_PINNED_SECTION
321/* lnkr_pinned_start[] and lnkr_pinned_end[] must encapsulate
322 * all the pinned sections as these are used by
323 * the MMU code to mark the physical page frames with
324 * K_MEM_PAGE_FRAME_PINNED.
325 */
326extern char lnkr_pinned_start[];
327extern char lnkr_pinned_end[];
328
329extern char lnkr_pinned_text_start[];
330extern char lnkr_pinned_text_end[];
331extern char lnkr_pinned_text_size[];
332extern char lnkr_pinned_data_start[];
333extern char lnkr_pinned_data_end[];
334extern char lnkr_pinned_data_size[];
335extern char lnkr_pinned_rodata_start[];
336extern char lnkr_pinned_rodata_end[];
337extern char lnkr_pinned_rodata_size[];
338extern char lnkr_pinned_bss_start[];
339extern char lnkr_pinned_bss_end[];
340extern char lnkr_pinned_bss_size[];
341extern char lnkr_pinned_noinit_start[];
342extern char lnkr_pinned_noinit_end[];
343extern char lnkr_pinned_noinit_size[];
344
345__pinned_func
346static inline bool lnkr_is_pinned(uint8_t *addr)
347{
348 if ((addr >= (uint8_t *)lnkr_pinned_start) &&
349 (addr < (uint8_t *)lnkr_pinned_end)) {
350 return true;
351 } else {
352 return false;
353 }
354}
355
356__pinned_func
357static inline bool lnkr_is_region_pinned(uint8_t *addr, size_t sz)
358{
359 if ((addr >= (uint8_t *)lnkr_pinned_start) &&
360 ((addr + sz) < (uint8_t *)lnkr_pinned_end)) {
361 return true;
362 } else {
363 return false;
364 }
365}
366
367#endif /* CONFIG_LINKER_USE_PINNED_SECTION */
368
369#ifdef CONFIG_LINKER_USE_ONDEMAND_SECTION
370/* lnkr_ondemand_start[] and lnkr_ondemand_end[] must encapsulate
371 * all the on-demand sections as these are used by
372 * the MMU code to mark the virtual pages with the appropriate backing store
373 * location token to have them be paged in on demand.
374 */
375extern char lnkr_ondemand_start[];
376extern char lnkr_ondemand_end[];
377extern char lnkr_ondemand_load_start[];
378
379extern char lnkr_ondemand_text_start[];
380extern char lnkr_ondemand_text_end[];
381extern char lnkr_ondemand_text_size[];
382extern char lnkr_ondemand_rodata_start[];
383extern char lnkr_ondemand_rodata_end[];
384extern char lnkr_ondemand_rodata_size[];
385
386#endif /* CONFIG_LINKER_USE_ONDEMAND_SECTION */
387#endif /* ! _ASMLANGUAGE */
388
389#ifdef ZTEST_UNITTEST
390#undef DT_NODE_HAS_STATUS
391#undef DT_NODE_HAS_STATUS_OKAY
392#endif
393
394#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.