From f5ac11ae32e37bc69f2e33fc3e3adcbe3665fa07 Mon Sep 17 00:00:00 2001 From: Nicolas Royer Date: Fri, 27 Mar 2020 17:36:48 +0100 Subject: [PATCH] arch: riscv: linker: add support for userspace - Move kobject list after .bss The previous order shift kernel object address defined in prebuild file (which is use as reference in running time). So it was impossible for zephyr to check if a kernel object address was granted because address changed during build. - Add support for memory shared. - Move sdata2 section in ROM because it contains constants. Signed-off-by: Nicolas Royer --- include/arch/riscv/common/linker.ld | 112 +++++++++++++++++++--------- 1 file changed, 76 insertions(+), 36 deletions(-) diff --git a/include/arch/riscv/common/linker.ld b/include/arch/riscv/common/linker.ld index 0093419502b..16662a1ef13 100644 --- a/include/arch/riscv/common/linker.ld +++ b/include/arch/riscv/common/linker.ld @@ -31,6 +31,22 @@ #define _EXCEPTION_SECTION_NAME exceptions #define _RESET_SECTION_NAME reset +#ifdef CONFIG_RISCV_PMP + #define MPU_MIN_SIZE 4 + #define MPU_MIN_SIZE_ALIGN . = ALIGN(MPU_MIN_SIZE ); + #if defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT) + #define MPU_ALIGN(region_size) \ + . = ALIGN(MPU_MIN_SIZE); \ + . = ALIGN( 1 << LOG2CEIL(region_size)) + #else + #define MPU_ALIGN(region_size) \ + . = ALIGN(MPU_MIN_SIZE) + #endif +#else + #define MPU_MIN_SIZE_ALIGN + #define MPU_ALIGN(region_size) . = ALIGN(4) +#endif + MEMORY { #ifdef CONFIG_XIP @@ -106,10 +122,12 @@ SECTIONS *(".text.*") *(.gnu.linkonce.t.*) *(.eh_frame) +#include } GROUP_LINK_IN(ROMABLE_REGION) _image_text_end = .; + _image_rodata_start = .; #include #include @@ -121,58 +139,47 @@ SECTIONS *(.rodata) *(".rodata.*") *(.gnu.linkonce.r.*) - -/* Located in generated directory. This file is populated by the - * zephyr_linker_sources() Cmake function. - */ -#include - - } GROUP_LINK_IN(ROMABLE_REGION) - -#include - - _image_rom_end = .; - __data_rom_start = .; - - GROUP_END(ROMABLE_REGION) - - GROUP_START(RAMABLE_REGION) - - SECTION_DATA_PROLOGUE(_DATA_SECTION_NAME,,) - { - . = ALIGN(4); - _image_ram_start = .; - __data_ram_start = .; - - *(.data) - *(".data.*") - - *(.sdata .sdata.* .gnu.linkonce.s.*) *(.sdata2 .sdata2.* .gnu.linkonce.s2.*) /* Located in generated directory. This file is populated by the * zephyr_linker_sources() Cmake function. */ -#include +#include +#include + . = ALIGN(4); + } GROUP_LINK_IN(ROMABLE_REGION) - } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) +#include + _image_rodata_end = .; + MPU_ALIGN(_image_rodata_end - _image_rom_start); + _image_rom_end = .; + _image_rom_size = _image_rom_end - _image_rom_start; + GROUP_END(ROMABLE_REGION) -#include + GROUP_START(RAMABLE_REGION) -/* Located in generated directory. This file is populated by the - * zephyr_linker_sources() Cmake function. - */ -#include - __data_ram_end = .; +#if defined(CONFIG_USERSPACE) +#define APP_SHARED_ALIGN MPU_MIN_SIZE_ALIGN +#define SMEM_PARTITION_ALIGN MPU_ALIGN + +#include + + _image_ram_start = _app_smem_start; + _app_smem_size = _app_smem_end - _app_smem_start; + _app_smem_rom_start = LOADADDR(_APP_SMEM_SECTION_NAME); +#endif /* CONFIG_USERSPACE */ SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),) { + MPU_MIN_SIZE_ALIGN /* * For performance, BSS section is assumed to be 4 byte aligned and * a multiple of 4 bytes */ . = ALIGN(4); __bss_start = .; + _image_ram_start = .; + __kernel_ram_start = .; *(.sbss) *(".sbss.*") *(.bss) @@ -186,12 +193,45 @@ SECTIONS } GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION) #include - #include + SECTION_DATA_PROLOGUE(_DATA_SECTION_NAME,,) + { + . = ALIGN(4); + /* _image_ram_start = .; */ + __data_ram_start = .; + + *(.data) + *(".data.*") + + *(.sdata .sdata.* .gnu.linkonce.s.*) + +/* Located in generated directory. This file is populated by the + * zephyr_linker_sources() Cmake function. + */ +#include + + } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) + + __data_rom_start = LOADADDR(_DATA_SECTION_NAME); + +#include +#include + +/* Located in generated directory. This file is populated by the + * zephyr_linker_sources() Cmake function. + */ +#include + __data_ram_end = .; + + MPU_MIN_SIZE_ALIGN + _image_ram_end = .; _end = .; /* end of image */ + __kernel_ram_end = .; + __kernel_ram_size = __kernel_ram_end - __kernel_ram_start; + /* Located in generated directory. This file is populated by the * zephyr_linker_sources() Cmake function. */