1570af302Sopenharmony_ci#include "libc.h" 2570af302Sopenharmony_ci 3570af302Sopenharmony_ci#if defined(__SH4A__) 4570af302Sopenharmony_ci 5570af302Sopenharmony_ci#define a_ll a_ll 6570af302Sopenharmony_cistatic inline int a_ll(volatile int *p) 7570af302Sopenharmony_ci{ 8570af302Sopenharmony_ci int v; 9570af302Sopenharmony_ci __asm__ __volatile__ ("movli.l @%1, %0" : "=z"(v) : "r"(p), "m"(*p)); 10570af302Sopenharmony_ci return v; 11570af302Sopenharmony_ci} 12570af302Sopenharmony_ci 13570af302Sopenharmony_ci#define a_sc a_sc 14570af302Sopenharmony_cistatic inline int a_sc(volatile int *p, int v) 15570af302Sopenharmony_ci{ 16570af302Sopenharmony_ci int r; 17570af302Sopenharmony_ci __asm__ __volatile__ ( 18570af302Sopenharmony_ci "movco.l %2, @%3 ; movt %0" 19570af302Sopenharmony_ci : "=r"(r), "=m"(*p) : "z"(v), "r"(p) : "memory", "cc"); 20570af302Sopenharmony_ci return r; 21570af302Sopenharmony_ci} 22570af302Sopenharmony_ci 23570af302Sopenharmony_ci#define a_barrier a_barrier 24570af302Sopenharmony_cistatic inline void a_barrier() 25570af302Sopenharmony_ci{ 26570af302Sopenharmony_ci __asm__ __volatile__ ("synco" ::: "memory"); 27570af302Sopenharmony_ci} 28570af302Sopenharmony_ci 29570af302Sopenharmony_ci#define a_pre_llsc a_barrier 30570af302Sopenharmony_ci#define a_post_llsc a_barrier 31570af302Sopenharmony_ci 32570af302Sopenharmony_ci#else 33570af302Sopenharmony_ci 34570af302Sopenharmony_ci#define a_cas a_cas 35570af302Sopenharmony_ciextern hidden const void *__sh_cas_ptr; 36570af302Sopenharmony_cistatic inline int a_cas(volatile int *p, int t, int s) 37570af302Sopenharmony_ci{ 38570af302Sopenharmony_ci register int r1 __asm__("r1"); 39570af302Sopenharmony_ci register int r2 __asm__("r2") = t; 40570af302Sopenharmony_ci register int r3 __asm__("r3") = s; 41570af302Sopenharmony_ci __asm__ __volatile__ ( 42570af302Sopenharmony_ci "jsr @%4 ; nop" 43570af302Sopenharmony_ci : "=r"(r1), "+r"(r3) : "z"(p), "r"(r2), "r"(__sh_cas_ptr) 44570af302Sopenharmony_ci : "memory", "pr", "cc"); 45570af302Sopenharmony_ci return r3; 46570af302Sopenharmony_ci} 47570af302Sopenharmony_ci 48570af302Sopenharmony_ci#endif 49