github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/libc/em64t_mem2.c (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  #include "vmm_defs.h"
    16  #include "common_libc.h"
    17  #ifdef JLMDEBUG
    18  #include "jlmdebug.h"
    19  #endif
    20  
    21  void vmm_lock_xchg_qword (UINT64 *dst, UINT64 *src) 
    22  {
    23  #ifdef JLMDEBUG
    24      bprint("vmm_lock_xchg_qword\n");
    25      LOOP_FOREVER
    26  #endif
    27      // CHECK(JLM)
    28      __asm__ volatile(
    29          "\tmovq %[src], %%r8\n"
    30          "\tmovq %[src], %%rdx\n"
    31          "\tmovq %[dst], %%rcx\n"
    32          "\tmovq %%r8, (%%rdx)\n"
    33          "\tlock; xchg %%r8, (%%rcx)\n"
    34      :
    35      : [dst] "m" (dst), [src] "m" (src)
    36      :"rcx", "rdx", "r8");
    37  }
    38  
    39  
    40  void vmm_lock_xchg_byte (UINT8 *dst, UINT8 *src) 
    41  {
    42  #ifdef JLMDEBUG
    43      bprint("vmm_lock_xchg_byte\n");
    44      LOOP_FOREVER
    45  #endif
    46      __asm__ volatile(
    47          "\tmovq %[src], %%rdx\n"
    48          "\tmovq %[dst], %%rcx\n"
    49          "\tmovb (%%rdx), %%bl\n"
    50          "\tlock xchg %%bl, (%%rcx)\n" // byte exchange
    51      :
    52      : [dst] "m" (dst), [src] "m" (src)
    53      :"rcx", "rbx", "rdx");
    54  }
    55