kernel, libroot: use C++11 atomics in atomic_*()
The less assembler in our sources the better. These functions wouldn't be used very much since SupportDef.h inlines them, but the symbols should be available. Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
This commit is contained in:
parent
aa58f7e431
commit
d3b1caa62d
@ -11,9 +11,13 @@ SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) kernel lib ] ;
|
||||
|
||||
UsePrivateHeaders [ FDirName libroot locale ] ;
|
||||
|
||||
local extraSources = ;
|
||||
if $(TARGET_GCC_VERSION_$(TARGET_PACKAGING_ARCH)[1]) = 2 {
|
||||
extraSources += atomic.S ;
|
||||
}
|
||||
|
||||
BootMergeObject boot_libroot.o :
|
||||
abs.c
|
||||
atomic.S
|
||||
ctype.cpp
|
||||
LocaleData.cpp
|
||||
qsort.c
|
||||
@ -36,6 +40,7 @@ BootMergeObject boot_libroot.o :
|
||||
strchr.c
|
||||
strrchr.c
|
||||
strtol.c
|
||||
$(extraSources)
|
||||
: -fno-pic
|
||||
;
|
||||
|
||||
|
@ -9,7 +9,6 @@ SEARCH_SOURCE += [ FDirName $(librootSources) os arch $(TARGET_ARCH) ] ;
|
||||
SEARCH_SOURCE += [ FDirName $(librootSources) os arch generic ] ;
|
||||
|
||||
KernelMergeObject kernel_os_arch_$(TARGET_ARCH).o :
|
||||
atomic.S
|
||||
byteorder.S
|
||||
|
||||
generic_atomic.cpp
|
||||
|
@ -10,13 +10,14 @@ local librootSources = [ FDirName $(HAIKU_TOP) src system libroot ] ;
|
||||
local posixSources = [ FDirName $(librootSources) posix ] ;
|
||||
|
||||
SEARCH_SOURCE += [ FDirName $(librootSources) os arch $(TARGET_ARCH) ] ;
|
||||
SEARCH_SOURCE += [ FDirName $(librootSources) os arch generic ] ;
|
||||
|
||||
KernelMergeObject kernel_os_arch_$(TARGET_ARCH).o :
|
||||
atomic.S
|
||||
byteorder.S
|
||||
system_time_asm.S
|
||||
system_time.c
|
||||
|
||||
generic_atomic.cpp
|
||||
: $(TARGET_KERNEL_PIC_CCFLAGS)
|
||||
;
|
||||
|
||||
|
@ -11,7 +11,6 @@ for architectureObject in [ MultiArchSubDirSetup arm ] {
|
||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) generic ] ;
|
||||
|
||||
MergeObject <$(architecture)>os_arch_$(TARGET_ARCH).o :
|
||||
atomic.S
|
||||
byteorder.S
|
||||
system_time.c
|
||||
stack_frame.c
|
||||
|
@ -1,113 +0,0 @@
|
||||
/*
|
||||
** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
||||
** Distributed under the terms of the OpenBeOS License.
|
||||
*/
|
||||
|
||||
#include <asm_defs.h>
|
||||
#include <arch_config.h>
|
||||
|
||||
|
||||
.text
|
||||
|
||||
#ifndef ATOMIC_FUNCS_ARE_SYSCALLS
|
||||
|
||||
/* int atomic_add(int *value, int increment)
|
||||
*/
|
||||
FUNCTION(atomic_add):
|
||||
miss1: ldrex r12, [r0]
|
||||
add r2, r12, r1
|
||||
strex r3, r2, [r0]
|
||||
teq r3, #0
|
||||
bne miss1
|
||||
mov r0, r12
|
||||
bx lr
|
||||
FUNCTION_END(atomic_add)
|
||||
|
||||
/* int atomic_and(int *value, int andValue)
|
||||
*/
|
||||
FUNCTION(atomic_and):
|
||||
miss2: ldrex r12, [r0]
|
||||
and r2, r12, r1
|
||||
strex r3, r2, [r0]
|
||||
teq r3, #0
|
||||
bne miss2
|
||||
mov r0, r12
|
||||
bx lr
|
||||
FUNCTION_END(atomic_and)
|
||||
|
||||
/* int atomic_or(int *value, int orValue)
|
||||
*/
|
||||
FUNCTION(atomic_or):
|
||||
miss3: ldrex r12, [r0]
|
||||
eor r2, r12, r1
|
||||
strex r3, r2, [r0]
|
||||
teq r3, #0
|
||||
bne miss3
|
||||
mov r0, r12
|
||||
bx lr
|
||||
FUNCTION_END(atomic_or)
|
||||
|
||||
/* void atomic_set(int *value, int setTo)
|
||||
*/
|
||||
FUNCTION(atomic_set):
|
||||
str r1, [r0]
|
||||
bx lr
|
||||
FUNCTION_END(atomic_set)
|
||||
|
||||
/* int atomic_test_and_set(int *value, int setTo, int testValue)
|
||||
*/
|
||||
FUNCTION(atomic_test_and_set):
|
||||
miss5: ldrex r12, [r0] @ load from the address and mark it exclusive
|
||||
cmp r12, r2 @ compare the value with the comperand(r2)
|
||||
strexeq r3, r1, [r0] @ if they were equal, attempt to store the new value (r1)
|
||||
bne differ @ if they were not equal jump to (differ) which clears the exclusive tag on the address and returns<
|
||||
cmp r3, #1 @ check the status of the store (returned in r3)
|
||||
beq miss5 @ go back to the start if it failed (0=success, 1=failure)
|
||||
bne same @ if it succeeded, jump to (same) and return. there is no need to clrex if strex succeeded
|
||||
differ: clrex @ clrex
|
||||
same: mov r0, r12
|
||||
bx lr
|
||||
FUNCTION_END(atomic_test_and_set)
|
||||
|
||||
/* int atomic_get(int *value)
|
||||
*/
|
||||
FUNCTION(atomic_get):
|
||||
ldr r0, [r0]
|
||||
bx lr
|
||||
FUNCTION_END(atomic_get)
|
||||
|
||||
#endif /* ATOMIC_FUNCS_ARE_SYSCALLS */
|
||||
|
||||
#ifndef ATOMIC64_FUNCS_ARE_SYSCALLS
|
||||
|
||||
/* int64 atomic_add64(vint64 *value, int64 addValue) */
|
||||
FUNCTION(atomic_add64):
|
||||
bx lr
|
||||
FUNCTION_END(atomic_add64)
|
||||
|
||||
/* int64 atomic_and64(vint64 *value, int64 andValue) */
|
||||
FUNCTION(atomic_and64):
|
||||
bx lr
|
||||
FUNCTION_END(atomic_and64)
|
||||
|
||||
/* int64 atomic_or64(vint64 *value, int64 orValue) */
|
||||
FUNCTION(atomic_or64):
|
||||
bx lr
|
||||
FUNCTION_END(atomic_or64)
|
||||
|
||||
/* int64 atomic_set64(vint64 *value, int64 newValue) */
|
||||
FUNCTION(atomic_set64):
|
||||
bx lr
|
||||
FUNCTION_END(atomic_set64)
|
||||
|
||||
/* int64 atomic_test_and_set64(vint64 *value, int64 newValue, int64 testAgainst) */
|
||||
FUNCTION(atomic_test_and_set64):
|
||||
bx lr
|
||||
FUNCTION_END(atomic_test_and_set64)
|
||||
|
||||
/* int64 atomic_get64(vint64 *value) */
|
||||
FUNCTION(atomic_get64):
|
||||
bx lr
|
||||
FUNCTION_END(atomic_get64)
|
||||
|
||||
#endif /* ATOMIC64_FUNCS_ARE_SYSCALLS */
|
@ -12,8 +12,9 @@ for architectureObject in [ MultiArchSubDirSetup x86_64 ] {
|
||||
# TODO in time.c!
|
||||
UsePrivateSystemHeaders ;
|
||||
|
||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) generic ] ;
|
||||
|
||||
MergeObject <$(architecture)>os_arch_$(TARGET_ARCH).o :
|
||||
atomic.S
|
||||
byteorder.S
|
||||
get_stack_frame.S
|
||||
system_info.cpp
|
||||
@ -21,6 +22,8 @@ for architectureObject in [ MultiArchSubDirSetup x86_64 ] {
|
||||
thread.cpp
|
||||
time.cpp
|
||||
tls.cpp
|
||||
|
||||
generic_atomic.cpp
|
||||
;
|
||||
}
|
||||
}
|
||||
|
@ -1,153 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013, Paweł Dziepak, pdziepak@quarnos.org.
|
||||
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <asm_defs.h>
|
||||
|
||||
|
||||
.text
|
||||
|
||||
|
||||
/* int32 atomic_set(int32* value, int32 newValue) */
|
||||
FUNCTION(atomic_set):
|
||||
sfence
|
||||
movl %esi, (%rdi)
|
||||
ret
|
||||
FUNCTION_END(atomic_set)
|
||||
|
||||
|
||||
/* int32 atomic_get_and_set(int32* value, int32 newValue) */
|
||||
FUNCTION(atomic_get_and_set):
|
||||
movl %esi, %eax
|
||||
xchgl %eax, (%rdi)
|
||||
ret
|
||||
FUNCTION_END(atomic_get_and_set)
|
||||
|
||||
|
||||
/* int32 atomic_test_and_set(int32* value, int32 newValue, int32 testAgainst) */
|
||||
FUNCTION(atomic_test_and_set):
|
||||
movl %edx, %eax
|
||||
lock
|
||||
cmpxchgl %esi, (%rdi)
|
||||
ret
|
||||
FUNCTION_END(atomic_test_and_set)
|
||||
|
||||
|
||||
/* int32 atomic_add(int32* value, int32 addValue) */
|
||||
FUNCTION(atomic_add):
|
||||
movl %esi, %eax
|
||||
lock
|
||||
xaddl %eax, (%rdi)
|
||||
ret
|
||||
FUNCTION_END(atomic_add)
|
||||
|
||||
|
||||
/* int32 atomic_and(int32* value, int32 andValue) */
|
||||
FUNCTION(atomic_and):
|
||||
movl (%rdi), %eax
|
||||
1: movl %eax, %edx
|
||||
movl %eax, %ecx
|
||||
andl %esi, %edx
|
||||
lock
|
||||
cmpxchgl %edx, (%rdi)
|
||||
jnz 1b
|
||||
movl %ecx, %eax
|
||||
ret
|
||||
FUNCTION_END(atomic_and)
|
||||
|
||||
|
||||
/* int32 atomic_or(int32* value, int32 orValue) */
|
||||
FUNCTION(atomic_or):
|
||||
movl (%rdi), %eax
|
||||
1: movl %eax, %edx
|
||||
movl %eax, %ecx
|
||||
orl %esi, %edx
|
||||
lock
|
||||
cmpxchgl %edx, (%rdi)
|
||||
jnz 1b
|
||||
movl %ecx, %eax
|
||||
ret
|
||||
FUNCTION_END(atomic_or)
|
||||
|
||||
|
||||
/* int32 atomic_get(int32* value) */
|
||||
FUNCTION(atomic_get):
|
||||
movl (%rdi), %eax
|
||||
lfence
|
||||
ret
|
||||
FUNCTION_END(atomic_get)
|
||||
|
||||
|
||||
/* int64 atomic_set64(int64* value, int64 newValue) */
|
||||
FUNCTION(atomic_set64):
|
||||
sfence
|
||||
movq %rsi, (%rdi)
|
||||
ret
|
||||
FUNCTION_END(atomic_set64)
|
||||
|
||||
|
||||
/* int64 atomic_get_and_set64(int64* value, int64 newValue) */
|
||||
FUNCTION(atomic_get_and_set64):
|
||||
movq %rsi, %rax
|
||||
xchgq %rax, (%rdi)
|
||||
ret
|
||||
FUNCTION_END(atomic_get_and_set64)
|
||||
|
||||
|
||||
/* int64 atomic_test_and_set64(int64* value, int64 newValue,
|
||||
int64 testAgainst) */
|
||||
FUNCTION(atomic_test_and_set64):
|
||||
movq %rdx, %rax
|
||||
lock
|
||||
cmpxchgq %rsi, (%rdi)
|
||||
ret
|
||||
FUNCTION_END(atomic_test_and_set64)
|
||||
|
||||
|
||||
/* int64 atomic_add64(int64* value, int64 addValue) */
|
||||
FUNCTION(atomic_add64):
|
||||
movq %rsi, %rax
|
||||
lock
|
||||
xaddq %rax, (%rdi)
|
||||
ret
|
||||
FUNCTION_END(atomic_add64)
|
||||
|
||||
|
||||
/* int64 atomic_and64(int64* value, int64 andValue) */
|
||||
FUNCTION(atomic_and64):
|
||||
movq (%rdi), %rax
|
||||
1: movq %rax, %rdx
|
||||
movq %rax, %rcx
|
||||
andq %rsi, %rdx
|
||||
lock
|
||||
cmpxchgq %rdx, (%rdi)
|
||||
jnz 1b
|
||||
movq %rcx, %rax
|
||||
ret
|
||||
FUNCTION_END(atomic_and64)
|
||||
|
||||
|
||||
/* int64 atomic_or64(int64* value, int64 orValue) */
|
||||
FUNCTION(atomic_or64):
|
||||
movq (%rdi), %rax
|
||||
1: movq %rax, %rdx
|
||||
movq %rax, %rcx
|
||||
orq %rsi, %rdx
|
||||
lock
|
||||
cmpxchgq %rdx, (%rdi)
|
||||
jnz 1b
|
||||
movq %rcx, %rax
|
||||
ret
|
||||
FUNCTION_END(atomic_or64)
|
||||
|
||||
|
||||
/* int64 atomic_get64(int64* value) */
|
||||
FUNCTION(atomic_get64):
|
||||
movq (%rdi), %rax
|
||||
lfence
|
||||
ret
|
||||
FUNCTION_END(atomic_get64)
|
||||
|
@ -10,7 +10,6 @@ SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) ] ;
|
||||
StaticLibrary libruntime_loader_$(TARGET_ARCH).a :
|
||||
arch_relocate.cpp
|
||||
:
|
||||
<src!system!libroot!os!arch!$(TARGET_ARCH)!$(architecture)>atomic.o
|
||||
<src!system!libroot!os!arch!$(TARGET_ARCH)!$(architecture)>thread.o
|
||||
|
||||
<src!system!libroot!posix!string!arch!$(TARGET_ARCH)!$(architecture)>arch_string.o
|
||||
|
@ -10,7 +10,6 @@ SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) ] ;
|
||||
StaticLibrary libruntime_loader_$(TARGET_ARCH).a :
|
||||
arch_relocate.cpp
|
||||
:
|
||||
<src!system!libroot!os!arch!$(TARGET_ARCH)!$(architecture)>atomic.o
|
||||
<src!system!libroot!os!arch!$(TARGET_ARCH)!$(architecture)>thread.o
|
||||
<src!system!libroot!posix!string!arch!$(TARGET_ARCH)!$(architecture)>arch_string.o
|
||||
;
|
||||
|
Loading…
Reference in New Issue
Block a user