github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/include/hw/hw_interlocked.h (about)

     1  /*
     2   * Copyright (c) 2013 Intel Corporation
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *     http://www.apache.org/licenses/LICENSE-2.0
     8   * Unless required by applicable law or agreed to in writing, software
     9   * distributed under the License is distributed on an "AS IS" BASIS,
    10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11   * See the License for the specific language governing permissions and
    12   * limitations under the License.
    13   */
    14  
    15  #ifndef _HW_INTERLOCKED_H_
    16  #define _HW_INTERLOCKED_H_
    17  
    18  #include "vmm_defs.h"
    19  
    20  #ifndef __GNUC__    // MS Compiler Intrinsics
    21  
    22  extern long _InterlockedCompareExchange(
    23              long volatile * Destination,
    24              long Exchange,
    25              long Comperand );
    26  extern __int64 _InterlockedCompareExchange64(
    27              __int64 volatile * Destination,
    28              __int64 Exchange,
    29              __int64 Comperand );
    30  extern long _InterlockedDecrement(long * lpAddend);
    31  extern long _InterlockedIncrement(long * lpAddend);
    32  extern __int64 _InterlockedIncrement64(long long volatile * lpAddend);
    33  extern long _InterlockedAdd(long volatile * Addend, long Value);
    34  extern long _InterlockedOr(long volatile * Value,long Mask);
    35  extern long _InterlockedAnd(long volatile * Value,long Mask);
    36  extern long _InterlockedXor(long volatile * Value,long Mask);
    37  extern long _InterlockedExchange(long * Target,long Value);
    38  extern void __faststorefence(void);
    39  
    40  #endif
    41  
    42  
    43  // Various interlocked routines
    44  
    45  // returns previous value
    46  // Assigns new value if previous value == expected_value
    47  // If previous value != expected_value do not change it
    48  // Compare returned value with expected to discover.
    49  
    50  
    51  #ifdef __GNUC__
    52  INT64  hw_interlocked_compare_exchange_64( INT64 volatile * destination,
    53              INT64 exchange, INT64 comperand );
    54  
    55  INT8  hw_interlocked_compare_exchange_8(INT8 volatile * destination,
    56              INT8 exchange, INT8 comperand );
    57  #if 0  // fixed interlock exchange
    58  #define hw_interlocked_compare_exchange( p_number, expected_value, new_value )\
    59      (INT64)gcc_interlocked_compare_exchange_8(                                \
    60              (INT64 volatile*)(p_number),                                      \
    61              (INT64)(new_value),                                               \
    62              (INT64)(expected_value) )
    63  #endif
    64  #endif
    65  
    66  INT32 hw_interlocked_compare_exchange(INT32 volatile * destination,
    67                                        INT32 expected, INT32 comperand);
    68  
    69  // Decrement value by 1
    70  // INT32 hw_interlocked_decrement( volatile INT32 *p_counter);
    71  #ifdef __GNUC__
    72  INT32    hw_interlocked_decrement(INT32 * minuend);
    73  #endif
    74  
    75  // Decrement value by 1
    76  // INT32 ASM_FUNCTION
    77  // hw_interlocked_increment( volatile INT32 *p_counter);
    78  #ifdef __GNUC__
    79  INT32    hw_interlocked_increment(INT32 * addend);
    80  #endif
    81  
    82  
    83  // This function guarantees to return the old value at the time of the addition
    84  // INT32 hw_interlocked_add( volatile INT32 *p_counter, INT32 addend);
    85  #ifdef __GNUC__
    86  INT32    hw_interlocked_add(INT32 volatile * addend, INT32 value);
    87  #endif
    88  
    89  // returns previous value
    90  // INT32 hw_interlocked_bit_or( volatile INT32* p_bit_set, INT32  mask);
    91  #ifdef __GNUC__
    92  INT32    hw_interlocked_or(INT32 volatile * value, INT32 mask);
    93  #endif
    94  
    95  
    96  // returns previous value
    97  // INT32 hw_interlocked_bit_and( volatile INT32* p_bit_set, INT32 mask);
    98  #ifdef __GNUC__
    99  INT32    hw_interlocked_and(INT32 volatile * value, INT32 mask);
   100  #endif
   101  
   102  
   103  // returns previous value
   104  // INT32 hw_interlocked_bit_xor( volatile INT32* p_bit_set, INT32  mask);
   105  #ifdef __GNUC__
   106  INT32    hw_interlocked_xor(INT32 volatile * value, INT32 mask);
   107  #endif
   108  
   109  
   110  // returns previous value
   111  // INT32 hw_interlocked_assign( volatile INT32* p_number, INT32 new_value);
   112  #ifdef __GNUC__
   113  INT32    hw_interlocked_assign(INT32 volatile * target, INT32 new_value);
   114  #endif
   115  
   116  
   117  #ifdef __GNUC__
   118  void    hw_store_fence(void);
   119  #endif
   120  
   121  
   122  // returns nothing
   123  // void hw_assign_as_barrier( volatile UINT32* p_number, UINT32 new_value )
   124  #define hw_assign_as_barrier( p_number, new_value )                             \
   125          hw_store_fence(); \
   126          *(p_number) = (new_value)
   127  
   128  // Execute assembler 'pause' instruction
   129  void hw_pause( void );
   130  
   131  // Execute assembler 'monitor' instruction
   132  void hw_monitor( void* addr, UINT32 extension, UINT32 hint );
   133  
   134  // Execute assembler 'mwait' instruction
   135  void hw_mwait( UINT32 extension, UINT32 hint );
   136  
   137  #endif // _HW_INTERLOCKED_H_
   138  
   139