github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/include/emulator_if.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 _EMULATOR_IF_H_
    16  #define _EMULATOR_IF_H_
    17  
    18  #include "vmm_defs.h"
    19  #include "list.h"
    20  #include "guest_cpu.h"
    21  #include "gdt.h"
    22  #include "hw_utils.h"
    23  #include "vmm_globals.h"
    24  
    25  typedef struct _EMULATOR_STATE * EMULATOR_HANDLE;
    26  typedef struct _CPU_ARCH_STATE * CPU_ARCH_STATE;
    27  
    28  typedef enum {
    29      EMUL_MMIO_GPA_ACCESS = 1,
    30      EMUL_MMIO_HVA_ACCESS = 2
    31  } EMUL_MMIO_ACCESS_TYPE;
    32  
    33  typedef VMM_STATUS (*EMUL_MMIO_HANDLER)(
    34      ADDRESS         addr,               // virtual address to IO
    35      void           *p,                  // copy to/from
    36      RW_ACCESS       access,             // read / write
    37      INT32           num_bytes,          // number bytes to transfer
    38      INT32          *bytes_succeeded,    // number bytes actually transferred
    39      void           *callee_context      // pointer to callee defined state
    40      );
    41  
    42  
    43  // should not be used outside emulator. placed here for convenience :-(
    44  typedef struct _EMU_MMIO_DESCRIPTOR {
    45      LIST_ELEMENT        list;
    46      ADDRESS             address;
    47      INT32               region_size;
    48      INT32               address_type;   // 0 - GPA, 1 - HVA, others invalid
    49      EMUL_MMIO_HANDLER   mmio_handler;
    50      EMUL_MMIO_HANDLER   write;
    51      void               *callee_context;
    52  } EMU_MMIO_DESCRIPTOR;
    53  
    54  
    55  EMULATOR_HANDLE emul_create_handle(GUEST_CPU_HANDLE guest_cpu);
    56  void    emul_destroy_handle(EMULATOR_HANDLE handle);
    57  void    emul_intialize(EMULATOR_HANDLE handle);
    58  void    emul_start_guest_execution(EMULATOR_HANDLE handle);
    59  void    emul_stop_guest_execution(EMULATOR_HANDLE handle);
    60  BOOLEAN emul_is_running(EMULATOR_HANDLE handle);
    61  BOOLEAN emulator_interrupt_handler(EMULATOR_HANDLE handle, VECTOR_ID vector);
    62  void    emulator_register_handlers(EMULATOR_HANDLE handle);
    63  BOOLEAN emul_run_single_instruction(EMULATOR_HANDLE handle);
    64  BOOLEAN emul_state_show(EMULATOR_HANDLE p_emu);
    65  void    emul_register_mmio_handler(
    66              EMULATOR_HANDLE         p_emu,
    67              ADDRESS                 region_address,
    68              unsigned                size_in_bytes,
    69              EMUL_MMIO_ACCESS_TYPE   addr_type,
    70              EMUL_MMIO_HANDLER       mmio_handler,
    71              void                    *callee_context
    72              );
    73  
    74  
    75  // FUNCTION : emulator_is_running_as_guest()
    76  // PURPOSE  : Used in interrupt handler
    77  // ARGUMENTS: void
    78  // RETURNS  : TRUE if guest runs emulator
    79  INLINE BOOLEAN emulator_is_running_as_guest(void)
    80  {
    81      return ((vmm_get_state() == VMM_STATE_RUN) && (0 != hw_read_gs()));
    82  }
    83  
    84  #endif // _EMULATOR_IF_H_
    85  
    86