1/* 2 * Copyright 2013, Paweł Dziepak, pdziepak@quarnos.org. 3 * Distributed under the terms of the MIT License. 4 * 5** Copyright 2003, Marcus Overhagen. All rights reserved. 6** Distributed under the terms of the OpenBeOS license. 7** 8** Copyright 2001, Travis Geiselbrecht. All rights reserved. 9** Distributed under the terms of the NewOS License. 10*/ 11 12 13#include <asm_defs.h> 14 15 16.text 17 18 19/* void atomic_set(int32* value, int32 newValue) */ 20FUNCTION(atomic_set): 21 movl 4(%esp), %edx 22 movl 8(%esp), %eax 23 lock 24 addl $0, (%esp) 25 movl %eax, (%edx) 26 ret 27FUNCTION_END(atomic_set) 28 29 30/* int32 atomic_get_and_set(int32* value, int32 newValue) */ 31FUNCTION(atomic_get_and_set): 32 movl 4(%esp), %edx 33 movl 8(%esp), %eax 34 xchg %eax, (%edx) 35 ret 36FUNCTION_END(atomic_get_and_set) 37 38 39/* int32 atomic_test_and_set(int32* value, int32 newValue, 40 int32 testAgainst) */ 41FUNCTION(atomic_test_and_set): 42 movl 4(%esp), %edx 43 movl 8(%esp), %ecx 44 movl 12(%esp), %eax 45 lock 46 cmpxchgl %ecx, (%edx) 47 ret 48FUNCTION_END(atomic_test_and_set) 49 50 51/* int32 atomic_add(int32* value, int32 addValue) */ 52FUNCTION(atomic_add): 53 movl 4(%esp), %edx 54 movl 8(%esp), %eax 55 lock 56 xaddl %eax, (%edx) 57 ret 58FUNCTION_END(atomic_add) 59 60 61/* int32 atomic_and(int32* value, int32 andValue) */ 62FUNCTION(atomic_and): 63 movl 4(%esp), %edx 641: 65 movl 8(%esp), %ecx 66 movl (%edx), %eax 67 andl %eax, %ecx 68 lock 69 cmpxchgl %ecx, (%edx) 70 jnz 1b 71 ret 72FUNCTION_END(atomic_and) 73 74 75/* int32 atomic_or(int32* value, int32 orValue) */ 76FUNCTION(atomic_or): 77 movl 4(%esp), %edx 781: 79 movl 8(%esp), %ecx 80 movl (%edx), %eax 81 orl %eax, %ecx 82 lock 83 cmpxchgl %ecx, (%edx) 84 jnz 1b 85 ret 86FUNCTION_END(atomic_or) 87 88 89/* int32 atomic_get(int32* value) */ 90FUNCTION(atomic_get): 91 movl 4(%esp), %edx 92 movl (%edx), %eax 93 lock 94 addl $0, (%esp) 95 ret 96FUNCTION_END(atomic_get) 97 98 99/* void atomic_set64(int64* value, int64 newValue) */ 100FUNCTION(atomic_set64): 101 push %esi 102 push %ebx 103 movl 12(%esp), %esi /* value */ 104 movl 16(%esp), %ebx /* newValue low */ 105 movl 20(%esp), %ecx /* newValue high */ 1061: 107 movl (%esi), %eax /* testAgainst low */ 108 movl 4(%esi), %edx /* testAgainst high */ 109 lock 110 cmpxchg8b (%esi) 111 jnz 1b 112 pop %ebx 113 pop %esi 114 ret 115FUNCTION_END(atomic_set64) 116 117 118/* void atomic_get_and_set64(int64* value, int64 newValue) */ 119FUNCTION(atomic_get_and_set64): 120 push %esi 121 push %ebx 122 movl 12(%esp), %esi /* value */ 123 movl 16(%esp), %ebx /* newValue low */ 124 movl 20(%esp), %ecx /* newValue high */ 1251: 126 movl (%esi), %eax /* testAgainst low */ 127 movl 4(%esi), %edx /* testAgainst high */ 128 lock 129 cmpxchg8b (%esi) 130 jnz 1b 131 pop %ebx 132 pop %esi 133 ret 134FUNCTION_END(atomic_get_and_set64) 135 136 137/* int64 atomic_test_and_set64(int64* value, int64 newValue, 138 int64 testAgainst) */ 139FUNCTION(atomic_test_and_set64): 140 push %esi 141 push %ebx 142 movl 12(%esp), %esi /* value */ 143 movl 16(%esp), %ebx /* newValue low */ 144 movl 20(%esp), %ecx /* newValue high */ 145 movl 24(%esp), %eax /* testAgainst low */ 146 movl 28(%esp), %edx /* testAgainst high */ 147 lock 148 cmpxchg8b (%esi) 149 pop %ebx 150 pop %esi 151 ret 152FUNCTION_END(atomic_test_and_set64) 153 154 155/* int64 atomic_add64(int64* value, int64 addValue) */ 156FUNCTION(atomic_add64): 157 push %esi 158 push %ebx 159 movl 12(%esp), %esi 1601: 161 movl (%esi), %eax 162 movl 4(%esi), %edx 163 movl %eax, %ebx 164 movl %edx, %ecx 165 addl 16(%esp), %ebx 166 adcl 20(%esp), %ecx 167 lock 168 cmpxchg8b (%esi) 169 jnz 1b 170 pop %ebx 171 pop %esi 172 ret 173FUNCTION_END(atomic_add64) 174 175/* int64 atomic_and64(int64* value, int64 andValue) */ 176FUNCTION(atomic_and64): 177 push %esi 178 push %ebx 179 movl 12(%esp), %esi 1801: 181 movl (%esi), %eax 182 movl 4(%esi), %edx 183 movl %eax, %ebx 184 movl %edx, %ecx 185 andl 16(%esp), %ebx 186 andl 20(%esp), %ecx 187 lock 188 cmpxchg8b (%esi) 189 jnz 1b 190 pop %ebx 191 pop %esi 192 ret 193FUNCTION_END(atomic_and64) 194 195 196/* int64 atomic_or64(int64* value, int64 orValue) */ 197FUNCTION(atomic_or64): 198 push %esi 199 push %ebx 200 movl 12(%esp), %esi 2011: 202 movl (%esi), %eax 203 movl 4(%esi), %edx 204 movl %eax, %ebx 205 movl %edx, %ecx 206 orl 16(%esp), %ebx 207 orl 20(%esp), %ecx 208 lock 209 cmpxchg8b (%esi) 210 jnz 1b 211 pop %ebx 212 pop %esi 213 ret 214FUNCTION_END(atomic_or64) 215 216 217/* int64 atomic_get64(int64* value) */ 218FUNCTION(atomic_get64): 219 push %esi 220 push %ebx 221 movl 12(%esp), %esi 2221: 223 movl (%esi), %eax 224 movl 4(%esi), %edx 225 movl %eax, %ebx 226 movl %edx, %ecx 227 lock 228 cmpxchg8b (%esi) 229 jnz 1b 230 pop %ebx 231 pop %esi 232 ret 233FUNCTION_END(atomic_get64) 234 235