diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 0f4d0efb66..e5eff102ea 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -55,6 +55,8 @@ config ARCH_CHIP_QEMU select ARCH_NEED_ADDRENV_MAPPING select ARCH_HAVE_POWEROFF select ARCH_HAVE_RESET + select ARCH_HAVE_TEXT_HEAP + select LIBC_ARCH_ELF_64BIT if LIBC_ARCH_ELF ---help--- QEMU virt platform (ARMv8a) diff --git a/arch/arm64/src/qemu/Make.defs b/arch/arm64/src/qemu/Make.defs index 2d70132802..037ce80428 100644 --- a/arch/arm64/src/qemu/Make.defs +++ b/arch/arm64/src/qemu/Make.defs @@ -26,3 +26,7 @@ CHIP_CSRCS = qemu_boot.c qemu_serial.c ifeq ($(CONFIG_ARCH_EARLY_PRINT),y) CHIP_ASRCS = qemu_lowputc.S endif + +ifeq ($(CONFIG_ARCH_USE_TEXT_HEAP),y) +CHIP_CSRCS += qemu_textheap.c +endif diff --git a/arch/arm64/src/qemu/qemu_textheap.c b/arch/arm64/src/qemu/qemu_textheap.c new file mode 100644 index 0000000000..a5a114a0ed --- /dev/null +++ b/arch/arm64/src/qemu/qemu_textheap.c @@ -0,0 +1,113 @@ +/**************************************************************************** + * arch/arm64/src/qemu/qemu_textheap.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 +#include +#include + +#include "arm64_mmu.h" +#include "arm64_internal.h" + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +extern uint8_t _sload[]; +extern uint8_t _szload[]; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct mm_heap_s *g_textheap; + +/* Mark load segment cacheable, write-read and executable */ + +static struct arm_mmu_region g_mmu_load = + MMU_REGION_FLAT_ENTRY("nx_load", + (uint64_t)_sload, + (uint64_t)_szload, + MT_NORMAL | MT_RW | MT_EXECUTE | MT_SECURE); + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_textheap_memalign + * + * Description: + * Allocate memory for text sections with the specified alignment. + * + ****************************************************************************/ + +void *up_textheap_memalign(size_t align, size_t size) +{ + if (g_textheap == NULL) + { + if (arm64_mmu_set_memregion(&g_mmu_load) != 0) + { + return NULL; + } + + g_textheap = mm_initialize("textheap", (void *)&_sload, + (size_t)_szload); + } + + return mm_memalign(g_textheap, align, size); +} + +/**************************************************************************** + * Name: up_textheap_free + * + * Description: + * Free memory allocated for text sections. + * + ****************************************************************************/ + +void up_textheap_free(void *p) +{ + if (g_textheap != NULL) + { + mm_free(g_textheap, p); + } +} + +/**************************************************************************** + * Name: up_textheap_heapmember + * + * Description: + * Test if memory is from text heap. + * + ****************************************************************************/ + +bool up_textheap_heapmember(void *p) +{ + if (g_textheap != NULL) + { + return mm_heapmember(g_textheap, p); + } + + return false; +} diff --git a/boards/arm64/qemu/qemu-armv8a/configs/sotest/defconfig b/boards/arm64/qemu/qemu-armv8a/configs/sotest/defconfig new file mode 100644 index 0000000000..4ecdcd2e57 --- /dev/null +++ b/boards/arm64/qemu/qemu-armv8a/configs/sotest/defconfig @@ -0,0 +1,82 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +CONFIG_ARCH="arm64" +CONFIG_ARCH_ARM64=y +CONFIG_ARCH_BOARD="qemu-armv8a" +CONFIG_ARCH_BOARD_QEMU_ARMV8A=y +CONFIG_ARCH_CHIP="qemu" +CONFIG_ARCH_CHIP_QEMU=y +CONFIG_ARCH_CHIP_QEMU_A53=y +CONFIG_ARCH_EARLY_PRINT=y +CONFIG_ARCH_INTERRUPTSTACK=4096 +CONFIG_ARM64_SEMIHOSTING_HOSTFS=y +CONFIG_ARM64_SEMIHOSTING_HOSTFS_CACHE_COHERENCE=y +CONFIG_ARM64_STRING_FUNCTION=y +CONFIG_BOARDCTL_ROMDISK=y +CONFIG_BUILTIN=y +CONFIG_DEBUG_ASSERTIONS=y +CONFIG_DEBUG_BINFMT=y +CONFIG_DEBUG_BINFMT_ERROR=y +CONFIG_DEBUG_BINFMT_INFO=y +CONFIG_DEBUG_BINFMT_WARN=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SCHED=y +CONFIG_DEBUG_SCHED_ERROR=y +CONFIG_DEBUG_SCHED_INFO=y +CONFIG_DEBUG_SCHED_WARN=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEFAULT_TASK_STACKSIZE=8192 +CONFIG_DEVICE_TREE=y +CONFIG_DEV_ZERO=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_EXAMPLES_SOTEST=y +CONFIG_EXAMPLES_SOTEST_DEVMINOR=10 +CONFIG_EXPERIMENTAL=y +CONFIG_FS_HOSTFS=y +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_REGISTER=y +CONFIG_FS_ROMFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_IDLETHREAD_STACKSIZE=8192 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INTELHEX_BINARY=y +CONFIG_LIBC_DLFCN=y +CONFIG_LIBC_FDT=y +CONFIG_MODLIB_DUMPBUFFER=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_READLINE=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_PTHREAD_STACK_MIN=8192 +CONFIG_RAMLOG=y +CONFIG_RAM_SIZE=134217728 +CONFIG_RAM_START=0x40000000 +CONFIG_RAW_BINARY=y +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_HPWORKPRIORITY=192 +CONFIG_SPINLOCK=y +CONFIG_STACK_COLORATION=y +CONFIG_START_MONTH=3 +CONFIG_START_YEAR=2022 +CONFIG_SYMTAB_ORDEREDBYNAME=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_SYSTEM=y +CONFIG_SYSTEM_TIME64=y +CONFIG_TESTING_GETPRIME=y +CONFIG_TESTING_OSTEST=y +CONFIG_UART1_BASE=0x9000000 +CONFIG_UART1_IRQ=33 +CONFIG_UART1_PL011=y +CONFIG_UART1_SERIAL_CONSOLE=y +CONFIG_UART_PL011=y +CONFIG_USEC_PER_TICK=1000 diff --git a/boards/arm64/qemu/qemu-armv8a/scripts/Make.defs b/boards/arm64/qemu/qemu-armv8a/scripts/Make.defs index 19c26455ea..fce2c86eea 100644 --- a/boards/arm64/qemu/qemu-armv8a/scripts/Make.defs +++ b/boards/arm64/qemu/qemu-armv8a/scripts/Make.defs @@ -41,6 +41,11 @@ LDNXFLATFLAGS = -e main -s 2048 # ELF module definitions +CMODULEFLAGS = $(CFLAGS) + +LDMODULEFLAGS = -r -e module_initialize +LDMODULEFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)/libs/libc/modlib/gnu-elf.ld) + CELFFLAGS = $(CFLAGS) -mlong-calls # --target1-abs CXXELFFLAGS = $(CXXFLAGS) -mlong-calls # --target1-abs diff --git a/boards/arm64/qemu/qemu-armv8a/scripts/dramboot.ld b/boards/arm64/qemu/qemu-armv8a/scripts/dramboot.ld index 4cedc61326..c8857860ea 100644 --- a/boards/arm64/qemu/qemu-armv8a/scripts/dramboot.ld +++ b/boards/arm64/qemu/qemu-armv8a/scripts/dramboot.ld @@ -62,6 +62,11 @@ SECTIONS _etext = .; /* End_1 of .text */ _sztext = _etext - _stext; + _sload = .; + . += 1048576; + _eload = .; + _szload = _eload - _sload; + . = ALIGN(4096); .rodata : { _srodata = .; /* Read-only data */