diff --git a/reactos/lib/intrlck/i386/compareexchange.s b/reactos/lib/intrlck/i386/compareexchange.c similarity index 64% rename from reactos/lib/intrlck/i386/compareexchange.s rename to reactos/lib/intrlck/i386/compareexchange.c index 8d4f1cc2542..772f26a2100 100644 --- a/reactos/lib/intrlck/i386/compareexchange.s +++ b/reactos/lib/intrlck/i386/compareexchange.c @@ -1,33 +1,37 @@ -/* - * PROJECT: ReactOS system libraries - * LICENSE: GPL - See COPYING in the top level directory - * FILE: lib/intrlck/i386/compareexchange.s - * PURPOSE: Inter lock compare exchanges - * PROGRAMMERS: Copyright 1995 Martin von Loewis - * Copyright 1997 Onno Hovers - */ - -/************************************************************************ - * InterlockedCompareExchange - * - * Atomically compares Destination and Comperand, and if found equal exchanges - * the value of Destination with Exchange - * - * RETURNS - * Prior value of value pointed to by Destination - */ - -/* - * LONG NTAPI InterlockedCompareExchange(LPLONG Destination, LONG Exchange, LONG Comperand) - */ - -.globl _InterlockedCompareExchange@12 - -_InterlockedCompareExchange@12: - movl 12(%esp),%eax - movl 8(%esp),%ecx - movl 4(%esp),%edx - lock - cmpxchgl %ecx,(%edx) - leave - ret $12 +/* + * PROJECT: ReactOS system libraries + * LICENSE: GPL - See COPYING in the top level directory + * FILE: lib/intrlck/i386/compareexchange.c + * PURPOSE: Inter lock compare exchanges + * PROGRAMMERS: Copyright 1995 Martin von Loewis + * Copyright 1997 Onno Hovers + */ + +/************************************************************************ + * InterlockedCompareExchange + * + * Atomically compares Destination and Comperand, and if found equal exchanges + * the value of Destination with Exchange + * + * RETURNS + * Prior value of value pointed to by Destination + */ + +/* + * LONG NTAPI InterlockedCompareExchange(LPLONG Destination, LONG Exchange, LONG Comperand) + */ + +#include +LONG +NTAPI +InterlockedCompareExchange( + LPLONG Destination, + LONG Exchange, + LONG Comperand) +{ + LONG ret; + __asm__ __volatile__( + "lock; cmpxchgl %2,(%1)" + : "=a" (ret) : "r" (Destination), "r" (Exchange), "0" (Comperand) : "memory" ); + return ret; +} diff --git a/reactos/lib/intrlck/i386/decrement.s b/reactos/lib/intrlck/i386/decrement.c similarity index 71% rename from reactos/lib/intrlck/i386/decrement.s rename to reactos/lib/intrlck/i386/decrement.c index 9509cab0aa1..5337ac989f0 100644 --- a/reactos/lib/intrlck/i386/decrement.s +++ b/reactos/lib/intrlck/i386/decrement.c @@ -1,31 +1,38 @@ -/* - * PROJECT: ReactOS system libraries - * LICENSE: GPL - See COPYING in the top level directory - * FILE: lib/intrlck/i386/decrement.s - * PURPOSE: Inter lock decrements - * PROGRAMMERS: Copyright 1995 Martin von Loewis - * Copyright 1997 Onno Hovers - */ - -/************************************************************************ -* InterlockedDecrement * -* * -* InterlockedDecrement adds -1 to a long variable and returns * -* the resulting decremented value. * -* * -************************************************************************/ - -/* - * LONG NTAPI InterlockedDecrement(LPLONG lpAddend) - */ - -.globl _InterlockedDecrement@4 - -_InterlockedDecrement@4: - movl $-1,%ebx - lock - xaddl %eax,%ebx - decl %eax - leave - ret $4 - +/* + * PROJECT: ReactOS system libraries + * LICENSE: GPL - See COPYING in the top level directory + * FILE: lib/intrlck/i386/decrement.c + * PURPOSE: Inter lock decrements + * PROGRAMMERS: Copyright 1995 Martin von Loewis + * Copyright 1997 Onno Hovers + */ + +/************************************************************************ +* InterlockedDecrement * +* * +* InterlockedDecrement adds -1 to a long variable and returns * +* the resulting decremented value. * +* * +************************************************************************/ + +/* + * LONG NTAPI InterlockedDecrement(LPLONG lpAddend) + */ + +#include +LONG +NTAPI +InterlockedDecrement(LPLONG lpAddend) +{ + LONG ret; + __asm__ + ( + "\tlock\n" /* for SMP systems */ + "\txaddl %0, (%1)\n" + "\tdecl %0\n" + :"=r" (ret) + :"r" (lpAddend), "0" (-1) + : "memory" + ); + return ret; +} diff --git a/reactos/lib/intrlck/i386/exchange.s b/reactos/lib/intrlck/i386/exchange.c similarity index 63% rename from reactos/lib/intrlck/i386/exchange.s rename to reactos/lib/intrlck/i386/exchange.c index 81a1d6c5496..993fe161e7d 100644 --- a/reactos/lib/intrlck/i386/exchange.s +++ b/reactos/lib/intrlck/i386/exchange.c @@ -1,29 +1,34 @@ -/* - * PROJECT: ReactOS system libraries - * LICENSE: GPL - See COPYING in the top level directory - * FILE: lib/intrlck/i386/exchange.s - * PURPOSE: Inter lock exchanges - * PROGRAMMERS: Copyright 1995 Martin von Loewis - * Copyright 1997 Onno Hovers - */ - -/************************************************************************ - * InterlockedExchange - * - * Atomically exchanges a pair of values. - * - * RETURNS - * Prior value of value pointed to by Target - */ - -/* - * LONG NTAPI InterlockedExchange(LPLONG target, LONG value) - */ - -.globl _InterlockedExchange@8 - -_InterlockedExchange@8: - lock - xchgl %eax,%ebx - leave - ret $8 +/* + * PROJECT: ReactOS system libraries + * LICENSE: GPL - See COPYING in the top level directory + * FILE: lib/intrlck/i386/exchange.c + * PURPOSE: Inter lock exchanges + * PROGRAMMERS: Copyright 1995 Martin von Loewis + * Copyright 1997 Onno Hovers + */ + +/************************************************************************ + * InterlockedExchange + * + * Atomically exchanges a pair of values. + * + * RETURNS + * Prior value of value pointed to by Target + */ + +/* + * LONG NTAPI InterlockedExchange(LPLONG target, LONG value) + */ + +#include +LONG +NTAPI +InterlockedExchange(LPLONG target, LONG value) +{ + LONG ret; + __asm__ ( + /* lock for SMP systems */ + "lock\n\txchgl %0,(%1)" + :"=r" (ret):"r" (target), "0" (value):"memory" ); + return ret; +} diff --git a/reactos/lib/intrlck/i386/exchangeadd.s b/reactos/lib/intrlck/i386/exchangeadd.c similarity index 63% rename from reactos/lib/intrlck/i386/exchangeadd.s rename to reactos/lib/intrlck/i386/exchangeadd.c index c4e906e69dc..50afcbe4584 100644 --- a/reactos/lib/intrlck/i386/exchangeadd.s +++ b/reactos/lib/intrlck/i386/exchangeadd.c @@ -1,30 +1,40 @@ -/* - * PROJECT: ReactOS system libraries - * LICENSE: GPL - See COPYING in the top level directory - * FILE: lib/intrlck/i386/exchangeadd.s - * PURPOSE: Inter lock exchange adds - * PROGRAMMERS: Copyright 1995 Martin von Loewis - * Copyright 1997 Onno Hovers - */ - -/************************************************************************ - * InterlockedExchangeAdd - * - * Atomically adds Increment to Addend and returns the previous value of - * Addend - * - * RETURNS - * Prior value of value pointed to by Addend - */ - -/* - * LONG NTAPI InterlockedExchangeAdd(PLONG Addend, LONG Increment) - */ - -.globl _InterlockedExchangeAdd@8 - -_InterlockedExchangeAdd@8: - lock - xaddl %eax,%ebx - leave - ret $4 +/* + * PROJECT: ReactOS system libraries + * LICENSE: GPL - See COPYING in the top level directory + * FILE: lib/intrlck/i386/exchangeadd.c + * PURPOSE: Inter lock exchange adds + * PROGRAMMERS: Copyright 1995 Martin von Loewis + * Copyright 1997 Onno Hovers + */ + +/************************************************************************ + * InterlockedExchangeAdd + * + * Atomically adds Increment to Addend and returns the previous value of + * Addend + * + * RETURNS + * Prior value of value pointed to by Addend + */ + +/* + * LONG NTAPI InterlockedExchangeAdd(PLONG Addend, LONG Increment) + */ + +#include +LONG +NTAPI +InterlockedExchangeAdd( + PLONG Addend, + LONG Increment) +{ + LONG ret; + __asm__ ( + /* lock for SMP systems */ + "lock\n\t" + "xaddl %0,(%1)" + :"=r" (ret) + :"r" (Addend), "0" (Increment) + :"memory" ); + return ret; +} diff --git a/reactos/lib/intrlck/i386/increment.s b/reactos/lib/intrlck/i386/increment.c similarity index 71% rename from reactos/lib/intrlck/i386/increment.s rename to reactos/lib/intrlck/i386/increment.c index 43ef2bba855..8054cdd8591 100644 --- a/reactos/lib/intrlck/i386/increment.s +++ b/reactos/lib/intrlck/i386/increment.c @@ -1,30 +1,38 @@ -/* - * PROJECT: ReactOS system libraries - * LICENSE: GPL - See COPYING in the top level directory - * FILE: lib/intrlck/i386/increment.s - * PURPOSE: Inter lock increments - * PROGRAMMERS: Copyright 1995 Martin von Loewis - * Copyright 1997 Onno Hovers - */ - -/************************************************************************ -* InterlockedIncrement * -* * -* InterlockedIncrement adds 1 to a long variable and returns * -* the resulting incremented value. * -* * -************************************************************************/ - -/* - * LONG NTAPI InterlockedIncrement(PLONG Addend) - */ - -.globl _InterlockedIncrement@4 - -_InterlockedIncrement@4: - movl $1,%ebx - lock - xaddl %eax,%ebx - incl %eax - leave - ret $4 +/* + * PROJECT: ReactOS system libraries + * LICENSE: GPL - See COPYING in the top level directory + * FILE: lib/intrlck/i386/increment.c + * PURPOSE: Inter lock increments + * PROGRAMMERS: Copyright 1995 Martin von Loewis + * Copyright 1997 Onno Hovers + */ + +/************************************************************************ +* InterlockedIncrement * +* * +* InterlockedIncrement adds 1 to a long variable and returns * +* the resulting incremented value. * +* * +************************************************************************/ + +/* + * LONG NTAPI InterlockedIncrement(PLONG Addend) + */ + +#include +LONG +NTAPI +InterlockedIncrement(PLONG lpAddend) +{ + LONG ret; + __asm__ + ( + "\tlock\n" /* for SMP systems */ + "\txaddl %0, (%1)\n" + "\tincl %0\n" + :"=r" (ret) + :"r" (lpAddend), "0" (1) + : "memory" + ); + return ret; +} diff --git a/reactos/lib/intrlck/intrlck.rbuild b/reactos/lib/intrlck/intrlck.rbuild index bec73cae0a4..a8421f10096 100644 --- a/reactos/lib/intrlck/intrlck.rbuild +++ b/reactos/lib/intrlck/intrlck.rbuild @@ -3,11 +3,11 @@ - compareexchange.s - decrement.s - exchange.s - exchangeadd.s - increment.s + compareexchange.c + decrement.c + exchange.c + exchangeadd.c + increment.c