Skip to content

Commit 2af53c8

Browse files
committed
riscv(support,linux): add Linux specfic icache sync codepath
1 parent 3a34ee2 commit 2af53c8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/lj_mcode.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
void sys_icache_invalidate(void *start, size_t len);
3939
#endif
4040

41+
#if LJ_TARGET_RISCV64 && LJ_TARGET_LINUX
42+
#include <unistd.h>
43+
#include <sys/syscall.h>
44+
#include <sys/cachectl.h>
45+
#endif
46+
4147
/* Synchronize data/instruction cache. */
4248
void lj_mcode_sync(void *start, void *end)
4349
{
@@ -52,6 +58,17 @@ void lj_mcode_sync(void *start, void *end)
5258
sys_icache_invalidate(start, (char *)end-(char *)start);
5359
#elif LJ_TARGET_PPC
5460
lj_vm_cachesync(start, end);
61+
#elif LJ_TARGET_RISCV64 && LJ_TARGET_LINUX
62+
#if (defined(__GNUC__) || defined(__clang__))
63+
__asm__ volatile("fence rw, rw");
64+
#else
65+
lj_vm_fence_rw_rw();
66+
#endif
67+
#ifdef __GLIBC__
68+
__riscv_flush_icache(start, end, 0);
69+
#else
70+
syscall(__NR_riscv_flush_icache, start, end, 0UL);
71+
#endif
5572
#elif defined(__GNUC__) || defined(__clang__)
5673
__clear_cache(start, end);
5774
#else

0 commit comments

Comments
 (0)