This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 4db5016d8385e7129e791b031b6ef944c805c6e9 Author: zhuyanlin <[email protected]> AuthorDate: Mon Nov 22 19:26:08 2021 +0800 arch:hostfs: add cache coherence config for semihosting option N/A Signed-off-by: zhuyanlin <[email protected]> --- arch/arm/Kconfig | 10 +++++++ arch/arm/src/common/arm_hostfs.c | 50 ++++++++++++++++++++++++++++------ arch/xtensa/Kconfig | 10 +++++++ arch/xtensa/src/common/xtensa_hostfs.c | 12 ++++++++ 4 files changed, 73 insertions(+), 9 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 9892328..dd34fbf 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -975,6 +975,16 @@ config ARM_SEMIHOSTING_HOSTFS This doesn't support some directory operations like readdir because of the limitations of semihosting mechanism. +if ARM_SEMIHOSTING_HOSTFS + +config ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE + bool "Cache coherence in semihosting hostfs" + depends on ARCH_DCACHE + ---help--- + Flush & Invalidte cache before & after bkpt instruction. + +endif + if ARCH_ARMV6M source "arch/arm/src/armv6-m/Kconfig" endif diff --git a/arch/arm/src/common/arm_hostfs.c b/arch/arm/src/common/arm_hostfs.c index d8ad1fa..7200758 100644 --- a/arch/arm/src/common/arm_hostfs.c +++ b/arch/arm/src/common/arm_hostfs.c @@ -23,6 +23,7 @@ ****************************************************************************/ #include <nuttx/config.h> +#include <nuttx/cache.h> #include <nuttx/fs/hostfs.h> #include <errno.h> @@ -49,8 +50,12 @@ * Private Functions ****************************************************************************/ -static long host_call(unsigned int nbr, void *parm) +static long host_call(unsigned int nbr, void *parm, size_t size) { +#ifdef CONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE + up_clean_dcache(parm, parm + size); +#endif + long ret = smh_call(nbr, parm); if (ret < 0) { @@ -66,7 +71,7 @@ static long host_call(unsigned int nbr, void *parm) static ssize_t host_flen(long fd) { - return host_call(HOST_FLEN, &fd); + return host_call(HOST_FLEN, &fd, sizeof(long)); } static int host_flags_to_mode(int flags) @@ -118,13 +123,17 @@ int host_open(const char *pathname, int flags, int mode) .len = strlen(pathname), }; - return host_call(HOST_OPEN, &open); +#ifdef CONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE + up_clean_dcache(pathname, pathname + open.len + 1); +#endif + + return host_call(HOST_OPEN, &open, sizeof(open)); } int host_close(int fd_) { long fd = fd_; - return host_call(HOST_CLOSE, &fd); + return host_call(HOST_CLOSE, &fd, sizeof(long)); } ssize_t host_read(int fd, void *buf, size_t count) @@ -141,7 +150,14 @@ ssize_t host_read(int fd, void *buf, size_t count) .count = count, }; - ssize_t ret = host_call(HOST_READ, &read); + ssize_t ret; + +#ifdef CONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE + up_invalidate_dcache(buf, buf + count); +#endif + + ret = host_call(HOST_READ, &read, sizeof(read)); + return ret < 0 ? ret : count - ret; } @@ -159,7 +175,13 @@ ssize_t host_write(int fd, const void *buf, size_t count) .count = count, }; - ssize_t ret = host_call(HOST_WRITE, &write); + ssize_t ret; + +#ifdef CONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE + up_clean_dcache(buf, buf + count); +#endif + + ret = host_call(HOST_WRITE, &write, sizeof(write)); return ret < 0 ? ret : count - ret; } @@ -189,7 +211,7 @@ off_t host_lseek(int fd, off_t offset, int whence) .pos = offset, }; - ret = host_call(HOST_SEEK, &seek); + ret = host_call(HOST_SEEK, &seek, sizeof(seek)); if (ret >= 0) { ret = offset; @@ -267,7 +289,12 @@ int host_unlink(const char *pathname) .pathname_len = strlen(pathname), }; - return host_call(HOST_REMOVE, &remove); +#ifdef CONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE + up_clean_dcache(pathname, pathname + + remove.pathname_len + 1); +#endif + + return host_call(HOST_REMOVE, &remove, sizeof(remove)); } int host_mkdir(const char *pathname, mode_t mode) @@ -296,7 +323,12 @@ int host_rename(const char *oldpath, const char *newpath) .newpath_len = strlen(newpath), }; - return host_call(HOST_RENAME, &rename); +#ifdef CONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE + up_clean_dcache(oldpath, oldpath + rename.oldpath_len + 1); + up_clean_dcache(newpath, newpath + rename.newpath_len + 1); +#endif + + return host_call(HOST_RENAME, &rename, sizeof(rename)); } int host_stat(const char *path, struct stat *buf) diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig index 402f92f..83268aa 100644 --- a/arch/xtensa/Kconfig +++ b/arch/xtensa/Kconfig @@ -220,6 +220,16 @@ config XTENSA_EXTMEM_BSS Adds a section and an attribute that allows to force variables into the external memory. +if CONFIG_FS_HOSTFS + +config XTENSA_HOSTFS_CACHE_COHERENCE + bool "Cache coherence in semihosting hostfs" + depends on ARCH_DCACHE + ---help--- + Flush & Invalidte cache before & after sim call. + +endif + choice prompt "Toolchain Selection" default XTENSA_TOOLCHAIN_ESP diff --git a/arch/xtensa/src/common/xtensa_hostfs.c b/arch/xtensa/src/common/xtensa_hostfs.c index fba8d31..20e62df 100644 --- a/arch/xtensa/src/common/xtensa_hostfs.c +++ b/arch/xtensa/src/common/xtensa_hostfs.c @@ -23,6 +23,7 @@ ****************************************************************************/ #include <nuttx/config.h> +#include <nuttx/cache.h> #include <nuttx/fs/hostfs.h> #include <arch/simcall.h> @@ -96,6 +97,9 @@ int host_open(const char *pathname, int flags, int mode) simcall_flags |= SIMCALL_O_EXCL; } +#ifdef CONFIG_XTENSA_HOSTFS_CACHE_COHERENCE + up_clean_dcache(pathname, pathname + strlen(pathname) + 1); +#endif return host_call(SIMCALL_SYS_OPEN, (int)pathname, simcall_flags, mode); } @@ -106,11 +110,19 @@ int host_close(int fd) ssize_t host_read(int fd, void *buf, size_t count) { +#ifdef CONFIG_XTENSA_HOSTFS_CACHE_COHERENCE + up_invalidate_dcache(buf, buf + count); +#endif + return host_call(SIMCALL_SYS_READ, fd, (int)buf, count); } ssize_t host_write(int fd, const void *buf, size_t count) { +#ifdef CONFIG_XTENSA_HOSTFS_CACHE_COHERENCE + up_clean_dcache(buf, buf + count); +#endif + return host_call(SIMCALL_SYS_WRITE, fd, (int)buf, count); }
