Home | History | Annotate | Download | only in goldfish
      1 /* Copyright (C) 2007-2008 The Android Open Source Project
      2 **
      3 ** This software is licensed under the terms of the GNU General Public
      4 ** License version 2, as published by the Free Software Foundation, and
      5 ** may be copied, distributed, and modified under those terms.
      6 **
      7 ** This program is distributed in the hope that it will be useful,
      8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
      9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     10 ** GNU General Public License for more details.
     11 */
     12 #include "hw/hw.h"
     13 #include "hw/android/goldfish/vmem.h"
     14 #ifdef TARGET_I386
     15 #include "sysemu/kvm.h"
     16 #endif
     17 
     18 
     19 // Both safe_memory_rw_debug and safe_get_phys_page_debug need to translate
     20 // virtual addresses to physical addresses. When running on KVM we need to
     21 // pull the cr registers and hflags from the VCPU. These functions wrap the
     22 // calls to kvm_get_sregs to pull these registers over when necessary.
     23 //
     24 // Note: we do not call the cpu_synchronize_state function because that pulls
     25 // all the VCPU registers. That equates to 4 ioctls on the KVM virtual device
     26 // and on AMD some of those ioctls (in particular KVM_GET_MSRS) are 10 to 100x
     27 // slower than on Intel chips.
     28 
     29 int safe_memory_rw_debug(CPUState *cpu, target_ulong addr, uint8_t *buf,
     30                          int len, int is_write)
     31 {
     32 #ifdef TARGET_I386
     33     if (kvm_enabled()) {
     34         kvm_get_sregs(cpu);
     35     }
     36 #endif
     37     return cpu_memory_rw_debug(cpu, addr, buf, len, is_write);
     38 }
     39 
     40 hwaddr safe_get_phys_page_debug(CPUState *cpu, target_ulong addr)
     41 {
     42     CPUArchState *env = cpu->env_ptr;
     43 
     44 #ifdef TARGET_I386
     45     if (kvm_enabled()) {
     46         kvm_get_sregs(cpu);
     47     }
     48 #endif
     49     return cpu_get_phys_page_debug(env, addr);
     50 }
     51 
     52