GccInline.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/** @file
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe GCC inline implementation of BaseSynchronizationLib processor specific functions.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe This program and the accompanying materials
843c398e8904ed9d833d2af3103894f909fb4b52Cody Peter Mello are licensed and made available under the terms and conditions of the BSD License
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe which accompanies this distribution. The full text of the license may be found at
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe http://opensource.org/licenses/bsd-license.php.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe**/
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/**
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe Performs an atomic increment of an 32-bit unsigned integer.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe Performs an atomic increment of the 32-bit unsigned integer specified by
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe Value and returns the incremented value. The increment operation must be
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe performed using MP safe mechanisms. The state of the return value is not
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe guaranteed to be MP safe.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe @param Value A pointer to the 32-bit value to increment.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe @return The incremented value.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe**/
c10c16dec587a0662068f6e2991c29ed3a9db943Richard LoweUINT32
c10c16dec587a0662068f6e2991c29ed3a9db943Richard LoweEFIAPI
c10c16dec587a0662068f6e2991c29ed3a9db943Richard LoweInternalSyncIncrement (
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe IN volatile UINT32 *Value
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe )
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe UINT32 Result;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe __asm__ __volatile__ (
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "lock \n\t"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "incl %2 \n\t"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "mov %2, %%eax "
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe : "=a" (Result), // %0
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "=m" (*Value) // %1
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe : "m" (*Value) // %2
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe : "memory",
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "cc"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe );
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return Result;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/**
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe Performs an atomic decrement of an 32-bit unsigned integer.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe Performs an atomic decrement of the 32-bit unsigned integer specified by
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe Value and returns the decremented value. The decrement operation must be
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe performed using MP safe mechanisms. The state of the return value is not
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe guaranteed to be MP safe.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe @param Value A pointer to the 32-bit value to decrement.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe @return The decremented value.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe**/
c10c16dec587a0662068f6e2991c29ed3a9db943Richard LoweUINT32
c10c16dec587a0662068f6e2991c29ed3a9db943Richard LoweEFIAPI
c10c16dec587a0662068f6e2991c29ed3a9db943Richard LoweInternalSyncDecrement (
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe IN volatile UINT32 *Value
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe )
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe UINT32 Result;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe __asm__ __volatile__ (
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "lock \n\t"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "decl %2 \n\t"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "mov %2, %%eax "
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe : "=a" (Result), // %0
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "=m" (*Value) // %1
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe : "m" (*Value) // %2
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe : "memory",
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "cc"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe );
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return Result;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/**
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe Performs an atomic compare exchange operation on a 32-bit unsigned integer.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe Performs an atomic compare exchange operation on the 32-bit unsigned integer
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe specified by Value. If Value is equal to CompareValue, then Value is set to
843c398e8904ed9d833d2af3103894f909fb4b52Cody Peter Mello ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe then Value is returned. The compare exchange operation must be performed using
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe MP safe mechanisms.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe @param Value A pointer to the 32-bit value for the compare exchange
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe operation.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe @param CompareValue 32-bit value used in compare operation.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe @param ExchangeValue 32-bit value used in exchange operation.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe @return The original *Value before exchange.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe**/
c10c16dec587a0662068f6e2991c29ed3a9db943Richard LoweUINT32
c10c16dec587a0662068f6e2991c29ed3a9db943Richard LoweEFIAPI
c10c16dec587a0662068f6e2991c29ed3a9db943Richard LoweInternalSyncCompareExchange32 (
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe IN OUT volatile UINT32 *Value,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe IN UINT32 CompareValue,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe IN UINT32 ExchangeValue
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe )
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe __asm__ __volatile__ (
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "lock \n\t"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "cmpxchgl %3, %1 "
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe : "=a" (CompareValue), // %0
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "=m" (*Value) // %1
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe : "a" (CompareValue), // %2
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "r" (ExchangeValue), // %3
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "m" (*Value)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe : "memory",
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "cc"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe );
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return CompareValue;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/**
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe Performs an atomic compare exchange operation on a 64-bit unsigned integer.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe The compare exchange operation must be performed using MP safe mechanisms.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe @param Value A pointer to the 64-bit value for the compare exchange
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe operation.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe @param CompareValue 64-bit value used in compare operation.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe @param ExchangeValue 64-bit value used in exchange operation.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe @return The original *Value before exchange.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe**/
c10c16dec587a0662068f6e2991c29ed3a9db943Richard LoweUINT64
c10c16dec587a0662068f6e2991c29ed3a9db943Richard LoweEFIAPI
c10c16dec587a0662068f6e2991c29ed3a9db943Richard LoweInternalSyncCompareExchange64 (
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe IN OUT volatile UINT64 *Value,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe IN UINT64 CompareValue,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe IN UINT64 ExchangeValue
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe )
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe __asm__ __volatile__ (
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "lock \n\t"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "cmpxchgq %3, %1 "
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe : "=a" (CompareValue), // %0
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "=m" (*Value) // %1
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe : "a" (CompareValue), // %2
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "r" (ExchangeValue), // %3
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "m" (*Value)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe : "memory",
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "cc"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe );
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return CompareValue;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe