This is an automated email from the ASF dual-hosted git repository. ligd pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 415be7f5b3a54c8e0973e67d66e819615f91d00d Author: hujun5 <[email protected]> AuthorDate: Tue May 13 14:57:38 2025 +0800 fvp-v8r: protect build support Enable fvp_userspace.c compilation when CONFIG_BUILD_PROTECTED is enabled, providing user-space isolation support for FVP platform. Include board memory map definitions for protected build configuration and update MPU regions for kernel/user space separation. Signed-off-by: hujun5 <[email protected]> --- arch/arm64/src/fvp-v8r/Make.defs | 2 +- arch/arm64/src/fvp-v8r/fvp_boot.c | 44 +++-- arch/arm64/src/fvp-v8r/fvp_v8r_allocateheap.c | 82 ++++++++++ .../fvp-v8r/fvp-armv8r/configs/nsh_smp/defconfig | 2 +- .../fvp-armv8r/configs/{nsh_smp => pnsh}/defconfig | 21 ++- .../configs/{nsh_smp => pnsh_smp}/defconfig | 16 +- .../fvp-v8r/fvp-armv8r/include/board_memorymap.h | 36 +++++ boards/arm64/fvp-v8r/fvp-armv8r/kernel/.gitignore | 1 + boards/arm64/fvp-v8r/fvp-armv8r/kernel/Makefile | 98 ++++++++++++ .../fvp-v8r/fvp-armv8r/kernel/fvp_userspace.c | 124 +++++++++++++++ .../arm64/fvp-v8r/fvp-armv8r/scripts/dramboot.ld | 177 ++++++++++++--------- boards/arm64/fvp-v8r/fvp-armv8r/scripts/memory.ld | 32 ++++ .../arm64/fvp-v8r/fvp-armv8r/scripts/nuttx_user.ld | 128 +++++++++++++++ 13 files changed, 655 insertions(+), 108 deletions(-) diff --git a/arch/arm64/src/fvp-v8r/Make.defs b/arch/arm64/src/fvp-v8r/Make.defs index b40eac0e015..f2f183f0913 100644 --- a/arch/arm64/src/fvp-v8r/Make.defs +++ b/arch/arm64/src/fvp-v8r/Make.defs @@ -23,7 +23,7 @@ include common/Make.defs # fvp-specific C source files -CHIP_CSRCS = fvp_boot.c fvp_serial.c +CHIP_CSRCS = fvp_boot.c fvp_serial.c fvp_v8r_allocateheap.c ifeq ($(CONFIG_ARCH_EARLY_PRINT),y) CHIP_ASRCS += fvp_lowputc.S diff --git a/arch/arm64/src/fvp-v8r/fvp_boot.c b/arch/arm64/src/fvp-v8r/fvp_boot.c index 33c458c0deb..8dcc1445541 100644 --- a/arch/arm64/src/fvp-v8r/fvp_boot.c +++ b/arch/arm64/src/fvp-v8r/fvp_boot.c @@ -43,6 +43,7 @@ #include "chip.h" #include "fvp_boot.h" +#include <arch/board/board_memorymap.h> #include <nuttx/serial/uart_pl011.h> /**************************************************************************** @@ -51,35 +52,44 @@ static const struct arm64_mpu_region g_mpu_regions[] = { - /* Region 0 NuttX text */ + /* Region 0 NuttX ktext */ - MPU_REGION_ENTRY("nx_code", - (uint64_t)_stext, - (uint64_t)_etext, - REGION_RAM_TEXT_ATTR), + MPU_REGION_ENTRY("nx_ktext", + (uint64_t)KTEXT_START, + (uint64_t)KTEXT_END, + REGION_RAM_TEXT_ATTR), - /* Region 1 NuttX rodata */ + /* Region 1 NuttX kdata */ - MPU_REGION_ENTRY("nx_rodata", - (uint64_t)_srodata, - (uint64_t)_erodata, - REGION_RAM_RO_ATTR), + MPU_REGION_ENTRY("nx_kdata", + (uint64_t)KSRAM_START, + (uint64_t)KSRAM_END, + REGION_RAM_ATTR), - /* Region 2 NuttX data */ +#ifdef CONFIG_BUILD_PROTECTED + /* Region 2 NuttX utext */ - MPU_REGION_ENTRY("nx_data", - (uint64_t)_sdata, - (uint64_t)CONFIG_RAMBANK_END, - REGION_RAM_ATTR), + MPU_REGION_ENTRY("nx_utext", + (uint64_t)UTEXT_START, + (uint64_t)UTEXT_END, + REGION_RAM_UTEXT_ATTR), - /* Region 3 device region */ + /* Region 3 NuttX udata */ + + MPU_REGION_ENTRY("nx_udata", + (uint64_t)USRAM_START, + (uint64_t)USRAM_END, + REGION_URAM_ATTR), +#endif + + /* Region 4 device region */ MPU_REGION_ENTRY("DEVICE1", (uint64_t)CONFIG_DEVICEIO1_BASEADDR, (uint64_t)CONFIG_DEVICEIO1_END, REGION_DEVICE_ATTR), - /* Region 4 device region */ + /* Region 5 device region */ MPU_REGION_ENTRY("DEVICE2", (uint64_t)CONFIG_DEVICEIO2_BASEADDR, diff --git a/arch/arm64/src/fvp-v8r/fvp_v8r_allocateheap.c b/arch/arm64/src/fvp-v8r/fvp_v8r_allocateheap.c new file mode 100644 index 00000000000..d5b7bc9e27a --- /dev/null +++ b/arch/arm64/src/fvp-v8r/fvp_v8r_allocateheap.c @@ -0,0 +1,82 @@ +/**************************************************************************** + * arch/arm64/src/fvp-v8r/fvp_v8r_allocateheap.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <sys/types.h> +#include <stdint.h> + +#include <assert.h> +#include <debug.h> +#include <nuttx/arch.h> +#include <nuttx/board.h> +#include <nuttx/userspace.h> +#include <arch/board/board_memorymap.h> + +#include "arm64_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/* Terminology. In the flat build (CONFIG_BUILD_FLAT=y), there is only a + * single heap access with the standard allocations (malloc/free). This + * heap is referred to as the user heap. In the protected build + * (CONFIG_BUILD_PROTECTED=y) where an MPU is used to protect a region of + * otherwise flat memory, there will be two allocators: One that allocates + * protected (kernel) memory and one that allocates unprotected (user) + * memory. These are referred to as the kernel and user heaps, + * respectively. + * + * The ARMv8 has no MPU but does have an MMU. With this MMU, it can support + * the kernel build (CONFIG_BUILD_KERNEL=y). In this configuration, there + * is one kernel heap but multiple user heaps: One per task group. However, + * in this case, we need only be concerned about initializing the single + * kernel heap here. + */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_allocate_kheap + * + * Description: + * For the kernel build (CONFIG_BUILD_PROTECTED/KERNEL=y) with both kernel- + * and user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function allocates + * the kernel-space heap. A custom version of this function is needed if + * memory protection of the kernel heap is required. + * + ****************************************************************************/ + +#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP) +void up_allocate_kheap(void **heap_start, size_t *heap_size) +{ + *heap_start = g_idle_topstack; + *heap_size = KSRAM_END - (size_t)g_idle_topstack; +} +#endif diff --git a/boards/arm64/fvp-v8r/fvp-armv8r/configs/nsh_smp/defconfig b/boards/arm64/fvp-v8r/fvp-armv8r/configs/nsh_smp/defconfig index 7e9ab4b2f3a..e035f186036 100644 --- a/boards/arm64/fvp-v8r/fvp-armv8r/configs/nsh_smp/defconfig +++ b/boards/arm64/fvp-v8r/fvp-armv8r/configs/nsh_smp/defconfig @@ -15,7 +15,7 @@ CONFIG_ARCH_CHIP_FVP_R82=y CONFIG_ARCH_EARLY_PRINT=y CONFIG_ARCH_INTERRUPTSTACK=4096 CONFIG_ARM64_SMP_BUSY_WAIT=y -CONFIG_ARM64_SMP_BUSY_WAIT_FLAG_ADDR=0x60000 +CONFIG_ARM64_SMP_BUSY_WAIT_FLAG_ADDR=0x4000000 CONFIG_ARM64_STRING_FUNCTION=y CONFIG_BUILTIN=y CONFIG_DEBUG_ASSERTIONS=y diff --git a/boards/arm64/fvp-v8r/fvp-armv8r/configs/nsh_smp/defconfig b/boards/arm64/fvp-v8r/fvp-armv8r/configs/pnsh/defconfig similarity index 83% copy from boards/arm64/fvp-v8r/fvp-armv8r/configs/nsh_smp/defconfig copy to boards/arm64/fvp-v8r/fvp-armv8r/configs/pnsh/defconfig index 7e9ab4b2f3a..a5e805f1fc7 100644 --- a/boards/arm64/fvp-v8r/fvp-armv8r/configs/nsh_smp/defconfig +++ b/boards/arm64/fvp-v8r/fvp-armv8r/configs/pnsh/defconfig @@ -6,6 +6,7 @@ # modifications. # CONFIG_ARCH="arm64" +CONFIG_ARCH_ADDRENV=y CONFIG_ARCH_ARM64=y CONFIG_ARCH_BOARD="fvp-armv8r" CONFIG_ARCH_BOARD_FVP_ARMV8R=y @@ -14,9 +15,11 @@ CONFIG_ARCH_CHIP_FVP_ARMV8R=y CONFIG_ARCH_CHIP_FVP_R82=y CONFIG_ARCH_EARLY_PRINT=y CONFIG_ARCH_INTERRUPTSTACK=4096 -CONFIG_ARM64_SMP_BUSY_WAIT=y -CONFIG_ARM64_SMP_BUSY_WAIT_FLAG_ADDR=0x60000 +CONFIG_ARCH_KERNEL_STACK=y +CONFIG_ARCH_KERNEL_STACKSIZE=8192 +CONFIG_ARCH_USE_MPU=y CONFIG_ARM64_STRING_FUNCTION=y +CONFIG_BUILD_PROTECTED=y CONFIG_BUILTIN=y CONFIG_DEBUG_ASSERTIONS=y CONFIG_DEBUG_FEATURES=y @@ -34,35 +37,37 @@ CONFIG_FS_ROMFS=y CONFIG_IDLETHREAD_STACKSIZE=8192 CONFIG_INIT_ENTRYPOINT="nsh_main" CONFIG_INTELHEX_BINARY=y +CONFIG_MM_KERNEL_HEAPSIZE=524288 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=512 CONFIG_NSH_READLINE=y +CONFIG_NUTTX_USERSPACE=0x800000 +CONFIG_PASS1_BUILDIR="boards/arm64/fvp-v8r/fvp-armv8r/kernel" CONFIG_PREALLOC_TIMERS=4 CONFIG_PTHREAD_STACK_MIN=8192 CONFIG_RAMLOG=y -CONFIG_RAM_SIZE=134217728 -CONFIG_RAM_START=0x0000000 +CONFIG_RAM_SIZE=16777216 +CONFIG_RAM_START=0 CONFIG_RAW_BINARY=y CONFIG_READLINE_CMD_HISTORY=y CONFIG_RR_INTERVAL=200 CONFIG_SCHED_HPWORK=y CONFIG_SCHED_HPWORKPRIORITY=192 -CONFIG_SMP=y +CONFIG_SCHED_LPWORK=y +CONFIG_SPINLOCK=y CONFIG_STACK_COLORATION=y CONFIG_START_MONTH=3 CONFIG_START_YEAR=2022 CONFIG_SYMTAB_ORDEREDBYNAME=y -CONFIG_SYSLOG_BUFFER=y CONFIG_SYSLOG_PROCESSID=y CONFIG_SYSLOG_PROCESS_NAME=y CONFIG_SYSTEM_NSH=y CONFIG_SYSTEM_SYSTEM=y -CONFIG_SYSTEM_TASKSET=y CONFIG_SYSTEM_TIME64=y CONFIG_TESTING_GETPRIME=y CONFIG_TESTING_OSTEST=y -CONFIG_TESTING_SMP=y +CONFIG_TESTING_OSTEST_FPUTESTDISABLE=y CONFIG_UART0_BASE=0x9c090000 CONFIG_UART0_IRQ=37 CONFIG_UART0_PL011=y diff --git a/boards/arm64/fvp-v8r/fvp-armv8r/configs/nsh_smp/defconfig b/boards/arm64/fvp-v8r/fvp-armv8r/configs/pnsh_smp/defconfig similarity index 82% copy from boards/arm64/fvp-v8r/fvp-armv8r/configs/nsh_smp/defconfig copy to boards/arm64/fvp-v8r/fvp-armv8r/configs/pnsh_smp/defconfig index 7e9ab4b2f3a..cc4f8c70a0d 100644 --- a/boards/arm64/fvp-v8r/fvp-armv8r/configs/nsh_smp/defconfig +++ b/boards/arm64/fvp-v8r/fvp-armv8r/configs/pnsh_smp/defconfig @@ -6,6 +6,7 @@ # modifications. # CONFIG_ARCH="arm64" +CONFIG_ARCH_ADDRENV=y CONFIG_ARCH_ARM64=y CONFIG_ARCH_BOARD="fvp-armv8r" CONFIG_ARCH_BOARD_FVP_ARMV8R=y @@ -14,9 +15,13 @@ CONFIG_ARCH_CHIP_FVP_ARMV8R=y CONFIG_ARCH_CHIP_FVP_R82=y CONFIG_ARCH_EARLY_PRINT=y CONFIG_ARCH_INTERRUPTSTACK=4096 +CONFIG_ARCH_KERNEL_STACK=y +CONFIG_ARCH_KERNEL_STACKSIZE=8192 +CONFIG_ARCH_USE_MPU=y CONFIG_ARM64_SMP_BUSY_WAIT=y -CONFIG_ARM64_SMP_BUSY_WAIT_FLAG_ADDR=0x60000 +CONFIG_ARM64_SMP_BUSY_WAIT_FLAG_ADDR=0x400000 CONFIG_ARM64_STRING_FUNCTION=y +CONFIG_BUILD_PROTECTED=y CONFIG_BUILTIN=y CONFIG_DEBUG_ASSERTIONS=y CONFIG_DEBUG_FEATURES=y @@ -34,20 +39,24 @@ CONFIG_FS_ROMFS=y CONFIG_IDLETHREAD_STACKSIZE=8192 CONFIG_INIT_ENTRYPOINT="nsh_main" CONFIG_INTELHEX_BINARY=y +CONFIG_MM_KERNEL_HEAPSIZE=524288 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=512 CONFIG_NSH_READLINE=y +CONFIG_NUTTX_USERSPACE=0x800000 +CONFIG_PASS1_BUILDIR="boards/arm64/fvp-v8r/fvp-armv8r/kernel" CONFIG_PREALLOC_TIMERS=4 CONFIG_PTHREAD_STACK_MIN=8192 CONFIG_RAMLOG=y -CONFIG_RAM_SIZE=134217728 -CONFIG_RAM_START=0x0000000 +CONFIG_RAM_SIZE=16777216 +CONFIG_RAM_START=0 CONFIG_RAW_BINARY=y CONFIG_READLINE_CMD_HISTORY=y CONFIG_RR_INTERVAL=200 CONFIG_SCHED_HPWORK=y CONFIG_SCHED_HPWORKPRIORITY=192 +CONFIG_SCHED_LPWORK=y CONFIG_SMP=y CONFIG_STACK_COLORATION=y CONFIG_START_MONTH=3 @@ -62,6 +71,7 @@ CONFIG_SYSTEM_TASKSET=y CONFIG_SYSTEM_TIME64=y CONFIG_TESTING_GETPRIME=y CONFIG_TESTING_OSTEST=y +CONFIG_TESTING_OSTEST_FPUTESTDISABLE=y CONFIG_TESTING_SMP=y CONFIG_UART0_BASE=0x9c090000 CONFIG_UART0_IRQ=37 diff --git a/boards/arm64/fvp-v8r/fvp-armv8r/include/board_memorymap.h b/boards/arm64/fvp-v8r/fvp-armv8r/include/board_memorymap.h index 66d3d119173..511ebc16f94 100644 --- a/boards/arm64/fvp-v8r/fvp-armv8r/include/board_memorymap.h +++ b/boards/arm64/fvp-v8r/fvp-armv8r/include/board_memorymap.h @@ -52,6 +52,42 @@ extern "C" * Public Function Prototypes ****************************************************************************/ +#ifdef CONFIG_BUILD_PROTECTED +/* Split SRAM between kernel and user spaces */ + +# define KTEXT_SIZE (CONFIG_RAM_SIZE / 4) +# define KSRAM_SIZE (CONFIG_RAM_SIZE / 4) +# define UTEXT_SIZE (CONFIG_RAM_SIZE / 4) +# define USRAM_SIZE (CONFIG_RAM_SIZE / 4) +#else +/* Give All RAM to kernel */ + +# define KTEXT_SIZE (CONFIG_RAM_SIZE / 2) +# define KSRAM_SIZE (CONFIG_RAM_SIZE / 2) +# define UTEXT_SIZE 0 +# define USRAM_SIZE 0 +#endif + +/* Kernel code memory (RX) */ + +#define KTEXT_START CONFIG_RAM_START +#define KTEXT_END (KTEXT_START + KTEXT_SIZE) + +/* Kernel RAM (RW) */ + +#define KSRAM_START KTEXT_END +#define KSRAM_END (KSRAM_START + KSRAM_SIZE) + +/* User code memory (RX) */ + +#define UTEXT_START KSRAM_END +#define UTEXT_END (UTEXT_START + UTEXT_SIZE) + +/* User RAM (RW) */ + +#define USRAM_START UTEXT_END +#define USRAM_END (USRAM_START + USRAM_SIZE) + #undef EXTERN #if defined(__cplusplus) } diff --git a/boards/arm64/fvp-v8r/fvp-armv8r/kernel/.gitignore b/boards/arm64/fvp-v8r/fvp-armv8r/kernel/.gitignore new file mode 100644 index 00000000000..d659ed84d83 --- /dev/null +++ b/boards/arm64/fvp-v8r/fvp-armv8r/kernel/.gitignore @@ -0,0 +1 @@ +/nuttx_user* diff --git a/boards/arm64/fvp-v8r/fvp-armv8r/kernel/Makefile b/boards/arm64/fvp-v8r/fvp-armv8r/kernel/Makefile new file mode 100644 index 00000000000..05fe433aa6c --- /dev/null +++ b/boards/arm64/fvp-v8r/fvp-armv8r/kernel/Makefile @@ -0,0 +1,98 @@ +############################################################################ +# boards/arm/qemu/qemu-armv7r/kernel/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(TOPDIR)/Make.defs + +# The entry point name (if none is provided in the .config file) + +CONFIG_INIT_ENTRYPOINT ?= user_start +ENTRYPT = $(patsubst "%",%,$(CONFIG_INIT_ENTRYPOINT)) + +# Get the paths to the libraries and the links script path in format that +# is appropriate for the host OS + +USER_LIBPATHS = $(addprefix -L,$(call CONVERT_PATH,$(addprefix $(TOPDIR)$(DELIM),$(dir $(USERLIBS))))) +USER_LDSCRIPT = $(call CONVERT_PATH,$(BOARD_DIR)$(DELIM)scripts$(DELIM)nuttx_user.ld) +USER_HEXFILE += $(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx_user.hex) +USER_SRECFILE += $(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx_user.srec) +USER_BINFILE += $(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx_user.bin) + +USER_LDFLAGS = --undefined=$(ENTRYPT) --entry=$(ENTRYPT) -T $(addsuffix .tmp,$(USER_LDSCRIPT)) +USER_LDLIBS = $(patsubst lib%,-l%,$(basename $(notdir $(USERLIBS)))) +USER_LIBGCC = "${shell "$(CC)" $(ARCHCPUFLAGS) -print-libgcc-file-name}" + +# Source files + +CSRCS = fvp_userspace.c +COBJS = $(CSRCS:.c=$(OBJEXT)) +OBJS = $(COBJS) + +# Targets: + +all: $(TOPDIR)$(DELIM)nuttx_user $(TOPDIR)$(DELIM)User.map +.PHONY: nuttx_user depend clean distclean + +$(COBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +$(addsuffix .tmp,$(USER_LDSCRIPT)): $(USER_LDSCRIPT) + $(call PREPROCESS,$(patsubst %.tmp,%,$@),$@) + +# Create the nuttx_user file containing all of the user-mode code + +nuttx_user: $(OBJS) $(addsuffix .tmp,$(USER_LDSCRIPT)) + $(Q) $(LD) -o $@ $(USER_LDFLAGS) $(USER_LIBPATHS) $(OBJS) --start-group $(USER_LDLIBS) $(USER_LIBGCC) --end-group + +$(TOPDIR)$(DELIM)nuttx_user: nuttx_user + @echo "LD: nuttx_user" + $(Q) cp -a nuttx_user $(TOPDIR)$(DELIM)nuttx_user +ifeq ($(CONFIG_INTELHEX_BINARY),y) + @echo "CP: nuttx_user.hex" + $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O ihex nuttx_user $(USER_HEXFILE) +endif +ifeq ($(CONFIG_MOTOROLA_SREC),y) + @echo "CP: nuttx_user.srec" + $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O srec nuttx_user $(USER_SRECFILE) +endif +ifeq ($(CONFIG_RAW_BINARY),y) + @echo "CP: nuttx_user.bin" + $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O binary nuttx_user $(USER_BINFILE) +endif + $(Q) $(call DELFILE, $(addsuffix .tmp,$(USER_LDSCRIPT))) + +$(TOPDIR)$(DELIM)User.map: nuttx_user + @echo "MK: User.map" + $(Q) $(NM) nuttx_user >$(TOPDIR)$(DELIM)User.map + $(Q) $(CROSSDEV)size nuttx_user + +.depend: + +depend: .depend + +clean: + $(call DELFILE, nuttx_user) + $(call DELFILE, $(addsuffix .tmp,$(USER_LDSCRIPT))) + $(call DELFILE, "$(TOPDIR)$(DELIM)nuttx_user.*") + $(call DELFILE, "$(TOPDIR)$(DELIM)User.map") + $(call CLEAN) + +distclean: clean diff --git a/boards/arm64/fvp-v8r/fvp-armv8r/kernel/fvp_userspace.c b/boards/arm64/fvp-v8r/fvp-armv8r/kernel/fvp_userspace.c new file mode 100644 index 00000000000..6168e475e39 --- /dev/null +++ b/boards/arm64/fvp-v8r/fvp-armv8r/kernel/fvp_userspace.c @@ -0,0 +1,124 @@ +/**************************************************************************** + * boards/arm64/fvp-v8r/fvp-armv8r/kernel/fvp_userspace.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdlib.h> + +#include <nuttx/arch.h> +#include <nuttx/mm/mm.h> +#include <nuttx/wqueue.h> +#include <nuttx/userspace.h> + +#if defined(CONFIG_BUILD_PROTECTED) && !defined(__KERNEL__) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +#ifndef CONFIG_NUTTX_USERSPACE +# error "CONFIG_NUTTX_USERSPACE not defined" +#endif + +#if CONFIG_NUTTX_USERSPACE != 0x800000 +# error "CONFIG_NUTTX_USERSPACE must be 0x800000 to match memory.ld" +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* These 'addresses' of these values are setup by the linker script. */ + +extern uint8_t _stext[]; /* Start of .text */ +extern uint8_t _etext[]; /* End_1 of .text + .rodata */ +extern const uint8_t _eronly[]; /* End+1 of read only section (.text + .rodata) */ +extern uint8_t _sdata[]; /* Start of .data */ +extern uint8_t _edata[]; /* End+1 of .data */ +extern uint8_t _sbss[]; /* Start of .bss */ +extern uint8_t _ebss[]; /* End+1 of .bss */ +static void sig_trampoline(void) naked_function; +static void sig_trampoline(void) +{ + __asm__ __volatile__ + ( + " sub sp, sp, #16\n" /* Create a stack frame to hold LR */ + " str lr, [sp, #0]\n" /* Save LR on the stack */ + " mov ip0, x0\n" /* IP=sighand */ + " mov x0, x1\n" /* R0=signo */ + " mov x1, x2\n" /* R1=info */ + " mov x2, x3\n" /* R2=ucontext */ + " blr ip0\n" /* Call the signal handler */ + " ldr lr, [sp, #0]\n" /* Recover LR in R2 */ + " add sp, sp, #16\n" /* Destroy the stack frame */ + " mov x0, %0\n" /* SYS_signal_handler_return */ + " svc %1\n" /* Return from the SYSCALL */ + : + : "i"(SYS_signal_handler_return), + "i"(SYS_syscall) + : + ); +} + +const struct userspace_s userspace locate_data(".userspace") = +{ + /* General memory map */ + + .us_entrypoint = CONFIG_INIT_ENTRYPOINT, + .us_textstart = (uintptr_t)_stext, + .us_textend = (uintptr_t)_etext, + .us_datasource = (uintptr_t)_eronly, + .us_datastart = (uintptr_t)_sdata, + .us_dataend = (uintptr_t)_edata, + .us_bssstart = (uintptr_t)_sbss, + .us_bssend = (uintptr_t)_ebss, + + /* Memory manager heap structure */ + + .us_heap = &g_mmheap, + + /* Task/thread startup routines */ + + .task_startup = nxtask_startup, + + /* Signal handler trampoline */ + + .signal_handler = (void *)sig_trampoline, + + /* User-space work queue support (declared in include/nuttx/wqueue.h) */ + +#ifdef CONFIG_LIBC_USRWORK + .work_usrstart = work_usrstart, +#endif +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#endif /* CONFIG_BUILD_PROTECTED && !__KERNEL__ */ diff --git a/boards/arm64/fvp-v8r/fvp-armv8r/scripts/dramboot.ld b/boards/arm64/fvp-v8r/fvp-armv8r/scripts/dramboot.ld index 6437c6afeb5..e76f593a0e3 100644 --- a/boards/arm64/fvp-v8r/fvp-armv8r/scripts/dramboot.ld +++ b/boards/arm64/fvp-v8r/fvp-armv8r/scripts/dramboot.ld @@ -20,114 +20,106 @@ * ****************************************************************************/ -#include <nuttx/config.h> +#include "memory.ld" OUTPUT_ARCH(aarch64) ENTRY(__start) -PHDRS -{ - text PT_LOAD ; -} - SECTIONS { - . = 0x00000000; /* load address */ - _start = .; + /* where the global variable out-of-bounds detection information located */ .text : { - _stext = .; /* Text section */ - *(.start .start.*) /* Place __start here */ - *(.text) - *(.text.cold) - *(.text.unlikely) - *(.fixup) - *(.gnu.warning) - } :text = 0x9090 + _stext = .; /* Text section */ + *(.start .start.*) + *(.vectors*) + *(.exc_vector_table*) + *(.text*) + *(.fixup) + *(.gnu.warning) + _etext = .; /* End_1 of .text */ + _sztext = _etext - _stext; + } > ktext + + .ARM.extab : + { + *(.ARM.extab*) + } > ktext + + /* .ARM.exidx is sorted, so has to go in its own output section. */ + + PROVIDE_HIDDEN (__exidx_start = .); + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > ktext + PROVIDE_HIDDEN (__exidx_end = .); . = ALIGN(4096); - .init_section : { - _sinit = ABSOLUTE(.); - KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) - KEEP(*(.init_array EXCLUDE_FILE(*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o) .ctors)) - _einit = ABSOLUTE(.); - } + .bss : { /* BSS */ + _sbss = . ; +#if defined(CONFIG_SMP) && defined(CONFIG_ARM64_SMP_BUSY_WAIT) + . = . + 0x4; /* Busy Wait Flag */ +#endif + *(.bss*) + . = ALIGN(4096); + _ebss = .; + } > ksram - . = ALIGN(4096); + _szbss = _ebss - _sbss; - .vector : { - _vector_start = .; - KEEP(*(.exc_vector_table)) - KEEP(*(".exc_vector_table.*")) - KEEP(*(.vectors)) - _vector_end = .; - } :text - . = ALIGN(4096); - _etext = .; /* End_1 of .text */ - _sztext = _etext - _stext; + .init_section : { + _sinit = ABSOLUTE(.); + KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP(*(.init_array EXCLUDE_FILE(*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o) .ctors)) + _einit = ABSOLUTE(.); + . = ALIGN(4096); + } > ksram - . = ALIGN(4096); .rodata : { - _srodata = .; /* Read-only data */ - *(.rodata) - *(.rodata.*) - *(.data.rel.ro) - *(.data.rel.ro.*) - } :text - . = ALIGN(4096); - _erodata = .; /* End of read-only data */ - _szrodata = _erodata - _srodata; - _eronly = .; /* End of read-only data */ + _srodata = .; /* Read-only data */ + *(.rodata*) + *(.data.rel.ro*) + KEEP(*(SORT(.scattered_array*))); + . = ALIGN(4096); + _erodata = .; + } > ksram - . = ALIGN(4096); .data : { /* Data */ - _sdata = .; - *(.data.page_aligned) - *(.data) - . = ALIGN(8); - __start_impls = .; - *(.impls) - KEEP(*(.impls)) - . = ALIGN(4); - __stop_impls = .; - *(.data.rel) - *(.data.rel.*) - CONSTRUCTORS - } :text - _edata = .; /* End+1 of .data */ - -#if defined(CONFIG_SMP) && defined(CONFIG_ARM64_SMP_BUSY_WAIT) - . = CONFIG_ARM64_SMP_BUSY_WAIT_FLAG_ADDR + 4; -#endif - - .bss : { /* BSS */ - . = ALIGN(8); - _sbss = .; - *(.bss) - . = ALIGN(8); - } :text - . = ALIGN(4096); - _ebss = .; - _szbss = _ebss - _sbss; - + _sdata = .; + *(.data*) + . = ALIGN(8); + __start_impls = .; + *(.impls) + KEEP(*(.impls)) + . = ALIGN(4); + __stop_impls = .; + _edata = .; + } > ksram + + .noinit : { + _snoinit = ABSOLUTE(.); + *(.noinit*) + _enoinit = ABSOLUTE(.); + . = + 60; + } > ksram + + . = ALIGN(4096); .initstack : { /* INIT STACK */ _s_initstack = .; *(.initstack) . = ALIGN(16); - } :text + } > ksram . = ALIGN(4096); _e_initstack = . ; g_idle_topstack = . ; - _szdata = _e_initstack - _sdata; - /* Sections to be discarded */ /DISCARD/ : { *(.exit.text) *(.exit.data) *(.exitcall.exit) - *(.eh_frame) } /* Stabs debugging sections. */ @@ -138,5 +130,34 @@ SECTIONS .stab.index 0 : { *(.stab.index) } .stab.indexstr 0 : { *(.stab.indexstr) } .comment 0 : { *(.comment) } + + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + + /* DWARF 1 */ + + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + + /* GNU DWARF 1 extensions */ + + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + + /* DWARF 1.1 and DWARF 2 */ + + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + + /* DWARF 2 */ + + .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } } diff --git a/boards/arm64/fvp-v8r/fvp-armv8r/scripts/memory.ld b/boards/arm64/fvp-v8r/fvp-armv8r/scripts/memory.ld new file mode 100644 index 00000000000..aec6f0bffdf --- /dev/null +++ b/boards/arm64/fvp-v8r/fvp-armv8r/scripts/memory.ld @@ -0,0 +1,32 @@ +/**************************************************************************** + * boards/arm/qemu/qemu-armv7r/scripts/memory.ld + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#include <nuttx/config.h> +#include <arch/board/board_memorymap.h> + +MEMORY +{ + ktext (rwx) : ORIGIN = KTEXT_START, LENGTH = KTEXT_SIZE + ksram (rwx) : ORIGIN = KSRAM_START, LENGTH = KSRAM_SIZE + utext (rwx) : ORIGIN = UTEXT_START, LENGTH = UTEXT_SIZE + usram (rwx) : ORIGIN = USRAM_START, LENGTH = USRAM_SIZE +} diff --git a/boards/arm64/fvp-v8r/fvp-armv8r/scripts/nuttx_user.ld b/boards/arm64/fvp-v8r/fvp-armv8r/scripts/nuttx_user.ld new file mode 100644 index 00000000000..48a88f898a7 --- /dev/null +++ b/boards/arm64/fvp-v8r/fvp-armv8r/scripts/nuttx_user.ld @@ -0,0 +1,128 @@ +/**************************************************************************** + * boards/arm/qemu/qemu-armv7r/scripts/nuttx_user.ld + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#include "memory.ld" + +OUTPUT_ARCH(aarch64) +SECTIONS +{ + .userspace : { + KEEP(*(.userspace)) + } > utext + + .text : { + _stext = ABSOLUTE(.); + *(.text .text.*) + *(.fixup) + *(.gnu.warning) + *(.rodata .rodata.*) + *(.gnu.linkonce.t.*) + *(.glue_7) + *(.glue_7t) + *(.got) + *(.gcc_except_table) + *(.gnu.linkonce.r.*) + _etext = ABSOLUTE(.); + } > utext + + .init_section : { + _sinit = ABSOLUTE(.); + KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP(*(.init_array EXCLUDE_FILE(*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o) .ctors)) + _einit = ABSOLUTE(.); + } > usram + + .ARM.extab : { + *(.ARM.extab*) + } > usram + + __exidx_start = ABSOLUTE(.); + .ARM.exidx : { + *(.ARM.exidx*) + } > usram + + __exidx_end = ABSOLUTE(.); + + _eronly = ABSOLUTE(.); + + .bss : { + _sbss = ABSOLUTE(.); + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(4); + _ebss = ABSOLUTE(.); + } > usram + + .data : { + _sdata = ABSOLUTE(.); + *(.data .data.*) + *(.gnu.linkonce.d.*) + CONSTRUCTORS + . = ALIGN(4); + _edata = ABSOLUTE(.); + } > usram + + /* Stabs debugging sections */ + + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_info 0 : { *(.debug_info) } + .debug_line 0 : { *(.debug_line) } + .debug_pubnames 0 : { *(.debug_pubnames) } + .debug_aranges 0 : { *(.debug_aranges) } + + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + + /* DWARF 1 */ + + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + + /* GNU DWARF 1 extensions */ + + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + + /* DWARF 1.1 and DWARF 2 */ + + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + + /* DWARF 2 */ + + .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } +}
