Improve atomic memory access and support -mno-atomic.

Use CONFIG_GENERIC_ATOMIC64 if 32-bit.  Add system call to emulate
atomic compare exchange, primarily for targets lacking hardware
support (i.e., lacking RV32A, RV64A).  Support excluding use of
atomic memory instructions (-mno-atomic).

This change is mutually dependent on the corresponding change to
riscv-gcc.
On 08/16/2014 02:02 AM, Albert Ou wrote:
> In arch/riscv/include/asm/unistd.h:
> 
>> @@ -14,8 +14,14 @@
>>  
>>  #include <asm-generic/unistd.h>
>>  
>> +#define __NR_sysriscv  __NR_arch_specific_syscall
>> +__SYSCALL(__NR_sysriscv, sys_sysriscv)
> 
> To avoid a link error, this line should be guarded by |#ifdef
> CONFIG_RV_SYSRISCV_ATOMIC|. If that is not feasible for some reason, at
> least define a stub for |sys_sysriscv()| in the case of
> |!CONFIG_RV_SYSRISCV_ATOMIC|. For example:
> 
> SYSCALL_DEFINE4(sysriscv, unsigned long, cmd, unsigned long, arg1,
>     unsigned long, arg2, unsigned long, arg3)
> {
> #ifdef CONFIG_RV_SYSRISCV_ATOMIC
> ...
> #else /* !CONFIG_RV_SYSRISCV_ATOMIC */
>     return -ENOSYS;
> #endif /* CONFIG_RV_SYSRISCV_ATOMIC */
> }
> 

Ok, understood.

The reason I omitted the #ifdef CONFIG_RV_SYSRISCV_ATOMIC guard was
because it prevented __NR_sysriscv from being defined when the header
was used by glibc.  I wanted to avoid manually defining that in both places.

I do not believe glibc knows about the kernel configuration macros, so I
think the solution is to provide the stub system call you suggest.

// darius