Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
app_memdomain.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef ZEPHYR_INCLUDE_APP_MEMORY_APP_MEMDOMAIN_H_
7#define ZEPHYR_INCLUDE_APP_MEMORY_APP_MEMDOMAIN_H_
8
10#include <sys/dlist.h>
11#include <kernel.h>
12
13#ifdef CONFIG_USERSPACE
14
23#define K_APP_DMEM_SECTION(id) data_smem_##id##_data
24
33#define K_APP_BMEM_SECTION(id) data_smem_##id##_bss
34
44#define K_APP_DMEM(id) Z_GENERIC_SECTION(K_APP_DMEM_SECTION(id))
45
54#define K_APP_BMEM(id) Z_GENERIC_SECTION(K_APP_BMEM_SECTION(id))
55
56struct z_app_region {
57 void *bss_start;
58 size_t bss_size;
59};
60
61#define Z_APP_START(id) z_data_smem_##id##_part_start
62#define Z_APP_SIZE(id) z_data_smem_##id##_part_size
63#define Z_APP_BSS_START(id) z_data_smem_##id##_bss_start
64#define Z_APP_BSS_SIZE(id) z_data_smem_##id##_bss_size
65
66/* If a partition is declared with K_APPMEM_PARTITION, but never has any
67 * data assigned to its contents, then no symbols with its prefix will end
68 * up in the symbol table. This prevents gen_app_partitions.py from detecting
69 * that the partition exists, and the linker symbols which specify partition
70 * bounds will not be generated, resulting in build errors.
71 *
72 * What this inline assembly code does is define a symbol with no data.
73 * This should work for all arches that produce ELF binaries, see
74 * https://sourceware.org/binutils/docs/as/Section.html
75 *
76 * We don't know what active flags/type of the pushed section were, so we are
77 * specific: "aw" indicates section is allocatable and writable,
78 * and "@progbits" indicates the section has data.
79 */
80#if defined(CONFIG_ARM) || defined(CONFIG_ARM64)
81/* ARM has a quirk in that '@' denotes a comment, so we have to send
82 * %progbits to the assembler instead.
83 */
84#define Z_PROGBITS_SYM "\%"
85#else
86#define Z_PROGBITS_SYM "@"
87#endif
88
89#if defined(CONFIG_ARC) && defined(__CCAC__)
90/* ARC MWDT assembler has slightly different pushsection/popsection directives
91 * names.
92 */
93#define Z_PUSHSECTION_DIRECTIV ".pushsect"
94#define Z_POPSECTION_DIRECTIVE ".popsect"
95#else
96#define Z_PUSHSECTION_DIRECTIV ".pushsection"
97#define Z_POPSECTION_DIRECTIVE ".popsection"
98#endif
99
100#define Z_APPMEM_PLACEHOLDER(name) \
101 __asm__ ( \
102 Z_PUSHSECTION_DIRECTIV " " STRINGIFY(K_APP_DMEM_SECTION(name)) \
103 ",\"aw\"," Z_PROGBITS_SYM "progbits\n\t" \
104 ".global " STRINGIFY(name) "_placeholder\n\t" \
105 STRINGIFY(name) "_placeholder:\n\t" \
106 Z_POPSECTION_DIRECTIVE "\n\t")
107
120#define K_APPMEM_PARTITION_DEFINE(name) \
121 extern char Z_APP_START(name)[]; \
122 extern char Z_APP_SIZE(name)[]; \
123 struct k_mem_partition name = { \
124 .start = (uintptr_t) &Z_APP_START(name), \
125 .size = (size_t) &Z_APP_SIZE(name), \
126 .attr = K_MEM_PARTITION_P_RW_U_RW \
127 }; \
128 extern char Z_APP_BSS_START(name)[]; \
129 extern char Z_APP_BSS_SIZE(name)[]; \
130 Z_GENERIC_SECTION(.app_regions.name) \
131 const struct z_app_region name##_region = { \
132 .bss_start = &Z_APP_BSS_START(name), \
133 .bss_size = (size_t) &Z_APP_BSS_SIZE(name) \
134 }; \
135 Z_APPMEM_PLACEHOLDER(name)
136#else
137
138#define K_APP_BMEM(ptn)
139#define K_APP_DMEM(ptn)
140#define K_APP_DMEM_SECTION(ptn) .data
141#define K_APP_BMEM_SECTION(ptn) .bss
142#define K_APPMEM_PARTITION_DEFINE(name)
143
144#endif /* CONFIG_USERSPACE */
145#endif /* ZEPHYR_INCLUDE_APP_MEMORY_APP_MEMDOMAIN_H_ */
Doubly-linked list implementation.