[NFC][RISCV][builtins] Remove some hard-coded values from i-cache clear routine

Remove some hard-coded values from i-cache clear routine

Differential Revision: https://reviews.llvm.org/D87578
This commit is contained in:
Alexey Baturo 2020-09-24 10:04:35 +01:00 committed by Luís Marques
parent ff00b58392
commit 303e8cdacb
1 changed files with 7 additions and 1 deletions

View File

@ -46,6 +46,11 @@ uintptr_t GetCurrentProcess(void);
#include <unistd.h>
#endif
#if defined(__linux__) && defined(__riscv)
// to get platform-specific syscall definitions
#include <linux/unistd.h>
#endif
// The compiler generates calls to __clear_cache() when creating
// trampoline functions on the stack for use with nested functions.
// It is expected to invalidate the instruction cache for the
@ -148,9 +153,10 @@ void __clear_cache(void *start, void *end) {
for (uintptr_t dword = start_dword; dword < end_dword; dword += dword_size)
__asm__ volatile("flush %0" : : "r"(dword));
#elif defined(__riscv) && defined(__linux__)
#define __NR_riscv_flush_icache (244 + 15)
// See: arch/riscv/include/asm/cacheflush.h, arch/riscv/kernel/sys_riscv.c
register void *start_reg __asm("a0") = start;
const register void *end_reg __asm("a1") = end;
// "0" means that we clear cache for all threads (SYS_RISCV_FLUSH_ICACHE_ALL)
const register long flags __asm("a2") = 0;
const register long syscall_nr __asm("a7") = __NR_riscv_flush_icache;
__asm __volatile("ecall"