diff --git a/options/glibc/generic/sys-cachectl.cpp b/options/glibc/generic/sys-cachectl.cpp new file mode 100644 index 0000000000..a57dac9913 --- /dev/null +++ b/options/glibc/generic/sys-cachectl.cpp @@ -0,0 +1,16 @@ +#include +#include +#include +#include + +#ifdef __riscv +int __riscv_flush_icache(void *start, void *end, unsigned long flags) { + auto sysdep = MLIBC_CHECK_OR_ENOSYS(mlibc::sys_riscv_flush_icache, -1); + + if(int e = sysdep(start, end, flags); e) { + errno = e; + return -1; + } + return 0; +} +#endif diff --git a/options/glibc/include/mlibc/glibc-sysdeps.hpp b/options/glibc/include/mlibc/glibc-sysdeps.hpp index a3888ce248..29b6c1a022 100644 --- a/options/glibc/include/mlibc/glibc-sysdeps.hpp +++ b/options/glibc/include/mlibc/glibc-sysdeps.hpp @@ -11,6 +11,10 @@ namespace [[gnu::visibility("hidden")]] mlibc { [[gnu::weak]] int sys_ioperm(unsigned long int from, unsigned long int num, int turn_on); [[gnu::weak]] int sys_iopl(int level); +#ifdef __riscv +[[gnu::weak]] int sys_riscv_flush_icache(void *start, void *end, unsigned long flags); +#endif + } // namespace mlibc #endif // MLIBC_GLIBC_SYSDEPS diff --git a/options/glibc/include/sys/cachectl.h b/options/glibc/include/sys/cachectl.h new file mode 100644 index 0000000000..f6b2d8ce01 --- /dev/null +++ b/options/glibc/include/sys/cachectl.h @@ -0,0 +1,16 @@ +#ifndef _SYS_CACHECTL_H +#define _SYS_CACHECTL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __riscv +int __riscv_flush_icache(void *, void *, unsigned long); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/options/glibc/meson.build b/options/glibc/meson.build index c4bfebaaa7..d57c32d16b 100644 --- a/options/glibc/meson.build +++ b/options/glibc/meson.build @@ -18,6 +18,7 @@ libc_sources += files( 'generic/sys-timex.cpp', 'generic/glibc-assert.cpp', 'generic/malloc.cpp', + 'generic/sys-cachectl.cpp', 'generic/sys-io.cpp', 'generic/search.cpp' ) @@ -41,6 +42,7 @@ if not no_headers 'include/features.h' ) install_headers( + 'include/sys/cachectl.h', 'include/sys/dir.h', 'include/sys/ioctl.h', 'include/sys/user.h',