15af32e75SAxel Dörfler/* 25af32e75SAxel Dörfler** Copyright 2003, Marcus Overhagen. All rights reserved. 35af32e75SAxel Dörfler** Distributed under the terms of the OpenBeOS license. 45af32e75SAxel Dörfler** 55af32e75SAxel Dörfler** Copyright 2001, Travis Geiselbrecht. All rights reserved. 65af32e75SAxel Dörfler** Distributed under the terms of the NewOS License. 75af32e75SAxel Dörfler*/ 85af32e75SAxel Dörfler 98cc14638SIngo Weinhold#include <asm_defs.h> 108cc14638SIngo Weinhold 115af32e75SAxel Dörfler 125af32e75SAxel Dörfler.text 135af32e75SAxel Dörfler 145af32e75SAxel Dörfler/* int32 atomic_set(vint32 *value, int32 newValue) */ 155af32e75SAxel DörflerFUNCTION(atomic_set): 165af32e75SAxel Dörfler movl 4(%esp),%edx 175af32e75SAxel Dörfler movl 8(%esp),%eax 185af32e75SAxel Dörfler lock 195af32e75SAxel Dörfler xchg %eax,(%edx) 205af32e75SAxel Dörfler ret 218cc14638SIngo WeinholdFUNCTION_END(atomic_set) 225af32e75SAxel Dörfler 235af32e75SAxel Dörfler/* int32 atomic_test_and_set(vint32 *value, int32 newValue, int32 testAgainst) */ 245af32e75SAxel DörflerFUNCTION(atomic_test_and_set): 255af32e75SAxel Dörfler movl 4(%esp),%edx 265af32e75SAxel Dörfler movl 8(%esp),%ecx 275af32e75SAxel Dörfler movl 12(%esp),%eax 285af32e75SAxel Dörfler lock 295af32e75SAxel Dörfler cmpxchgl %ecx,(%edx) 305af32e75SAxel Dörfler ret 318cc14638SIngo WeinholdFUNCTION_END(atomic_test_and_set) 325af32e75SAxel Dörfler 335af32e75SAxel Dörfler/* int32 atomic_add(vint32 *value, int32 addValue) */ 345af32e75SAxel DörflerFUNCTION(atomic_add): 355af32e75SAxel Dörfler movl 4(%esp),%edx 365af32e75SAxel Dörfler movl 8(%esp),%eax 375af32e75SAxel Dörfler lock 385af32e75SAxel Dörfler xaddl %eax,(%edx) 395af32e75SAxel Dörfler ret 408cc14638SIngo WeinholdFUNCTION_END(atomic_add) 415af32e75SAxel Dörfler 425af32e75SAxel Dörfler/* int32 atomic_and(vint32 *value, int32 andValue) */ 435af32e75SAxel DörflerFUNCTION(atomic_and): 445af32e75SAxel Dörfler movl 4(%esp),%edx 455af32e75SAxel Dörfler_atomic_and1: 465af32e75SAxel Dörfler movl 8(%esp),%ecx 475af32e75SAxel Dörfler movl (%edx),%eax 485af32e75SAxel Dörfler andl %eax,%ecx 495af32e75SAxel Dörfler lock 505af32e75SAxel Dörfler cmpxchgl %ecx,(%edx) 515af32e75SAxel Dörfler jnz _atomic_and1 525af32e75SAxel Dörfler ret 538cc14638SIngo WeinholdFUNCTION_END(atomic_and) 545af32e75SAxel Dörfler 555af32e75SAxel Dörfler/* int32 atomic_or(vint32 *value, int32 orValue) */ 565af32e75SAxel DörflerFUNCTION(atomic_or): 575af32e75SAxel Dörfler movl 4(%esp),%edx 585af32e75SAxel Dörfler_atomic_or1: 595af32e75SAxel Dörfler movl 8(%esp),%ecx 605af32e75SAxel Dörfler movl (%edx),%eax 615af32e75SAxel Dörfler orl %eax,%ecx 625af32e75SAxel Dörfler lock 635af32e75SAxel Dörfler cmpxchgl %ecx,(%edx) 645af32e75SAxel Dörfler jnz _atomic_or1 655af32e75SAxel Dörfler ret 668cc14638SIngo WeinholdFUNCTION_END(atomic_or) 675af32e75SAxel Dörfler 685af32e75SAxel Dörfler/* int32 atomic_get(vint32 *value) */ 695af32e75SAxel DörflerFUNCTION(atomic_get): 705af32e75SAxel Dörfler movl 4(%esp), %edx 715af32e75SAxel Dörfler_atomic_get1: 725af32e75SAxel Dörfler movl (%edx), %eax 735af32e75SAxel Dörfler movl %eax, %ecx 745af32e75SAxel Dörfler lock 755af32e75SAxel Dörfler cmpxchgl %ecx, (%edx) 765af32e75SAxel Dörfler jnz _atomic_get1 775af32e75SAxel Dörfler ret 788cc14638SIngo WeinholdFUNCTION_END(atomic_get) 795af32e75SAxel Dörfler 805af32e75SAxel Dörfler/* int64 atomic_set64(vint64 *value, int64 newValue) */ 815af32e75SAxel DörflerFUNCTION(atomic_set64): 82*f711e9dcSIngo Weinhold push %esi 835af32e75SAxel Dörfler push %ebx 84*f711e9dcSIngo Weinhold movl 12(%esp), %esi /* value */ 855af32e75SAxel Dörfler movl 16(%esp), %ebx /* newValue low */ 865af32e75SAxel Dörfler movl 20(%esp), %ecx /* newValue high */ 875af32e75SAxel Dörfler_atomic_set64_1: 88*f711e9dcSIngo Weinhold movl (%esi), %eax /* testAgainst low */ 89*f711e9dcSIngo Weinhold movl 4(%esi), %edx /* testAgainst high */ 905af32e75SAxel Dörfler lock 91*f711e9dcSIngo Weinhold cmpxchg8b (%esi) 925af32e75SAxel Dörfler jnz _atomic_set64_1 935af32e75SAxel Dörfler pop %ebx 94*f711e9dcSIngo Weinhold pop %esi 955af32e75SAxel Dörfler ret 968cc14638SIngo WeinholdFUNCTION_END(atomic_set64) 975af32e75SAxel Dörfler 985af32e75SAxel Dörfler/* int64 atomic_test_and_set64(vint64 *value, int64 newValue, int64 testAgainst) */ 995af32e75SAxel DörflerFUNCTION(atomic_test_and_set64): 100*f711e9dcSIngo Weinhold push %esi 1015af32e75SAxel Dörfler push %ebx 102*f711e9dcSIngo Weinhold movl 12(%esp), %esi /* value */ 1035af32e75SAxel Dörfler movl 16(%esp), %ebx /* newValue low */ 1045af32e75SAxel Dörfler movl 20(%esp), %ecx /* newValue high */ 1055af32e75SAxel Dörfler movl 24(%esp), %eax /* testAgainst low */ 1065af32e75SAxel Dörfler movl 28(%esp), %edx /* testAgainst high */ 1075af32e75SAxel Dörfler lock 108*f711e9dcSIngo Weinhold cmpxchg8b (%esi) 1095af32e75SAxel Dörfler pop %ebx 110*f711e9dcSIngo Weinhold pop %esi 1115af32e75SAxel Dörfler ret 1128cc14638SIngo WeinholdFUNCTION_END(atomic_test_and_set64) 1135af32e75SAxel Dörfler 1145af32e75SAxel Dörfler/* int64 atomic_add64(vint64 *value, int64 addValue) */ 1155af32e75SAxel DörflerFUNCTION(atomic_add64): 116*f711e9dcSIngo Weinhold push %esi 1175af32e75SAxel Dörfler push %ebx 118*f711e9dcSIngo Weinhold movl 12(%esp), %esi 1195af32e75SAxel Dörfler_atomic_add64_1: 120*f711e9dcSIngo Weinhold movl (%esi), %eax 121*f711e9dcSIngo Weinhold movl 4(%esi), %edx 1225af32e75SAxel Dörfler movl %eax, %ebx 1235af32e75SAxel Dörfler movl %edx, %ecx 1245af32e75SAxel Dörfler addl 16(%esp), %ebx 1255af32e75SAxel Dörfler adcl 20(%esp), %ecx 1265af32e75SAxel Dörfler lock 127*f711e9dcSIngo Weinhold cmpxchg8b (%esi) 1285af32e75SAxel Dörfler jnz _atomic_add64_1 1295af32e75SAxel Dörfler pop %ebx 130*f711e9dcSIngo Weinhold pop %esi 1315af32e75SAxel Dörfler ret 1328cc14638SIngo WeinholdFUNCTION_END(atomic_add64) 1335af32e75SAxel Dörfler 1345af32e75SAxel Dörfler/* int64 atomic_and64(vint64 *value, int64 andValue) */ 1355af32e75SAxel DörflerFUNCTION(atomic_and64): 136*f711e9dcSIngo Weinhold push %esi 1375af32e75SAxel Dörfler push %ebx 138*f711e9dcSIngo Weinhold movl 12(%esp), %esi 1395af32e75SAxel Dörfler_atomic_and64_1: 140*f711e9dcSIngo Weinhold movl (%esi), %eax 141*f711e9dcSIngo Weinhold movl 4(%esi), %edx 1425af32e75SAxel Dörfler movl %eax, %ebx 1435af32e75SAxel Dörfler movl %edx, %ecx 1445af32e75SAxel Dörfler andl 16(%esp), %ebx 1455af32e75SAxel Dörfler andl 20(%esp), %ecx 1465af32e75SAxel Dörfler lock 147*f711e9dcSIngo Weinhold cmpxchg8b (%esi) 1485af32e75SAxel Dörfler jnz _atomic_and64_1 1495af32e75SAxel Dörfler pop %ebx 150*f711e9dcSIngo Weinhold pop %esi 1515af32e75SAxel Dörfler ret 1528cc14638SIngo WeinholdFUNCTION_END(atomic_and64) 1535af32e75SAxel Dörfler 1545af32e75SAxel Dörfler/* int64 atomic_or64(vint64 *value, int64 orValue) */ 1555af32e75SAxel DörflerFUNCTION(atomic_or64): 156*f711e9dcSIngo Weinhold push %esi 1575af32e75SAxel Dörfler push %ebx 158*f711e9dcSIngo Weinhold movl 12(%esp), %esi 1595af32e75SAxel Dörfler_atomic_or64_1: 160*f711e9dcSIngo Weinhold movl (%esi), %eax 161*f711e9dcSIngo Weinhold movl 4(%esi), %edx 1625af32e75SAxel Dörfler movl %eax, %ebx 1635af32e75SAxel Dörfler movl %edx, %ecx 1645af32e75SAxel Dörfler orl 16(%esp), %ebx 1655af32e75SAxel Dörfler orl 20(%esp), %ecx 1665af32e75SAxel Dörfler lock 167*f711e9dcSIngo Weinhold cmpxchg8b (%esi) 1685af32e75SAxel Dörfler jnz _atomic_or64_1 1695af32e75SAxel Dörfler pop %ebx 170*f711e9dcSIngo Weinhold pop %esi 1715af32e75SAxel Dörfler ret 1728cc14638SIngo WeinholdFUNCTION_END(atomic_or64) 1735af32e75SAxel Dörfler 1745af32e75SAxel Dörfler/* int64 atomic_get64(vint64 *value) */ 1755af32e75SAxel DörflerFUNCTION(atomic_get64): 176*f711e9dcSIngo Weinhold push %esi 1775af32e75SAxel Dörfler push %ebx 178*f711e9dcSIngo Weinhold movl 12(%esp), %esi 1795af32e75SAxel Dörfler_atomic_get64_1: 180*f711e9dcSIngo Weinhold movl (%esi), %eax 181*f711e9dcSIngo Weinhold movl 4(%esi), %edx 1825af32e75SAxel Dörfler movl %eax, %ebx 1835af32e75SAxel Dörfler movl %edx, %ecx 1845af32e75SAxel Dörfler lock 185*f711e9dcSIngo Weinhold cmpxchg8b (%esi) 1865af32e75SAxel Dörfler jnz _atomic_get64_1 1875af32e75SAxel Dörfler pop %ebx 188*f711e9dcSIngo Weinhold pop %esi 1895af32e75SAxel Dörfler ret 1908cc14638SIngo WeinholdFUNCTION_END(atomic_get64) 191