Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | #ifndef ZEPHYR_INCLUDE_APP_MEMORY_APP_MEMDOMAIN_H_ #define ZEPHYR_INCLUDE_APP_MEMORY_APP_MEMDOMAIN_H_ #include <linker/linker-defs.h> #include <misc/dlist.h> #include <kernel.h> #ifdef CONFIG_USERSPACE #if defined(CONFIG_X86) #define MEM_DOMAIN_ALIGN_SIZE _STACK_BASE_ALIGN #elif defined(STACK_ALIGN) #define MEM_DOMAIN_ALIGN_SIZE STACK_ALIGN #else #error "Not implemented for this architecture" #endif /** * @brief Name of the data section for a particular partition * * Useful for defining memory pools, or any other macro that takes a * section name as a parameter. * * @param id Partition name */ #define K_APP_DMEM_SECTION(id) data_smem_##id##_data /** * @brief Name of the bss section for a particular partition * * Useful for defining memory pools, or any other macro that takes a * section name as a parameter. * * @param id Partition name */ #define K_APP_BMEM_SECTION(id) data_smem_##id##_bss /** * @brief Place data in a partition's data section * * Globals tagged with this will end up in the data section for the * specified memory partition. This data should be initialized to some * desired value. * * @param id Name of the memory partition to associate this data */ #define K_APP_DMEM(id) Z_GENERIC_SECTION(K_APP_DMEM_SECTION(id)) /** * @brief Place data in a partition's bss section * * Globals tagged with this will end up in the bss section for the * specified memory partition. This data will be zeroed at boot. * * @param id Name of the memory partition to associate this data */ #define K_APP_BMEM(id) Z_GENERIC_SECTION(K_APP_BMEM_SECTION(id)) struct z_app_region { void *bss_start; size_t bss_size; }; #define Z_APP_START(id) z_data_smem_##id##_part_start #define Z_APP_SIZE(id) z_data_smem_##id##_part_size #define Z_APP_BSS_START(id) z_data_smem_##id##_bss_start #define Z_APP_BSS_SIZE(id) z_data_smem_##id##_bss_size /* If a partition is declared with K_APPMEM_PARTITION, but never has any * data assigned to its contents, then no symbols with its prefix will end * up in the symbol table. This prevents gen_app_partitions.py from detecting * that the partition exists, and the linker symbols which specify partition * bounds will not be generated, resulting in build errors. * * What this inline assembly code does is define a symbol with no data. * This should work for all arches that produce ELF binaries, see * https://sourceware.org/binutils/docs/as/Section.html * * We don't know what active flags/type of the pushed section were, so we are * specific: "aw" indicates section is allocatable and writable, * and "@progbits" indicates the section has data. */ #ifdef CONFIG_ARM /* ARM has a quirk in that '@' denotes a comment, so we have to send * %progbits to the assembler instead. */ #define Z_PROGBITS_SYM "\%" #else #define Z_PROGBITS_SYM "@" #endif #define Z_APPMEM_PLACEHOLDER(name) \ __asm__ ( \ ".pushsection " STRINGIFY(K_APP_DMEM_SECTION(name)) \ ",\"aw\"," Z_PROGBITS_SYM "progbits\n\t" \ ".global " STRINGIFY(name) "_placeholder\n\t" \ STRINGIFY(name) "_placeholder:\n\t" \ ".popsection\n\t") /** * @brief Define an application memory partition with linker support * * Defines a k_mem_paritition with the provided name. * This name may be used with the K_APP_DMEM and K_APP_BMEM macros to * place globals automatically in this partition. * * NOTE: placeholder char variable is defined here to prevent build errors * if a partition is defined but nothing ever placed in it. * * @param name Name of the k_mem_partition to declare */ #define K_APPMEM_PARTITION_DEFINE(name) \ extern char Z_APP_START(name)[]; \ extern char Z_APP_SIZE(name)[]; \ struct k_mem_partition name = { \ .start = (u32_t) &Z_APP_START(name), \ .size = (u32_t) &Z_APP_SIZE(name), \ .attr = K_MEM_PARTITION_P_RW_U_RW \ }; \ extern char Z_APP_BSS_START(name)[]; \ extern char Z_APP_BSS_SIZE(name)[]; \ Z_GENERIC_SECTION(.app_regions.name) \ struct z_app_region name##_region = { \ .bss_start = &Z_APP_BSS_START(name), \ .bss_size = (size_t) &Z_APP_BSS_SIZE(name) \ }; \ Z_APPMEM_PLACEHOLDER(name); #else #define K_APP_BMEM(ptn) #define K_APP_DMEM(ptn) #define K_APP_DMEM_SECTION(ptn) .data #define K_APP_BMEM_SECTION(ptn) .bss #define K_APPMEM_PARTITION_DEFINE(name) #endif /* CONFIG_USERSPACE */ #endif /* ZEPHYR_INCLUDE_APP_MEMORY_APP_MEMDOMAIN_H_ */ |