1/* 2** Copyright 2003, Marcus Overhagen. All rights reserved. 3** Distributed under the terms of the OpenBeOS license. 4** 5** Copyright 2001, Travis Geiselbrecht. All rights reserved. 6** Distributed under the terms of the NewOS License. 7*/ 8 9#include <asm_defs.h> 10 11 12.text 13 14/* int32 atomic_set(vint32 *value, int32 newValue) */ 15FUNCTION(atomic_set): 16 movl 4(%esp),%edx 17 movl 8(%esp),%eax 18 lock 19 xchg %eax,(%edx) 20 ret 21FUNCTION_END(atomic_set) 22 23/* int32 atomic_test_and_set(vint32 *value, int32 newValue, int32 testAgainst) */ 24FUNCTION(atomic_test_and_set): 25 movl 4(%esp),%edx 26 movl 8(%esp),%ecx 27 movl 12(%esp),%eax 28 lock 29 cmpxchgl %ecx,(%edx) 30 ret 31FUNCTION_END(atomic_test_and_set) 32 33/* int32 atomic_add(vint32 *value, int32 addValue) */ 34FUNCTION(atomic_add): 35 movl 4(%esp),%edx 36 movl 8(%esp),%eax 37 lock 38 xaddl %eax,(%edx) 39 ret 40FUNCTION_END(atomic_add) 41 42/* int32 atomic_and(vint32 *value, int32 andValue) */ 43FUNCTION(atomic_and): 44 movl 4(%esp),%edx 45_atomic_and1: 46 movl 8(%esp),%ecx 47 movl (%edx),%eax 48 andl %eax,%ecx 49 lock 50 cmpxchgl %ecx,(%edx) 51 jnz _atomic_and1 52 ret 53FUNCTION_END(atomic_and) 54 55/* int32 atomic_or(vint32 *value, int32 orValue) */ 56FUNCTION(atomic_or): 57 movl 4(%esp),%edx 58_atomic_or1: 59 movl 8(%esp),%ecx 60 movl (%edx),%eax 61 orl %eax,%ecx 62 lock 63 cmpxchgl %ecx,(%edx) 64 jnz _atomic_or1 65 ret 66FUNCTION_END(atomic_or) 67 68/* int32 atomic_get(vint32 *value) */ 69FUNCTION(atomic_get): 70 movl 4(%esp), %edx 71_atomic_get1: 72 movl (%edx), %eax 73 movl %eax, %ecx 74 lock 75 cmpxchgl %ecx, (%edx) 76 jnz _atomic_get1 77 ret 78FUNCTION_END(atomic_get) 79 80/* int64 atomic_set64(vint64 *value, int64 newValue) */ 81FUNCTION(atomic_set64): 82 push %esi 83 push %ebx 84 movl 12(%esp), %esi /* value */ 85 movl 16(%esp), %ebx /* newValue low */ 86 movl 20(%esp), %ecx /* newValue high */ 87_atomic_set64_1: 88 movl (%esi), %eax /* testAgainst low */ 89 movl 4(%esi), %edx /* testAgainst high */ 90 lock 91 cmpxchg8b (%esi) 92 jnz _atomic_set64_1 93 pop %ebx 94 pop %esi 95 ret 96FUNCTION_END(atomic_set64) 97 98/* int64 atomic_test_and_set64(vint64 *value, int64 newValue, int64 testAgainst) */ 99FUNCTION(atomic_test_and_set64): 100 push %esi 101 push %ebx 102 movl 12(%esp), %esi /* value */ 103 movl 16(%esp), %ebx /* newValue low */ 104 movl 20(%esp), %ecx /* newValue high */ 105 movl 24(%esp), %eax /* testAgainst low */ 106 movl 28(%esp), %edx /* testAgainst high */ 107 lock 108 cmpxchg8b (%esi) 109 pop %ebx 110 pop %esi 111 ret 112FUNCTION_END(atomic_test_and_set64) 113 114/* int64 atomic_add64(vint64 *value, int64 addValue) */ 115FUNCTION(atomic_add64): 116 push %esi 117 push %ebx 118 movl 12(%esp), %esi 119_atomic_add64_1: 120 movl (%esi), %eax 121 movl 4(%esi), %edx 122 movl %eax, %ebx 123 movl %edx, %ecx 124 addl 16(%esp), %ebx 125 adcl 20(%esp), %ecx 126 lock 127 cmpxchg8b (%esi) 128 jnz _atomic_add64_1 129 pop %ebx 130 pop %esi 131 ret 132FUNCTION_END(atomic_add64) 133 134/* int64 atomic_and64(vint64 *value, int64 andValue) */ 135FUNCTION(atomic_and64): 136 push %esi 137 push %ebx 138 movl 12(%esp), %esi 139_atomic_and64_1: 140 movl (%esi), %eax 141 movl 4(%esi), %edx 142 movl %eax, %ebx 143 movl %edx, %ecx 144 andl 16(%esp), %ebx 145 andl 20(%esp), %ecx 146 lock 147 cmpxchg8b (%esi) 148 jnz _atomic_and64_1 149 pop %ebx 150 pop %esi 151 ret 152FUNCTION_END(atomic_and64) 153 154/* int64 atomic_or64(vint64 *value, int64 orValue) */ 155FUNCTION(atomic_or64): 156 push %esi 157 push %ebx 158 movl 12(%esp), %esi 159_atomic_or64_1: 160 movl (%esi), %eax 161 movl 4(%esi), %edx 162 movl %eax, %ebx 163 movl %edx, %ecx 164 orl 16(%esp), %ebx 165 orl 20(%esp), %ecx 166 lock 167 cmpxchg8b (%esi) 168 jnz _atomic_or64_1 169 pop %ebx 170 pop %esi 171 ret 172FUNCTION_END(atomic_or64) 173 174/* int64 atomic_get64(vint64 *value) */ 175FUNCTION(atomic_get64): 176 push %esi 177 push %ebx 178 movl 12(%esp), %esi 179_atomic_get64_1: 180 movl (%esi), %eax 181 movl 4(%esi), %edx 182 movl %eax, %ebx 183 movl %edx, %ecx 184 lock 185 cmpxchg8b (%esi) 186 jnz _atomic_get64_1 187 pop %ebx 188 pop %esi 189 ret 190FUNCTION_END(atomic_get64) 191