tinycc/lib/armflush.c
grischka 7f7845cd7e review some recent changes
tccrun.c:
- simplify usage of VirtualAlloc on win32/64
  from 6728a64f1b
tccpe.c:
- revert changes to pe_create_pdb()
  (doesn't work and/or too much complication)
  from 37b7247796
- reduce #ifdef amount
tccgen.c:
- fix fix for cast to void
  from fad812360b
tccelf.c:
- put create_riscv_attribute_section() into right place
  from c77339ab41
tcc.h/libtcc.c:
- simplify link-option parser for pe dll_characteristics
  from 1a54e47dda
i386-gen.c:
- fix tls
  from 8502540b4a
workflow/build.yml:
- add i386-linux
- disable riscv64-linux-native (seems not supported currently)
2026-07-08 14:01:40 +02:00

71 lines
1.6 KiB
C

/* armflush.c - flush the instruction cache
__clear_cache is used in tccrun.c, It is a built-in
intrinsic with gcc. However tcc in order to compile
itself needs this function */
/* ------------------------------------------------------------- */
#if defined __arm__
#ifdef __TINYC__
/* syscall wrapper */
unsigned _tccsyscall(unsigned syscall_nr, ...);
/* arm-tcc supports only fake asm currently */
__asm__(
".global _tccsyscall\n"
"_tccsyscall:\n"
"push {r7, lr}\n\t"
"mov r7, r0\n\t"
"mov r0, r1\n\t"
"mov r1, r2\n\t"
"mov r2, r3\n\t"
"svc #0\n\t"
"pop {r7, pc}"
);
/* from unistd.h: */
#if defined(__thumb__) || defined(__ARM_EABI__)
# define __NR_SYSCALL_BASE 0x0
#else
# define __NR_SYSCALL_BASE 0x900000
#endif
#define __ARM_NR_BASE (__NR_SYSCALL_BASE+0x0f0000)
#define __ARM_NR_cacheflush (__ARM_NR_BASE+2)
#define syscall _tccsyscall
#else
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <stdio.h>
#endif
/* Flushing for tccrun */
void __clear_cache(void *beginning, void *end)
{
/* __ARM_NR_cacheflush is kernel private and should not be used in user space.
* However, there is no ARM asm parser in tcc so we use it for now */
syscall(__ARM_NR_cacheflush, beginning, end, 0);
}
/* ------------------------------------------------------------- */
#elif defined __aarch64__
void __clear_cache(void *beg, void *end)
{
__arm64_clear_cache(beg, end);
}
/* ------------------------------------------------------------- */
#elif defined __riscv
void __clear_cache(void *beg, void *end)
{
__riscv64_clear_cache(beg, end);
}
#endif