riscv: asm: implement `j offset`
[tinycc.git] / lib / armflush.c
blobc379e43620cccf43689351e32d2df09cdd6aedfc
1 /* armflush.c - flush the instruction cache
3 __clear_cache is used in tccrun.c, It is a built-in
4 intrinsic with gcc. However tcc in order to compile
5 itself needs this function */
7 #ifdef __TINYC__
9 /* syscall wrapper */
10 unsigned _tccsyscall(unsigned syscall_nr, ...);
12 /* arm-tcc supports only fake asm currently */
13 __asm__(
14 ".global _tccsyscall\n"
15 "_tccsyscall:\n"
16 "push {r7, lr}\n\t"
17 "mov r7, r0\n\t"
18 "mov r0, r1\n\t"
19 "mov r1, r2\n\t"
20 "mov r2, r3\n\t"
21 "svc #0\n\t"
22 "pop {r7, pc}"
25 /* from unistd.h: */
26 #if defined(__thumb__) || defined(__ARM_EABI__)
27 # define __NR_SYSCALL_BASE 0x0
28 #else
29 # define __NR_SYSCALL_BASE 0x900000
30 #endif
31 #define __ARM_NR_BASE (__NR_SYSCALL_BASE+0x0f0000)
32 #define __ARM_NR_cacheflush (__ARM_NR_BASE+2)
34 #define syscall _tccsyscall
36 #else
38 #define _GNU_SOURCE
39 #include <unistd.h>
40 #include <sys/syscall.h>
41 #include <stdio.h>
43 #endif
45 /* Flushing for tccrun */
46 void __clear_cache(void *beginning, void *end)
48 /* __ARM_NR_cacheflush is kernel private and should not be used in user space.
49 * However, there is no ARM asm parser in tcc so we use it for now */
50 syscall(__ARM_NR_cacheflush, beginning, end, 0);