108c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych/* Copyright (C) 2007-2008 The Android Open Source Project
208c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych**
308c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych** This software is licensed under the terms of the GNU General Public
408c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych** License version 2, as published by the Free Software Foundation, and
508c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych** may be copied, distributed, and modified under those terms.
608c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych**
708c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych** This program is distributed in the hope that it will be useful,
808c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych** but WITHOUT ANY WARRANTY; without even the implied warranty of
908c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1008c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych** GNU General Public License for more details.
1108c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych*/
122ec695af7284adbedcdbc08a22d818b6bdd8990cDavid 'Digit' Turner#include "hw/hw.h"
13f5bc01c356e1fa924ed07aadf589b3663873593eDavid 'Digit' Turner#include "hw/android/goldfish/vmem.h"
1408c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych#ifdef TARGET_I386
1534c48ff1e3ad5cd2084ca40188754d45f423750bDavid 'Digit' Turner#include "sysemu/kvm.h"
1608c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych#endif
1708c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych
1808c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych
1908c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych// Both safe_memory_rw_debug and safe_get_phys_page_debug need to translate
2008c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych// virtual addresses to physical addresses. When running on KVM we need to
2108c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych// pull the cr registers and hflags from the VCPU. These functions wrap the
2208c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych// calls to kvm_get_sregs to pull these registers over when necessary.
2308c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych//
2408c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych// Note: we do not call the cpu_synchronize_state function because that pulls
2508c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych// all the VCPU registers. That equates to 4 ioctls on the KVM virtual device
2608c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych// and on AMD some of those ioctls (in particular KVM_GET_MSRS) are 10 to 100x
2708c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych// slower than on Intel chips.
2808c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych
29aaef275467ba13162d52ef6f690fd97f9733eb58David 'Digit' Turnerint safe_memory_rw_debug(CPUState *cpu, target_ulong addr, uint8_t *buf,
3008c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych                         int len, int is_write)
3108c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych{
3208c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych#ifdef TARGET_I386
3308c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych    if (kvm_enabled()) {
34e36a683b547e540c68bf9c5578e05b29c8676f47David 'Digit' Turner        kvm_get_sregs(cpu);
3508c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych    }
3608c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych#endif
37aaef275467ba13162d52ef6f690fd97f9733eb58David 'Digit' Turner    return cpu_memory_rw_debug(cpu, addr, buf, len, is_write);
3808c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych}
3908c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych
40aaef275467ba13162d52ef6f690fd97f9733eb58David 'Digit' Turnerhwaddr safe_get_phys_page_debug(CPUState *cpu, target_ulong addr)
4108c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych{
42aaef275467ba13162d52ef6f690fd97f9733eb58David 'Digit' Turner    CPUArchState *env = cpu->env_ptr;
43aaef275467ba13162d52ef6f690fd97f9733eb58David 'Digit' Turner
4408c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych#ifdef TARGET_I386
4508c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych    if (kvm_enabled()) {
46e36a683b547e540c68bf9c5578e05b29c8676f47David 'Digit' Turner        kvm_get_sregs(cpu);
4708c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych    }
4808c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych#endif
4908c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych    return cpu_get_phys_page_debug(env, addr);
5008c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych}
5108c7228c50f8b27acba312c4d2f0c07d0ab6a06bTom Knych
52