mirror of
https://github.com/utmapp/qemu.git
synced 2026-12-01 22:23:23 -10:00
Compare commits
67
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06f72b6b41 | ||
|
|
40c3e9af45 | ||
|
|
3a54a4e813 | ||
|
|
612ca12613 | ||
|
|
11ed5b8f10 | ||
|
|
4a3199be61 | ||
|
|
73b368199a | ||
|
|
711f09dee4 | ||
|
|
0f74dc7f55 | ||
|
|
25eb2ff8a7 | ||
|
|
8bbb55ab42 | ||
|
|
b262ed2a1a | ||
|
|
4e36bac10b | ||
|
|
c85ff5308b | ||
|
|
6a278ab4ef | ||
|
|
89424f89f4 | ||
|
|
a3367554f5 | ||
|
|
f8be906d32 | ||
|
|
c17f7d3b39 | ||
|
|
ef94dda997 | ||
|
|
bf215a5a6b | ||
|
|
4b86a96edc | ||
|
|
50d66d4a6d | ||
|
|
15b56ea532 | ||
|
|
5861ba146e | ||
|
|
8b66138f4c | ||
|
|
b60ae504f0 | ||
|
|
ceb2ae8c94 | ||
|
|
ddb32ce98d | ||
|
|
d2862788fc | ||
|
|
c6603c22b8 | ||
|
|
f472d2a9a4 | ||
|
|
c7b4c9ef06 | ||
|
|
5a73605068 | ||
|
|
b07237ddf5 | ||
|
|
1b609a5e82 | ||
|
|
ab6c76aeda | ||
|
|
eeb9f35b52 | ||
|
|
5d2fb73b63 | ||
|
|
54626b4577 | ||
|
|
a81038425c | ||
|
|
43276137be | ||
|
|
b5817c5ffe | ||
|
|
3a0b856585 | ||
|
|
875346c2f1 | ||
|
|
d8fca0b8d0 | ||
|
|
5c1da59df8 | ||
|
|
cf974dcd57 | ||
|
|
4e63180ada | ||
|
|
2acd41d2d9 | ||
|
|
43dc2fccc4 | ||
|
|
a93d787bb9 | ||
|
|
14f4daed4c | ||
|
|
6d2cbe338b | ||
|
|
1ff4e38e1d | ||
|
|
91633839ff | ||
|
|
ef98b3c104 | ||
|
|
ff58797d11 | ||
|
|
204f5dd20a | ||
|
|
3a0629b809 | ||
|
|
e69b13a6c5 | ||
|
|
0c55fbc2c2 | ||
|
|
5b1eb71d0d | ||
|
|
22fc3b0280 | ||
|
|
4a47d9160c | ||
|
|
722b23b5bb | ||
|
|
2a3aaedef1 |
No files matched your search
@@ -64,3 +64,6 @@
|
||||
[submodule "roms/vbootrom"]
|
||||
path = roms/vbootrom
|
||||
url = https://git.qemu.org/git/vbootrom.git
|
||||
[submodule "libucontext"]
|
||||
path = subprojects/libucontext
|
||||
url = https://github.com/utmapp/libucontext.git
|
||||
+22
-1
@@ -119,6 +119,8 @@ F: softmmu/cpus.c
|
||||
F: cpus-common.c
|
||||
F: accel/tcg/
|
||||
F: accel/stubs/tcg-stub.c
|
||||
F: util/cacheinfo.c
|
||||
F: util/cacheflush.c
|
||||
F: scripts/decodetree.py
|
||||
F: docs/devel/decodetree.rst
|
||||
F: include/exec/cpu*.h
|
||||
@@ -441,14 +443,26 @@ F: accel/accel.c
|
||||
F: accel/Makefile.objs
|
||||
F: accel/stubs/Makefile.objs
|
||||
|
||||
Apple Silicon HVF CPUs
|
||||
M: Alexander Graf <[email protected]>
|
||||
S: Maintained
|
||||
F: target/arm/hvf/
|
||||
|
||||
X86 HVF CPUs
|
||||
M: Cameron Esfahani <[email protected]>
|
||||
M: Roman Bolshakov <[email protected]>
|
||||
W: https://wiki.qemu.org/Features/HVF
|
||||
S: Maintained
|
||||
F: accel/stubs/hvf-stub.c
|
||||
F: target/i386/hvf/
|
||||
|
||||
HVF
|
||||
M: Cameron Esfahani <[email protected]>
|
||||
M: Roman Bolshakov <[email protected]>
|
||||
W: https://wiki.qemu.org/Features/HVF
|
||||
S: Maintained
|
||||
F: accel/hvf/
|
||||
F: include/sysemu/hvf.h
|
||||
F: include/sysemu/hvf_int.h
|
||||
|
||||
WHPX CPUs
|
||||
M: Sunil Muthuswamy <[email protected]>
|
||||
@@ -536,6 +550,13 @@ F: include/*/*win32*
|
||||
X: qga/*win32*
|
||||
F: qemu.nsi
|
||||
|
||||
IOS
|
||||
M: Joelle van Dyne <[email protected]>
|
||||
S: Maintained
|
||||
K: ^Subject:.*(?i)iOS
|
||||
F: docs/devel/ios.rst
|
||||
F: include/tcg/tcg-apple-jit.h
|
||||
|
||||
Alpha Machines
|
||||
--------------
|
||||
M: Richard Henderson <[email protected]>
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* QEMU Hypervisor.framework support
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2. See
|
||||
* the COPYING file in the top-level directory.
|
||||
*
|
||||
* Contributions after 2012-01-13 are licensed under the terms of the
|
||||
* GNU GPL, version 2 or (at your option) any later version.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu-common.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "sysemu/hvf.h"
|
||||
#include "sysemu/hvf_int.h"
|
||||
#include "sysemu/runstate.h"
|
||||
|
||||
#include "qemu/main-loop.h"
|
||||
#include "sysemu/accel.h"
|
||||
|
||||
bool hvf_allowed;
|
||||
HVFState *hvf_state;
|
||||
|
||||
void assert_hvf_ok(hv_return_t ret)
|
||||
{
|
||||
if (ret == HV_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (ret) {
|
||||
case HV_ERROR:
|
||||
error_report("Error: HV_ERROR");
|
||||
break;
|
||||
case HV_BUSY:
|
||||
error_report("Error: HV_BUSY");
|
||||
break;
|
||||
case HV_BAD_ARGUMENT:
|
||||
error_report("Error: HV_BAD_ARGUMENT");
|
||||
break;
|
||||
case HV_NO_RESOURCES:
|
||||
error_report("Error: HV_NO_RESOURCES");
|
||||
break;
|
||||
case HV_NO_DEVICE:
|
||||
error_report("Error: HV_NO_DEVICE");
|
||||
break;
|
||||
case HV_UNSUPPORTED:
|
||||
error_report("Error: HV_UNSUPPORTED");
|
||||
break;
|
||||
default:
|
||||
error_report("Unknown Error");
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
@@ -0,0 +1,466 @@
|
||||
/*
|
||||
* Copyright 2008 IBM Corporation
|
||||
* 2008 Red Hat, Inc.
|
||||
* Copyright 2011 Intel Corporation
|
||||
* Copyright 2016 Veertu, Inc.
|
||||
* Copyright 2017 The Android Open Source Project
|
||||
*
|
||||
* QEMU Hypervisor.framework support
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2 of the GNU General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This file contain code under public domain from the hvdos project:
|
||||
* https://github.com/mist64/hvdos
|
||||
*
|
||||
* Parts Copyright (c) 2011 NetApp, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/main-loop.h"
|
||||
#include "exec/address-spaces.h"
|
||||
#include "exec/exec-all.h"
|
||||
#include "sysemu/cpus.h"
|
||||
#include "sysemu/hvf.h"
|
||||
#include "sysemu/hvf_int.h"
|
||||
#include "sysemu/runstate.h"
|
||||
#include "qemu/guest-random.h"
|
||||
|
||||
#ifdef __aarch64__
|
||||
#define HV_VM_DEFAULT NULL
|
||||
#endif
|
||||
|
||||
/* Memory slots */
|
||||
|
||||
struct mac_slot {
|
||||
int present;
|
||||
uint64_t size;
|
||||
uint64_t gpa_start;
|
||||
uint64_t gva;
|
||||
};
|
||||
|
||||
hvf_slot *hvf_find_overlap_slot(uint64_t start, uint64_t size)
|
||||
{
|
||||
hvf_slot *slot;
|
||||
int x;
|
||||
for (x = 0; x < hvf_state->num_slots; ++x) {
|
||||
slot = &hvf_state->slots[x];
|
||||
if (slot->size && start < (slot->start + slot->size) &&
|
||||
(start + size) > slot->start) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mac_slot mac_slots[32];
|
||||
|
||||
static int do_hvf_set_memory(hvf_slot *slot, hv_memory_flags_t flags)
|
||||
{
|
||||
struct mac_slot *macslot;
|
||||
hv_return_t ret;
|
||||
|
||||
macslot = &mac_slots[slot->slot_id];
|
||||
|
||||
if (macslot->present) {
|
||||
if (macslot->size != slot->size) {
|
||||
macslot->present = 0;
|
||||
ret = hv_vm_unmap(macslot->gpa_start, macslot->size);
|
||||
assert_hvf_ok(ret);
|
||||
}
|
||||
}
|
||||
|
||||
if (!slot->size) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
macslot->present = 1;
|
||||
macslot->gpa_start = slot->start;
|
||||
macslot->size = slot->size;
|
||||
ret = hv_vm_map(slot->mem, slot->start, slot->size, flags);
|
||||
assert_hvf_ok(ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void hvf_set_phys_mem(MemoryRegionSection *section, bool add)
|
||||
{
|
||||
hvf_slot *mem;
|
||||
MemoryRegion *area = section->mr;
|
||||
bool writeable = !area->readonly && !area->rom_device;
|
||||
hv_memory_flags_t flags;
|
||||
|
||||
if (!memory_region_is_ram(area)) {
|
||||
if (writeable) {
|
||||
return;
|
||||
} else if (!memory_region_is_romd(area)) {
|
||||
/*
|
||||
* If the memory device is not in romd_mode, then we actually want
|
||||
* to remove the hvf memory slot so all accesses will trap.
|
||||
*/
|
||||
add = false;
|
||||
}
|
||||
}
|
||||
|
||||
mem = hvf_find_overlap_slot(
|
||||
section->offset_within_address_space,
|
||||
int128_get64(section->size));
|
||||
|
||||
if (mem && add) {
|
||||
if (mem->size == int128_get64(section->size) &&
|
||||
mem->start == section->offset_within_address_space &&
|
||||
mem->mem == (memory_region_get_ram_ptr(area) +
|
||||
section->offset_within_region)) {
|
||||
return; /* Same region was attempted to register, go away. */
|
||||
}
|
||||
}
|
||||
|
||||
/* Region needs to be reset. set the size to 0 and remap it. */
|
||||
if (mem) {
|
||||
mem->size = 0;
|
||||
if (do_hvf_set_memory(mem, 0)) {
|
||||
error_report("Failed to reset overlapping slot");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
if (!add) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (area->readonly ||
|
||||
(!memory_region_is_ram(area) && memory_region_is_romd(area))) {
|
||||
flags = HV_MEMORY_READ | HV_MEMORY_EXEC;
|
||||
} else {
|
||||
flags = HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC;
|
||||
}
|
||||
|
||||
/* Now make a new slot. */
|
||||
int x;
|
||||
|
||||
for (x = 0; x < hvf_state->num_slots; ++x) {
|
||||
mem = &hvf_state->slots[x];
|
||||
if (!mem->size) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (x == hvf_state->num_slots) {
|
||||
error_report("No free slots");
|
||||
abort();
|
||||
}
|
||||
|
||||
mem->size = int128_get64(section->size);
|
||||
mem->mem = memory_region_get_ram_ptr(area) + section->offset_within_region;
|
||||
mem->start = section->offset_within_address_space;
|
||||
mem->region = area;
|
||||
|
||||
if (do_hvf_set_memory(mem, flags)) {
|
||||
error_report("Error registering new memory slot");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
static void hvf_set_dirty_tracking(MemoryRegionSection *section, bool on)
|
||||
{
|
||||
hvf_slot *slot;
|
||||
|
||||
slot = hvf_find_overlap_slot(
|
||||
section->offset_within_address_space,
|
||||
int128_get64(section->size));
|
||||
|
||||
/* protect region against writes; begin tracking it */
|
||||
if (on) {
|
||||
slot->flags |= HVF_SLOT_LOG;
|
||||
hv_vm_protect((uintptr_t)slot->start, (size_t)slot->size,
|
||||
HV_MEMORY_READ);
|
||||
/* stop tracking region*/
|
||||
} else {
|
||||
slot->flags &= ~HVF_SLOT_LOG;
|
||||
hv_vm_protect((uintptr_t)slot->start, (size_t)slot->size,
|
||||
HV_MEMORY_READ | HV_MEMORY_WRITE);
|
||||
}
|
||||
}
|
||||
|
||||
static void hvf_log_start(MemoryListener *listener,
|
||||
MemoryRegionSection *section, int old, int new)
|
||||
{
|
||||
if (old != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
hvf_set_dirty_tracking(section, 1);
|
||||
}
|
||||
|
||||
static void hvf_log_stop(MemoryListener *listener,
|
||||
MemoryRegionSection *section, int old, int new)
|
||||
{
|
||||
if (new != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
hvf_set_dirty_tracking(section, 0);
|
||||
}
|
||||
|
||||
static void hvf_log_sync(MemoryListener *listener,
|
||||
MemoryRegionSection *section)
|
||||
{
|
||||
/*
|
||||
* sync of dirty pages is handled elsewhere; just make sure we keep
|
||||
* tracking the region.
|
||||
*/
|
||||
hvf_set_dirty_tracking(section, 1);
|
||||
}
|
||||
|
||||
static void hvf_region_add(MemoryListener *listener,
|
||||
MemoryRegionSection *section)
|
||||
{
|
||||
hvf_set_phys_mem(section, true);
|
||||
}
|
||||
|
||||
static void hvf_region_del(MemoryListener *listener,
|
||||
MemoryRegionSection *section)
|
||||
{
|
||||
hvf_set_phys_mem(section, false);
|
||||
}
|
||||
|
||||
static MemoryListener hvf_memory_listener = {
|
||||
.priority = 10,
|
||||
.region_add = hvf_region_add,
|
||||
.region_del = hvf_region_del,
|
||||
.log_start = hvf_log_start,
|
||||
.log_stop = hvf_log_stop,
|
||||
.log_sync = hvf_log_sync,
|
||||
};
|
||||
|
||||
static void do_hvf_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg)
|
||||
{
|
||||
if (!cpu->vcpu_dirty) {
|
||||
hvf_get_registers(cpu);
|
||||
cpu->vcpu_dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void hvf_cpu_synchronize_state(CPUState *cpu)
|
||||
{
|
||||
if (!cpu->vcpu_dirty) {
|
||||
run_on_cpu(cpu, do_hvf_cpu_synchronize_state, RUN_ON_CPU_NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void do_hvf_cpu_synchronize_set_dirty(CPUState *cpu,
|
||||
run_on_cpu_data arg)
|
||||
{
|
||||
/* QEMU state is the reference, push it to HVF now and on next entry */
|
||||
cpu->vcpu_dirty = true;
|
||||
}
|
||||
|
||||
static void hvf_cpu_synchronize_post_reset(CPUState *cpu)
|
||||
{
|
||||
run_on_cpu(cpu, do_hvf_cpu_synchronize_set_dirty, RUN_ON_CPU_NULL);
|
||||
}
|
||||
|
||||
static void hvf_cpu_synchronize_post_init(CPUState *cpu)
|
||||
{
|
||||
run_on_cpu(cpu, do_hvf_cpu_synchronize_set_dirty, RUN_ON_CPU_NULL);
|
||||
}
|
||||
|
||||
static void hvf_cpu_synchronize_pre_loadvm(CPUState *cpu)
|
||||
{
|
||||
run_on_cpu(cpu, do_hvf_cpu_synchronize_set_dirty, RUN_ON_CPU_NULL);
|
||||
}
|
||||
|
||||
static void hvf_vcpu_destroy(CPUState *cpu)
|
||||
{
|
||||
hv_return_t ret = hv_vcpu_destroy(cpu->hvf->fd);
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
hvf_arch_vcpu_destroy(cpu);
|
||||
free(cpu->hvf);
|
||||
cpu->hvf = NULL;
|
||||
}
|
||||
|
||||
static void dummy_signal(int sig)
|
||||
{
|
||||
}
|
||||
|
||||
static int hvf_init_vcpu(CPUState *cpu)
|
||||
{
|
||||
int r;
|
||||
|
||||
cpu->hvf = g_malloc0(sizeof(*cpu->hvf));
|
||||
|
||||
/* init cpu signals */
|
||||
struct sigaction sigact;
|
||||
|
||||
memset(&sigact, 0, sizeof(sigact));
|
||||
sigact.sa_handler = dummy_signal;
|
||||
sigaction(SIG_IPI, &sigact, NULL);
|
||||
|
||||
pthread_sigmask(SIG_BLOCK, NULL, &cpu->hvf->unblock_ipi_mask);
|
||||
sigdelset(&cpu->hvf->unblock_ipi_mask, SIG_IPI);
|
||||
|
||||
#ifdef __aarch64__
|
||||
r = hv_vcpu_create(&cpu->hvf->fd, (hv_vcpu_exit_t **)&cpu->hvf->exit, NULL);
|
||||
#else
|
||||
r = hv_vcpu_create((hv_vcpuid_t *)&cpu->hvf->fd, HV_VCPU_DEFAULT);
|
||||
#endif
|
||||
cpu->vcpu_dirty = 1;
|
||||
assert_hvf_ok(r);
|
||||
|
||||
return hvf_arch_init_vcpu(cpu);
|
||||
}
|
||||
|
||||
/*
|
||||
* The HVF-specific vCPU thread function. This one should only run when the host
|
||||
* CPU supports the VMX "unrestricted guest" feature.
|
||||
*/
|
||||
static void *hvf_cpu_thread_fn(void *arg)
|
||||
{
|
||||
CPUState *cpu = arg;
|
||||
|
||||
int r;
|
||||
|
||||
assert(hvf_enabled());
|
||||
|
||||
rcu_register_thread();
|
||||
|
||||
qemu_mutex_lock_iothread();
|
||||
qemu_thread_get_self(cpu->thread);
|
||||
|
||||
cpu->thread_id = qemu_get_thread_id();
|
||||
cpu->can_do_io = 1;
|
||||
current_cpu = cpu;
|
||||
|
||||
hvf_init_vcpu(cpu);
|
||||
|
||||
/* signal CPU creation */
|
||||
cpu_thread_signal_created(cpu);
|
||||
qemu_guest_random_seed_thread_part2(cpu->random_seed);
|
||||
|
||||
do {
|
||||
if (cpu_can_run(cpu)) {
|
||||
r = hvf_vcpu_exec(cpu);
|
||||
if (r == EXCP_DEBUG) {
|
||||
cpu_handle_guest_debug(cpu);
|
||||
}
|
||||
}
|
||||
qemu_wait_io_event(cpu);
|
||||
} while (!cpu->unplug || cpu_can_run(cpu));
|
||||
|
||||
hvf_vcpu_destroy(cpu);
|
||||
cpu_thread_signal_destroyed(cpu);
|
||||
qemu_mutex_unlock_iothread();
|
||||
rcu_unregister_thread();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void hvf_start_vcpu_thread(CPUState *cpu)
|
||||
{
|
||||
char thread_name[VCPU_THREAD_NAME_SIZE];
|
||||
|
||||
/*
|
||||
* HVF currently does not support TCG, and only runs in
|
||||
* unrestricted-guest mode.
|
||||
*/
|
||||
assert(hvf_enabled());
|
||||
|
||||
cpu->thread = g_malloc0(sizeof(QemuThread));
|
||||
cpu->halt_cond = g_malloc0(sizeof(QemuCond));
|
||||
qemu_cond_init(cpu->halt_cond);
|
||||
|
||||
snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HVF",
|
||||
cpu->cpu_index);
|
||||
qemu_thread_create(cpu->thread, thread_name, hvf_cpu_thread_fn,
|
||||
cpu, QEMU_THREAD_JOINABLE);
|
||||
}
|
||||
|
||||
__attribute__((weak)) void hvf_kick_vcpu_thread(CPUState *cpu)
|
||||
{
|
||||
cpus_kick_thread(cpu);
|
||||
}
|
||||
|
||||
static const CpusAccel hvf_cpus = {
|
||||
.create_vcpu_thread = hvf_start_vcpu_thread,
|
||||
.kick_vcpu_thread = hvf_kick_vcpu_thread,
|
||||
|
||||
.synchronize_post_reset = hvf_cpu_synchronize_post_reset,
|
||||
.synchronize_post_init = hvf_cpu_synchronize_post_init,
|
||||
.synchronize_state = hvf_cpu_synchronize_state,
|
||||
.synchronize_pre_loadvm = hvf_cpu_synchronize_pre_loadvm,
|
||||
};
|
||||
|
||||
static int hvf_accel_init(MachineState *ms)
|
||||
{
|
||||
int x;
|
||||
hv_return_t ret;
|
||||
HVFState *s;
|
||||
|
||||
ret = hv_vm_create(HV_VM_DEFAULT);
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
s = g_new0(HVFState, 1);
|
||||
|
||||
s->num_slots = 32;
|
||||
for (x = 0; x < s->num_slots; ++x) {
|
||||
s->slots[x].size = 0;
|
||||
s->slots[x].slot_id = x;
|
||||
}
|
||||
|
||||
hvf_state = s;
|
||||
memory_listener_register(&hvf_memory_listener, &address_space_memory);
|
||||
cpus_register_accel(&hvf_cpus);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void hvf_accel_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
AccelClass *ac = ACCEL_CLASS(oc);
|
||||
ac->name = "HVF";
|
||||
ac->init_machine = hvf_accel_init;
|
||||
ac->allowed = &hvf_allowed;
|
||||
}
|
||||
|
||||
static const TypeInfo hvf_accel_type = {
|
||||
.name = TYPE_HVF_ACCEL,
|
||||
.parent = TYPE_ACCEL,
|
||||
.class_init = hvf_accel_class_init,
|
||||
};
|
||||
|
||||
static void hvf_type_init(void)
|
||||
{
|
||||
type_register_static(&hvf_accel_type);
|
||||
}
|
||||
|
||||
type_init(hvf_type_init);
|
||||
@@ -0,0 +1,7 @@
|
||||
hvf_ss = ss.source_set()
|
||||
hvf_ss.add(files(
|
||||
'hvf-all.c',
|
||||
'hvf-cpus.c',
|
||||
))
|
||||
|
||||
specific_ss.add_all(when: 'CONFIG_HVF', if_true: hvf_ss)
|
||||
@@ -1,5 +1,6 @@
|
||||
softmmu_ss.add(files('accel.c'))
|
||||
|
||||
subdir('hvf')
|
||||
subdir('qtest')
|
||||
subdir('kvm')
|
||||
subdir('tcg')
|
||||
|
||||
+28
-15
@@ -144,13 +144,14 @@ static void init_delay_params(SyncClocks *sc, const CPUState *cpu)
|
||||
#endif /* CONFIG USER ONLY */
|
||||
|
||||
/* Execute a TB, and fix up the CPU state afterwards if necessary */
|
||||
static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb)
|
||||
static inline TranslationBlock *cpu_tb_exec(CPUState *cpu,
|
||||
TranslationBlock *itb,
|
||||
int *tb_exit)
|
||||
{
|
||||
CPUArchState *env = cpu->env_ptr;
|
||||
uintptr_t ret;
|
||||
TranslationBlock *last_tb;
|
||||
int tb_exit;
|
||||
uint8_t *tb_ptr = itb->tc.ptr;
|
||||
const void *tb_ptr = itb->tc.ptr;
|
||||
|
||||
qemu_log_mask_and_addr(CPU_LOG_EXEC, itb->pc,
|
||||
"Trace %d: %p ["
|
||||
@@ -175,13 +176,23 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb)
|
||||
}
|
||||
#endif /* DEBUG_DISAS */
|
||||
|
||||
qemu_thread_jit_execute();
|
||||
ret = tcg_qemu_tb_exec(env, tb_ptr);
|
||||
cpu->can_do_io = 1;
|
||||
last_tb = (TranslationBlock *)(ret & ~TB_EXIT_MASK);
|
||||
tb_exit = ret & TB_EXIT_MASK;
|
||||
trace_exec_tb_exit(last_tb, tb_exit);
|
||||
/*
|
||||
* TODO: Delay swapping back to the read-write region of the TB
|
||||
* until we actually need to modify the TB. The read-only copy,
|
||||
* coming from the rx region, shares the same host TLB entry as
|
||||
* the code that executed the exit_tb opcode that arrived here.
|
||||
* If we insist on touching both the RX and the RW pages, we
|
||||
* double the host TLB pressure.
|
||||
*/
|
||||
last_tb = tcg_splitwx_to_rw((void *)(ret & ~TB_EXIT_MASK));
|
||||
*tb_exit = ret & TB_EXIT_MASK;
|
||||
|
||||
if (tb_exit > TB_EXIT_IDX1) {
|
||||
trace_exec_tb_exit(last_tb, *tb_exit);
|
||||
|
||||
if (*tb_exit > TB_EXIT_IDX1) {
|
||||
/* We didn't start executing this TB (eg because the instruction
|
||||
* counter hit zero); we must restore the guest PC to the address
|
||||
* of the start of the TB.
|
||||
@@ -199,7 +210,7 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb)
|
||||
cc->set_pc(cpu, last_tb->pc);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return last_tb;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_USER_ONLY
|
||||
@@ -210,6 +221,7 @@ static void cpu_exec_nocache(CPUState *cpu, int max_cycles,
|
||||
{
|
||||
TranslationBlock *tb;
|
||||
uint32_t cflags = curr_cflags() | CF_NOCACHE;
|
||||
int tb_exit;
|
||||
|
||||
if (ignore_icount) {
|
||||
cflags &= ~CF_USE_ICOUNT;
|
||||
@@ -227,7 +239,7 @@ static void cpu_exec_nocache(CPUState *cpu, int max_cycles,
|
||||
|
||||
/* execute the generated code */
|
||||
trace_exec_tb_nocache(tb, tb->pc);
|
||||
cpu_tb_exec(cpu, tb);
|
||||
cpu_tb_exec(cpu, tb, &tb_exit);
|
||||
|
||||
mmap_lock();
|
||||
tb_phys_invalidate(tb, -1);
|
||||
@@ -244,6 +256,7 @@ void cpu_exec_step_atomic(CPUState *cpu)
|
||||
uint32_t flags;
|
||||
uint32_t cflags = 1;
|
||||
uint32_t cf_mask = cflags & CF_HASH_MASK;
|
||||
int tb_exit;
|
||||
|
||||
if (sigsetjmp(cpu->jmp_env, 0) == 0) {
|
||||
start_exclusive();
|
||||
@@ -260,7 +273,7 @@ void cpu_exec_step_atomic(CPUState *cpu)
|
||||
cc->cpu_exec_enter(cpu);
|
||||
/* execute the generated code */
|
||||
trace_exec_tb(tb, pc);
|
||||
cpu_tb_exec(cpu, tb);
|
||||
cpu_tb_exec(cpu, tb, &tb_exit);
|
||||
cc->cpu_exec_exit(cpu);
|
||||
} else {
|
||||
/*
|
||||
@@ -354,7 +367,9 @@ void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr)
|
||||
if (TCG_TARGET_HAS_direct_jump) {
|
||||
uintptr_t offset = tb->jmp_target_arg[n];
|
||||
uintptr_t tc_ptr = (uintptr_t)tb->tc.ptr;
|
||||
tb_target_set_jmp_target(tc_ptr, tc_ptr + offset, addr);
|
||||
uintptr_t jmp_rx = tc_ptr + offset;
|
||||
uintptr_t jmp_rw = jmp_rx - tcg_splitwx_diff;
|
||||
tb_target_set_jmp_target(tc_ptr, jmp_rx, jmp_rw, addr);
|
||||
} else {
|
||||
tb->jmp_target_arg[n] = addr;
|
||||
}
|
||||
@@ -365,6 +380,7 @@ static inline void tb_add_jump(TranslationBlock *tb, int n,
|
||||
{
|
||||
uintptr_t old;
|
||||
|
||||
qemu_thread_jit_write();
|
||||
assert(n < ARRAY_SIZE(tb->jmp_list_next));
|
||||
qemu_spin_lock(&tb_next->jmp_lock);
|
||||
|
||||
@@ -651,13 +667,10 @@ static inline bool cpu_handle_interrupt(CPUState *cpu,
|
||||
static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
|
||||
TranslationBlock **last_tb, int *tb_exit)
|
||||
{
|
||||
uintptr_t ret;
|
||||
int32_t insns_left;
|
||||
|
||||
trace_exec_tb(tb, tb->pc);
|
||||
ret = cpu_tb_exec(cpu, tb);
|
||||
tb = (TranslationBlock *)(ret & ~TB_EXIT_MASK);
|
||||
*tb_exit = ret & TB_EXIT_MASK;
|
||||
tb = cpu_tb_exec(cpu, tb, tb_exit);
|
||||
if (*tb_exit != TB_EXIT_REQUESTED) {
|
||||
*last_tb = tb;
|
||||
return;
|
||||
|
||||
+25
-1
@@ -38,6 +38,7 @@ struct TCGState {
|
||||
AccelState parent_obj;
|
||||
|
||||
bool mttcg_enabled;
|
||||
int splitwx_enabled;
|
||||
unsigned long tb_size;
|
||||
};
|
||||
typedef struct TCGState TCGState;
|
||||
@@ -94,6 +95,13 @@ static void tcg_accel_instance_init(Object *obj)
|
||||
TCGState *s = TCG_STATE(obj);
|
||||
|
||||
s->mttcg_enabled = default_mttcg_enabled();
|
||||
|
||||
/* If debugging enabled, default "auto on", otherwise off. */
|
||||
#ifdef CONFIG_DEBUG_TCG
|
||||
s->splitwx_enabled = -1;
|
||||
#else
|
||||
s->splitwx_enabled = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool mttcg_enabled;
|
||||
@@ -102,7 +110,7 @@ static int tcg_init(MachineState *ms)
|
||||
{
|
||||
TCGState *s = TCG_STATE(current_accel());
|
||||
|
||||
tcg_exec_init(s->tb_size * 1024 * 1024);
|
||||
tcg_exec_init(s->tb_size * 1024 * 1024, s->splitwx_enabled);
|
||||
mttcg_enabled = s->mttcg_enabled;
|
||||
|
||||
/*
|
||||
@@ -179,6 +187,18 @@ static void tcg_set_tb_size(Object *obj, Visitor *v,
|
||||
s->tb_size = value;
|
||||
}
|
||||
|
||||
static bool tcg_get_splitwx(Object *obj, Error **errp)
|
||||
{
|
||||
TCGState *s = TCG_STATE(obj);
|
||||
return s->splitwx_enabled;
|
||||
}
|
||||
|
||||
static void tcg_set_splitwx(Object *obj, bool value, Error **errp)
|
||||
{
|
||||
TCGState *s = TCG_STATE(obj);
|
||||
s->splitwx_enabled = value;
|
||||
}
|
||||
|
||||
static void tcg_accel_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
AccelClass *ac = ACCEL_CLASS(oc);
|
||||
@@ -196,6 +216,10 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data)
|
||||
object_class_property_set_description(oc, "tb-size",
|
||||
"TCG translation block cache size");
|
||||
|
||||
object_class_property_add_bool(oc, "split-wx",
|
||||
tcg_get_splitwx, tcg_set_splitwx);
|
||||
object_class_property_set_description(oc, "split-wx",
|
||||
"Map jit pages into separate RW and RX regions");
|
||||
}
|
||||
|
||||
static const TypeInfo tcg_accel_type = {
|
||||
|
||||
@@ -145,7 +145,7 @@ uint64_t HELPER(ctpop_i64)(uint64_t arg)
|
||||
return ctpop64(arg);
|
||||
}
|
||||
|
||||
void *HELPER(lookup_tb_ptr)(CPUArchState *env)
|
||||
const void *HELPER(lookup_tb_ptr)(CPUArchState *env)
|
||||
{
|
||||
CPUState *cpu = env_cpu(env);
|
||||
TranslationBlock *tb;
|
||||
@@ -154,7 +154,7 @@ void *HELPER(lookup_tb_ptr)(CPUArchState *env)
|
||||
|
||||
tb = tb_lookup__cpu_state(cpu, &pc, &cs_base, &flags, curr_cflags());
|
||||
if (tb == NULL) {
|
||||
return tcg_ctx->code_gen_epilogue;
|
||||
return tcg_code_gen_epilogue;
|
||||
}
|
||||
qemu_log_mask_and_addr(CPU_LOG_EXEC, pc,
|
||||
"Chain %d: %p ["
|
||||
|
||||
@@ -24,7 +24,7 @@ DEF_HELPER_FLAGS_1(clrsb_i64, TCG_CALL_NO_RWG_SE, i64, i64)
|
||||
DEF_HELPER_FLAGS_1(ctpop_i32, TCG_CALL_NO_RWG_SE, i32, i32)
|
||||
DEF_HELPER_FLAGS_1(ctpop_i64, TCG_CALL_NO_RWG_SE, i64, i64)
|
||||
|
||||
DEF_HELPER_FLAGS_1(lookup_tb_ptr, TCG_CALL_NO_WG_SE, ptr, env)
|
||||
DEF_HELPER_FLAGS_1(lookup_tb_ptr, TCG_CALL_NO_WG_SE, cptr, env)
|
||||
|
||||
DEF_HELPER_FLAGS_1(exit_atomic, TCG_CALL_NO_WG, noreturn, env)
|
||||
|
||||
|
||||
@@ -7,4 +7,4 @@ exec_tb_nocache(void *tb, uintptr_t pc) "tb:%p pc=0x%"PRIxPTR
|
||||
exec_tb_exit(void *last_tb, unsigned int flags) "tb:%p flags=0x%x"
|
||||
|
||||
# translate-all.c
|
||||
translate_block(void *tb, uintptr_t pc, uint8_t *tb_code) "tb:%p, pc:0x%"PRIxPTR", tb_code:%p"
|
||||
translate_block(void *tb, uintptr_t pc, const void *tb_code) "tb:%p, pc:0x%"PRIxPTR", tb_code:%p"
|
||||
+249
-65
@@ -59,6 +59,7 @@
|
||||
#include "sysemu/cpus.h"
|
||||
#include "sysemu/cpu-timers.h"
|
||||
#include "sysemu/tcg.h"
|
||||
#include "qapi/error.h"
|
||||
|
||||
/* #define DEBUG_TB_INVALIDATE */
|
||||
/* #define DEBUG_TB_FLUSH */
|
||||
@@ -269,9 +270,9 @@ static uint8_t *encode_sleb128(uint8_t *p, target_long val)
|
||||
|
||||
/* Decode a signed leb128 sequence at *PP; increment *PP past the
|
||||
decoded value. Return the decoded value. */
|
||||
static target_long decode_sleb128(uint8_t **pp)
|
||||
static target_long decode_sleb128(const uint8_t **pp)
|
||||
{
|
||||
uint8_t *p = *pp;
|
||||
const uint8_t *p = *pp;
|
||||
target_long val = 0;
|
||||
int byte, shift = 0;
|
||||
|
||||
@@ -342,7 +343,7 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,
|
||||
target_ulong data[TARGET_INSN_START_WORDS] = { tb->pc };
|
||||
uintptr_t host_pc = (uintptr_t)tb->tc.ptr;
|
||||
CPUArchState *env = cpu->env_ptr;
|
||||
uint8_t *p = tb->tc.ptr + tb->tc.size;
|
||||
const uint8_t *p = tb->tc.ptr + tb->tc.size;
|
||||
int i, j, num_insns = tb->icount;
|
||||
#ifdef CONFIG_PROFILER
|
||||
TCGProfile *prof = &tcg_ctx->prof;
|
||||
@@ -392,27 +393,18 @@ void tb_destroy(TranslationBlock *tb)
|
||||
|
||||
bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit)
|
||||
{
|
||||
TranslationBlock *tb;
|
||||
bool r = false;
|
||||
uintptr_t check_offset;
|
||||
|
||||
/* The host_pc has to be in the region of current code buffer. If
|
||||
* it is not we will not be able to resolve it here. The two cases
|
||||
* where host_pc will not be correct are:
|
||||
/*
|
||||
* The host_pc has to be in the rx region of the code buffer.
|
||||
* If it is not we will not be able to resolve it here.
|
||||
* The two cases where host_pc will not be correct are:
|
||||
*
|
||||
* - fault during translation (instruction fetch)
|
||||
* - fault from helper (not using GETPC() macro)
|
||||
*
|
||||
* Either way we need return early as we can't resolve it here.
|
||||
*
|
||||
* We are using unsigned arithmetic so if host_pc <
|
||||
* tcg_init_ctx.code_gen_buffer check_offset will wrap to way
|
||||
* above the code_gen_buffer_size
|
||||
*/
|
||||
check_offset = host_pc - (uintptr_t) tcg_init_ctx.code_gen_buffer;
|
||||
|
||||
if (check_offset < tcg_init_ctx.code_gen_buffer_size) {
|
||||
tb = tcg_tb_lookup(host_pc);
|
||||
if (in_code_gen_buffer((const void *)(host_pc - tcg_splitwx_diff))) {
|
||||
TranslationBlock *tb = tcg_tb_lookup(host_pc);
|
||||
if (tb) {
|
||||
cpu_restore_state_from_tb(cpu, tb, host_pc, will_exit);
|
||||
if (tb_cflags(tb) & CF_NOCACHE) {
|
||||
@@ -421,11 +413,10 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit)
|
||||
tcg_tb_remove(tb);
|
||||
tb_destroy(tb);
|
||||
}
|
||||
r = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void page_init(void)
|
||||
@@ -973,7 +964,7 @@ static void page_lock_pair(PageDesc **ret_p1, tb_page_addr_t phys1,
|
||||
(DEFAULT_CODE_GEN_BUFFER_SIZE_1 < MAX_CODE_GEN_BUFFER_SIZE \
|
||||
? DEFAULT_CODE_GEN_BUFFER_SIZE_1 : MAX_CODE_GEN_BUFFER_SIZE)
|
||||
|
||||
static inline size_t size_code_gen_buffer(size_t tb_size)
|
||||
static size_t size_code_gen_buffer(size_t tb_size)
|
||||
{
|
||||
/* Size the buffer. */
|
||||
if (tb_size == 0) {
|
||||
@@ -1024,22 +1015,27 @@ static inline void *split_cross_256mb(void *buf1, size_t size1)
|
||||
static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE]
|
||||
__attribute__((aligned(CODE_GEN_ALIGN)));
|
||||
|
||||
static inline void *alloc_code_gen_buffer(void)
|
||||
static bool alloc_code_gen_buffer(size_t tb_size, int splitwx, Error **errp)
|
||||
{
|
||||
void *buf = static_code_gen_buffer;
|
||||
void *end = static_code_gen_buffer + sizeof(static_code_gen_buffer);
|
||||
void *buf, *end;
|
||||
size_t size;
|
||||
|
||||
if (splitwx > 0) {
|
||||
error_setg(errp, "jit split-wx not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* page-align the beginning and end of the buffer */
|
||||
buf = static_code_gen_buffer;
|
||||
end = static_code_gen_buffer + sizeof(static_code_gen_buffer);
|
||||
buf = QEMU_ALIGN_PTR_UP(buf, qemu_real_host_page_size);
|
||||
end = QEMU_ALIGN_PTR_DOWN(end, qemu_real_host_page_size);
|
||||
|
||||
size = end - buf;
|
||||
|
||||
/* Honor a command-line option limiting the size of the buffer. */
|
||||
if (size > tcg_ctx->code_gen_buffer_size) {
|
||||
size = QEMU_ALIGN_DOWN(tcg_ctx->code_gen_buffer_size,
|
||||
qemu_real_host_page_size);
|
||||
if (size > tb_size) {
|
||||
size = QEMU_ALIGN_DOWN(tb_size, qemu_real_host_page_size);
|
||||
}
|
||||
tcg_ctx->code_gen_buffer_size = size;
|
||||
|
||||
@@ -1051,31 +1047,49 @@ static inline void *alloc_code_gen_buffer(void)
|
||||
#endif
|
||||
|
||||
if (qemu_mprotect_rwx(buf, size)) {
|
||||
abort();
|
||||
error_setg_errno(errp, errno, "mprotect of jit buffer");
|
||||
return false;
|
||||
}
|
||||
qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE);
|
||||
|
||||
return buf;
|
||||
tcg_ctx->code_gen_buffer = buf;
|
||||
return true;
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
static inline void *alloc_code_gen_buffer(void)
|
||||
static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp)
|
||||
{
|
||||
size_t size = tcg_ctx->code_gen_buffer_size;
|
||||
return VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT,
|
||||
PAGE_EXECUTE_READWRITE);
|
||||
void *buf;
|
||||
|
||||
if (splitwx > 0) {
|
||||
error_setg(errp, "jit split-wx not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
buf = VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT,
|
||||
PAGE_EXECUTE_READWRITE);
|
||||
if (buf == NULL) {
|
||||
error_setg_win32(errp, GetLastError(),
|
||||
"allocate %zu bytes for jit buffer", size);
|
||||
return false;
|
||||
}
|
||||
|
||||
tcg_ctx->code_gen_buffer = buf;
|
||||
tcg_ctx->code_gen_buffer_size = size;
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
static inline void *alloc_code_gen_buffer(void)
|
||||
static bool alloc_code_gen_buffer_anon(size_t size, int prot,
|
||||
int flags, Error **errp)
|
||||
{
|
||||
int prot = PROT_WRITE | PROT_READ | PROT_EXEC;
|
||||
int flags = MAP_PRIVATE | MAP_ANONYMOUS;
|
||||
size_t size = tcg_ctx->code_gen_buffer_size;
|
||||
void *buf;
|
||||
|
||||
buf = mmap(NULL, size, prot, flags, -1, 0);
|
||||
if (buf == MAP_FAILED) {
|
||||
return NULL;
|
||||
error_setg_errno(errp, errno,
|
||||
"allocate %zu bytes for jit buffer", size);
|
||||
return false;
|
||||
}
|
||||
tcg_ctx->code_gen_buffer_size = size;
|
||||
|
||||
#ifdef __mips__
|
||||
if (cross_256mb(buf, size)) {
|
||||
@@ -1114,20 +1128,184 @@ static inline void *alloc_code_gen_buffer(void)
|
||||
/* Request large pages for the buffer. */
|
||||
qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE);
|
||||
|
||||
return buf;
|
||||
tcg_ctx->code_gen_buffer = buf;
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_TCG_INTERPRETER
|
||||
#ifdef CONFIG_POSIX
|
||||
#include "qemu/memfd.h"
|
||||
|
||||
static bool alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp)
|
||||
{
|
||||
void *buf_rw = NULL, *buf_rx = MAP_FAILED;
|
||||
int fd = -1;
|
||||
|
||||
#ifdef __mips__
|
||||
/* Find space for the RX mapping, vs the 256MiB regions. */
|
||||
if (!alloc_code_gen_buffer_anon(size, PROT_NONE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS |
|
||||
MAP_NORESERVE, errp)) {
|
||||
return false;
|
||||
}
|
||||
/* The size of the mapping may have been adjusted. */
|
||||
size = tcg_ctx->code_gen_buffer_size;
|
||||
buf_rx = tcg_ctx->code_gen_buffer;
|
||||
#endif
|
||||
|
||||
buf_rw = qemu_memfd_alloc("tcg-jit", size, 0, &fd, errp);
|
||||
if (buf_rw == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#ifdef __mips__
|
||||
void *tmp = mmap(buf_rx, size, PROT_READ | PROT_EXEC,
|
||||
MAP_SHARED | MAP_FIXED, fd, 0);
|
||||
if (tmp != buf_rx) {
|
||||
goto fail_rx;
|
||||
}
|
||||
#else
|
||||
buf_rx = mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_SHARED, fd, 0);
|
||||
if (buf_rx == MAP_FAILED) {
|
||||
goto fail_rx;
|
||||
}
|
||||
#endif
|
||||
|
||||
close(fd);
|
||||
tcg_ctx->code_gen_buffer = buf_rw;
|
||||
tcg_ctx->code_gen_buffer_size = size;
|
||||
tcg_splitwx_diff = buf_rx - buf_rw;
|
||||
|
||||
/* Request large pages for the buffer and the splitwx. */
|
||||
qemu_madvise(buf_rw, size, QEMU_MADV_HUGEPAGE);
|
||||
qemu_madvise(buf_rx, size, QEMU_MADV_HUGEPAGE);
|
||||
return true;
|
||||
|
||||
fail_rx:
|
||||
error_setg_errno(errp, errno, "failed to map shared memory for execute");
|
||||
fail:
|
||||
if (buf_rx != MAP_FAILED) {
|
||||
munmap(buf_rx, size);
|
||||
}
|
||||
if (buf_rw) {
|
||||
munmap(buf_rw, size);
|
||||
}
|
||||
if (fd >= 0) {
|
||||
close(fd);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif /* CONFIG_POSIX */
|
||||
|
||||
#ifdef CONFIG_DARWIN
|
||||
#include <mach/mach.h>
|
||||
|
||||
extern kern_return_t mach_vm_remap(vm_map_t target_task,
|
||||
mach_vm_address_t *target_address,
|
||||
mach_vm_size_t size,
|
||||
mach_vm_offset_t mask,
|
||||
int flags,
|
||||
vm_map_t src_task,
|
||||
mach_vm_address_t src_address,
|
||||
boolean_t copy,
|
||||
vm_prot_t *cur_protection,
|
||||
vm_prot_t *max_protection,
|
||||
vm_inherit_t inheritance);
|
||||
|
||||
static bool alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **errp)
|
||||
{
|
||||
kern_return_t ret;
|
||||
mach_vm_address_t buf_rw, buf_rx;
|
||||
vm_prot_t cur_prot, max_prot;
|
||||
|
||||
/* Map the read-write portion via normal anon memory. */
|
||||
if (!alloc_code_gen_buffer_anon(size, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, errp)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
buf_rw = (mach_vm_address_t)tcg_ctx->code_gen_buffer;
|
||||
buf_rx = 0;
|
||||
ret = mach_vm_remap(mach_task_self(),
|
||||
&buf_rx,
|
||||
size,
|
||||
0,
|
||||
VM_FLAGS_ANYWHERE,
|
||||
mach_task_self(),
|
||||
buf_rw,
|
||||
false,
|
||||
&cur_prot,
|
||||
&max_prot,
|
||||
VM_INHERIT_NONE);
|
||||
if (ret != KERN_SUCCESS) {
|
||||
/* TODO: Convert "ret" to a human readable error message. */
|
||||
error_setg(errp, "vm_remap for jit splitwx failed");
|
||||
munmap((void *)buf_rw, size);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mprotect((void *)buf_rx, size, PROT_READ | PROT_EXEC) != 0) {
|
||||
error_setg_errno(errp, errno, "mprotect for jit splitwx");
|
||||
munmap((void *)buf_rx, size);
|
||||
munmap((void *)buf_rw, size);
|
||||
return false;
|
||||
}
|
||||
|
||||
tcg_splitwx_diff = buf_rx - buf_rw;
|
||||
return true;
|
||||
}
|
||||
#endif /* CONFIG_DARWIN */
|
||||
#endif /* CONFIG_TCG_INTERPRETER */
|
||||
|
||||
static bool alloc_code_gen_buffer_splitwx(size_t size, Error **errp)
|
||||
{
|
||||
#ifndef CONFIG_TCG_INTERPRETER
|
||||
# ifdef CONFIG_DARWIN
|
||||
return alloc_code_gen_buffer_splitwx_vmremap(size, errp);
|
||||
# endif
|
||||
# ifdef CONFIG_POSIX
|
||||
return alloc_code_gen_buffer_splitwx_memfd(size, errp);
|
||||
# endif
|
||||
#endif
|
||||
error_setg(errp, "jit split-wx not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp)
|
||||
{
|
||||
ERRP_GUARD();
|
||||
int prot, flags;
|
||||
|
||||
if (splitwx) {
|
||||
if (alloc_code_gen_buffer_splitwx(size, errp)) {
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
* If splitwx force-on (1), fail;
|
||||
* if splitwx default-on (-1), fall through to splitwx off.
|
||||
*/
|
||||
if (splitwx > 0) {
|
||||
return false;
|
||||
}
|
||||
error_free_or_abort(errp);
|
||||
}
|
||||
|
||||
prot = PROT_READ | PROT_WRITE | PROT_EXEC;
|
||||
flags = MAP_PRIVATE | MAP_ANONYMOUS;
|
||||
#ifdef CONFIG_TCG_INTERPRETER
|
||||
/* The tcg interpreter does not need execute permission. */
|
||||
prot = PROT_READ | PROT_WRITE;
|
||||
#elif defined(CONFIG_DARWIN)
|
||||
/* Applicable to both iOS and macOS (Apple Silicon). */
|
||||
if (!splitwx) {
|
||||
flags |= MAP_JIT;
|
||||
}
|
||||
#endif
|
||||
|
||||
return alloc_code_gen_buffer_anon(size, prot, flags, errp);
|
||||
}
|
||||
#endif /* USE_STATIC_CODE_GEN_BUFFER, WIN32, POSIX */
|
||||
|
||||
static inline void code_gen_alloc(size_t tb_size)
|
||||
{
|
||||
tcg_ctx->code_gen_buffer_size = size_code_gen_buffer(tb_size);
|
||||
tcg_ctx->code_gen_buffer = alloc_code_gen_buffer();
|
||||
if (tcg_ctx->code_gen_buffer == NULL) {
|
||||
fprintf(stderr, "Could not allocate dynamic translator buffer\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static bool tb_cmp(const void *ap, const void *bp)
|
||||
{
|
||||
const TranslationBlock *a = ap;
|
||||
@@ -1152,13 +1330,19 @@ static void tb_htable_init(void)
|
||||
/* Must be called before using the QEMU cpus. 'tb_size' is the size
|
||||
(in bytes) allocated to the translation buffer. Zero means default
|
||||
size. */
|
||||
void tcg_exec_init(unsigned long tb_size)
|
||||
void tcg_exec_init(unsigned long tb_size, int splitwx)
|
||||
{
|
||||
bool ok;
|
||||
|
||||
tcg_allowed = true;
|
||||
cpu_gen_init();
|
||||
page_init();
|
||||
tb_htable_init();
|
||||
code_gen_alloc(tb_size);
|
||||
|
||||
ok = alloc_code_gen_buffer(size_code_gen_buffer(tb_size),
|
||||
splitwx, &error_fatal);
|
||||
assert(ok);
|
||||
|
||||
#if defined(CONFIG_SOFTMMU)
|
||||
/* There's no guest base to take into account, so go ahead and
|
||||
initialize the prologue now. */
|
||||
@@ -1485,7 +1669,9 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list)
|
||||
|
||||
static void tb_phys_invalidate__locked(TranslationBlock *tb)
|
||||
{
|
||||
qemu_thread_jit_write();
|
||||
do_tb_phys_invalidate(tb, true);
|
||||
qemu_thread_jit_execute();
|
||||
}
|
||||
|
||||
/* invalidate one TB
|
||||
@@ -1687,6 +1873,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
|
||||
#endif
|
||||
|
||||
assert_memory_lock();
|
||||
qemu_thread_jit_write();
|
||||
|
||||
phys_pc = get_page_addr_code(env, pc);
|
||||
|
||||
@@ -1722,7 +1909,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
|
||||
}
|
||||
|
||||
gen_code_buf = tcg_ctx->code_gen_ptr;
|
||||
tb->tc.ptr = gen_code_buf;
|
||||
tb->tc.ptr = tcg_splitwx_to_rx(gen_code_buf);
|
||||
tb->pc = pc;
|
||||
tb->cs_base = cs_base;
|
||||
tb->flags = flags;
|
||||
@@ -1816,15 +2003,19 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
|
||||
if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM) &&
|
||||
qemu_log_in_addr_range(tb->pc)) {
|
||||
FILE *logfile = qemu_log_lock();
|
||||
int code_size, data_size = 0;
|
||||
int code_size, data_size;
|
||||
const tcg_target_ulong *rx_data_gen_ptr;
|
||||
size_t chunk_start;
|
||||
int insn = 0;
|
||||
|
||||
if (tcg_ctx->data_gen_ptr) {
|
||||
code_size = tcg_ctx->data_gen_ptr - tb->tc.ptr;
|
||||
rx_data_gen_ptr = tcg_splitwx_to_rx(tcg_ctx->data_gen_ptr);
|
||||
code_size = (const void *)rx_data_gen_ptr - tb->tc.ptr;
|
||||
data_size = gen_code_size - code_size;
|
||||
} else {
|
||||
rx_data_gen_ptr = 0;
|
||||
code_size = gen_code_size;
|
||||
data_size = 0;
|
||||
}
|
||||
|
||||
/* Dump header and the first instruction */
|
||||
@@ -1859,16 +2050,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
|
||||
if (data_size) {
|
||||
int i;
|
||||
qemu_log(" data: [size=%d]\n", data_size);
|
||||
for (i = 0; i < data_size; i += sizeof(tcg_target_ulong)) {
|
||||
if (sizeof(tcg_target_ulong) == 8) {
|
||||
qemu_log("0x%08" PRIxPTR ": .quad 0x%016" PRIx64 "\n",
|
||||
(uintptr_t)tcg_ctx->data_gen_ptr + i,
|
||||
*(uint64_t *)(tcg_ctx->data_gen_ptr + i));
|
||||
} else {
|
||||
qemu_log("0x%08" PRIxPTR ": .long 0x%08x\n",
|
||||
(uintptr_t)tcg_ctx->data_gen_ptr + i,
|
||||
*(uint32_t *)(tcg_ctx->data_gen_ptr + i));
|
||||
}
|
||||
for (i = 0; i < data_size / sizeof(tcg_target_ulong); i++) {
|
||||
qemu_log("0x%08" PRIxPTR ": .quad 0x%" TCG_PRIlx "\n",
|
||||
(uintptr_t)&rx_data_gen_ptr[i], rx_data_gen_ptr[i]);
|
||||
}
|
||||
}
|
||||
qemu_log("\n");
|
||||
|
||||
@@ -133,8 +133,8 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db,
|
||||
}
|
||||
|
||||
/* The disas_log hook may use these values rather than recompute. */
|
||||
db->tb->size = db->pc_next - db->pc_first;
|
||||
db->tb->icount = db->num_insns;
|
||||
tb->size = db->pc_next - db->pc_first;
|
||||
tb->icount = db->num_insns;
|
||||
|
||||
#ifdef DEBUG_DISAS
|
||||
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
#ifdef CONFIG_BSD
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/queue.h>
|
||||
#ifndef __DragonFly__
|
||||
#if !defined(__DragonFly__) && !defined(CONFIG_IOS)
|
||||
#include <sys/disk.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
+61
-13
@@ -41,7 +41,7 @@
|
||||
#include "scsi/pr-manager.h"
|
||||
#include "scsi/constants.h"
|
||||
|
||||
#if defined(__APPLE__) && (__MACH__)
|
||||
#if defined(CONFIG_HOST_BLOCK_DEVICE) && defined(__APPLE__) && (__MACH__)
|
||||
#include <paths.h>
|
||||
#include <sys/param.h>
|
||||
#include <IOKit/IOKitLib.h>
|
||||
@@ -181,7 +181,17 @@ typedef struct BDRVRawReopenState {
|
||||
bool check_cache_dropped;
|
||||
} BDRVRawReopenState;
|
||||
|
||||
static int fd_open(BlockDriverState *bs);
|
||||
static int fd_open(BlockDriverState *bs)
|
||||
{
|
||||
BDRVRawState *s = bs->opaque;
|
||||
|
||||
/* this is just to ensure s->fd is sane (its called by io ops) */
|
||||
if (s->fd >= 0) {
|
||||
return 0;
|
||||
}
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int64_t raw_getlength(BlockDriverState *bs);
|
||||
|
||||
typedef struct RawPosixAIOData {
|
||||
@@ -252,6 +262,12 @@ static int raw_normalize_devicepath(const char **filename, Error **errp)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_IOS)
|
||||
static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
|
||||
{
|
||||
return -ENOTSUP; /* not supported on iOS */
|
||||
}
|
||||
#else /* CONFIG_IOS */
|
||||
/*
|
||||
* Get logical block size via ioctl. On success store it in @sector_size_p.
|
||||
*/
|
||||
@@ -284,6 +300,7 @@ static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
|
||||
|
||||
return success ? 0 : -errno;
|
||||
}
|
||||
#endif /* !CONFIG_IOS */
|
||||
|
||||
/**
|
||||
* Get physical block size of @fd.
|
||||
@@ -1373,17 +1390,50 @@ static int handle_aiocb_flush(void *opaque)
|
||||
#ifdef CONFIG_PREADV
|
||||
|
||||
static bool preadv_present = true;
|
||||
static bool preadv_checked;
|
||||
|
||||
static ssize_t
|
||||
qemu_preadv(int fd, const struct iovec *iov, int nr_iov, off_t offset)
|
||||
{
|
||||
#ifdef CONFIG_DARWIN /* preadv introduced in macOS 11 */
|
||||
if (unlikely(!preadv_checked)) {
|
||||
if (__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) {
|
||||
preadv_checked = true;
|
||||
} else {
|
||||
preadv_present = false;
|
||||
return -ENOSYS;
|
||||
}
|
||||
}
|
||||
/* Now we suppress the availability warning since we use the cached check */
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
|
||||
return preadv(fd, iov, nr_iov, offset);
|
||||
#pragma clang diagnostic pop
|
||||
#else /* CONFIG_DARWIN */
|
||||
return preadv(fd, iov, nr_iov, offset);
|
||||
#endif
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
qemu_pwritev(int fd, const struct iovec *iov, int nr_iov, off_t offset)
|
||||
{
|
||||
#ifdef CONFIG_DARWIN /* preadv introduced in macOS 11 */
|
||||
if (unlikely(!preadv_checked)) {
|
||||
if (__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) {
|
||||
preadv_checked = true;
|
||||
} else {
|
||||
preadv_present = false;
|
||||
return -ENOSYS;
|
||||
}
|
||||
}
|
||||
/* Now we suppress the availability warning since we use the cached check */
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
|
||||
return pwritev(fd, iov, nr_iov, offset);
|
||||
#pragma clang diagnostic pop
|
||||
#else /* CONFIG_DARWIN */
|
||||
return pwritev(fd, iov, nr_iov, offset);
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -2307,7 +2357,7 @@ again:
|
||||
}
|
||||
if (size == 0)
|
||||
#endif
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#if !defined(CONFIG_IOS) && defined(__APPLE__) && defined(__MACH__)
|
||||
{
|
||||
uint64_t sectors = 0;
|
||||
uint32_t sector_size = 0;
|
||||
@@ -3014,6 +3064,7 @@ static BlockStatsSpecific *raw_get_specific_stats(BlockDriverState *bs)
|
||||
return stats;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_HOST_BLOCK_DEVICE)
|
||||
static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs)
|
||||
{
|
||||
BlockStatsSpecific *stats = g_new(BlockStatsSpecific, 1);
|
||||
@@ -3023,6 +3074,7 @@ static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs)
|
||||
|
||||
return stats;
|
||||
}
|
||||
#endif /* CONFIG_HOST_BLOCK_DEVICE */
|
||||
|
||||
static QemuOptsList raw_create_opts = {
|
||||
.name = "raw-create-opts",
|
||||
@@ -3247,6 +3299,8 @@ BlockDriver bdrv_file = {
|
||||
/***********************************************/
|
||||
/* host device */
|
||||
|
||||
#if defined(CONFIG_HOST_BLOCK_DEVICE)
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
static kern_return_t GetBSDPath(io_iterator_t mediaIterator, char *bsdPath,
|
||||
CFIndex maxPathSize, int flags);
|
||||
@@ -3539,16 +3593,6 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
|
||||
}
|
||||
#endif /* linux */
|
||||
|
||||
static int fd_open(BlockDriverState *bs)
|
||||
{
|
||||
BDRVRawState *s = bs->opaque;
|
||||
|
||||
/* this is just to ensure s->fd is sane (its called by io ops) */
|
||||
if (s->fd >= 0)
|
||||
return 0;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static coroutine_fn int
|
||||
hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
|
||||
{
|
||||
@@ -3872,6 +3916,8 @@ static BlockDriver bdrv_host_cdrom = {
|
||||
};
|
||||
#endif /* __FreeBSD__ */
|
||||
|
||||
#endif /* CONFIG_HOST_BLOCK_DEVICE */
|
||||
|
||||
static void bdrv_file_init(void)
|
||||
{
|
||||
/*
|
||||
@@ -3879,6 +3925,7 @@ static void bdrv_file_init(void)
|
||||
* registered last will get probed first.
|
||||
*/
|
||||
bdrv_register(&bdrv_file);
|
||||
#if defined(CONFIG_HOST_BLOCK_DEVICE)
|
||||
bdrv_register(&bdrv_host_device);
|
||||
#ifdef __linux__
|
||||
bdrv_register(&bdrv_host_cdrom);
|
||||
@@ -3886,6 +3933,7 @@ static void bdrv_file_init(void)
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
bdrv_register(&bdrv_host_cdrom);
|
||||
#endif
|
||||
#endif /* CONFIG_HOST_BLOCK_DEVICE */
|
||||
}
|
||||
|
||||
block_init(bdrv_file_init);
|
||||
+1
-1
@@ -908,7 +908,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* init tcg before creating CPUs and to get qemu_host_page_size */
|
||||
tcg_exec_init(0);
|
||||
tcg_exec_init(0, false);
|
||||
|
||||
cpu_type = parse_cpu_option(cpu_model);
|
||||
cpu = cpu_create(cpu_type);
|
||||
|
||||
@@ -234,6 +234,7 @@ cpu=""
|
||||
iasl="iasl"
|
||||
interp_prefix="/usr/gnemul/qemu-%M"
|
||||
static="no"
|
||||
cross_compile="no"
|
||||
cross_prefix=""
|
||||
audio_drv_list=""
|
||||
block_drv_rw_whitelist=""
|
||||
@@ -451,6 +452,8 @@ skip_meson=no
|
||||
gettext=""
|
||||
fuse="auto"
|
||||
fuse_lseek="auto"
|
||||
host_block_device_support="yes"
|
||||
shared_lib="false"
|
||||
|
||||
bogus_os="no"
|
||||
malloc_trim="auto"
|
||||
@@ -460,6 +463,7 @@ for opt do
|
||||
optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
|
||||
case "$opt" in
|
||||
--cross-prefix=*) cross_prefix="$optarg"
|
||||
cross_compile="yes"
|
||||
;;
|
||||
--cc=*) CC="$optarg"
|
||||
;;
|
||||
@@ -557,6 +561,19 @@ EOF
|
||||
compile_object
|
||||
}
|
||||
|
||||
check_ios() {
|
||||
cat > $TMPC <<EOF
|
||||
#ifdef __APPLE__
|
||||
#import "TargetConditionals.h"
|
||||
#if !TARGET_OS_IPHONE
|
||||
#error TARGET_OS_IPHONE not true
|
||||
#endif
|
||||
#endif
|
||||
int main(void) { return 0; }
|
||||
EOF
|
||||
compile_object
|
||||
}
|
||||
|
||||
check_include() {
|
||||
cat > $TMPC <<EOF
|
||||
#include <$1>
|
||||
@@ -599,7 +616,11 @@ elif check_define __DragonFly__ ; then
|
||||
elif check_define __NetBSD__; then
|
||||
targetos='NetBSD'
|
||||
elif check_define __APPLE__; then
|
||||
targetos='Darwin'
|
||||
if check_ios ; then
|
||||
targetos='iOS'
|
||||
else
|
||||
targetos='Darwin'
|
||||
fi
|
||||
else
|
||||
# This is a fatal error, but don't report it yet, because we
|
||||
# might be going to just print the --help text, or it might
|
||||
@@ -776,6 +797,22 @@ Darwin)
|
||||
# won't work when we're compiling with gcc as a C compiler.
|
||||
QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
|
||||
;;
|
||||
iOS)
|
||||
bsd="yes"
|
||||
darwin="yes"
|
||||
ios="yes"
|
||||
if [ "$cpu" = "x86_64" ] ; then
|
||||
QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
|
||||
QEMU_LDFLAGS="-arch x86_64 $QEMU_LDFLAGS"
|
||||
fi
|
||||
host_block_device_support="no"
|
||||
audio_drv_list=""
|
||||
audio_possible_drivers=""
|
||||
QEMU_LDFLAGS="-framework CoreFoundation $QEMU_LDFLAGS"
|
||||
# Disable attempts to use ObjectiveC features in os/object.h since they
|
||||
# won't work when we're compiling with gcc as a C compiler.
|
||||
QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
|
||||
;;
|
||||
SunOS)
|
||||
solaris="yes"
|
||||
make="${MAKE-gmake}"
|
||||
@@ -1535,6 +1572,10 @@ for opt do
|
||||
;;
|
||||
--disable-fuse-lseek) fuse_lseek="disabled"
|
||||
;;
|
||||
--enable-shared-lib) shared_lib=true
|
||||
;;
|
||||
--disable-shared-lib) shared_lib=false
|
||||
;;
|
||||
*)
|
||||
echo "ERROR: unknown option $opt"
|
||||
echo "Try '$0 --help' for more information"
|
||||
@@ -1673,7 +1714,7 @@ $(echo Deprecated targets: $deprecated_targets_list | \
|
||||
--target-list-exclude=LIST exclude a set of targets from the default target-list
|
||||
|
||||
Advanced options (experts only):
|
||||
--cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
|
||||
--cross-prefix=PREFIX use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
|
||||
--cc=CC use C compiler CC [$cc]
|
||||
--iasl=IASL use ACPI compiler IASL [$iasl]
|
||||
--host-cc=CC use C compiler CC [$host_cc] for code run at
|
||||
@@ -1731,7 +1772,7 @@ Advanced options (experts only):
|
||||
--oss-lib path to OSS library
|
||||
--cpu=CPU Build for host CPU [$cpu]
|
||||
--with-coroutine=BACKEND coroutine backend. Supported options:
|
||||
ucontext, sigaltstack, windows
|
||||
ucontext, libucontext, sigaltstack, windows
|
||||
--enable-gcov enable test coverage analysis with gcov
|
||||
--disable-blobs disable installing provided firmware blobs
|
||||
--with-vss-sdk=SDK-path enable Windows VSS support in QEMU Guest Agent
|
||||
@@ -1745,6 +1786,7 @@ Advanced options (experts only):
|
||||
enable plugins via shared library loading
|
||||
--disable-containers don't use containers for cross-building
|
||||
--gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
|
||||
--enable-shared-lib build QEMU as a shared library
|
||||
|
||||
Optional features, enabled with --enable-FEATURE and
|
||||
disabled with --disable-FEATURE, default is enabled if available:
|
||||
@@ -4877,6 +4919,8 @@ if test "$coroutine" = ""; then
|
||||
coroutine=win32
|
||||
elif test "$ucontext_works" = "yes"; then
|
||||
coroutine=ucontext
|
||||
elif test "$ios" = "yes"; then
|
||||
coroutine=libucontext
|
||||
else
|
||||
coroutine=sigaltstack
|
||||
fi
|
||||
@@ -4900,12 +4944,27 @@ else
|
||||
error_exit "only the 'windows' coroutine backend is valid for Windows"
|
||||
fi
|
||||
;;
|
||||
libucontext)
|
||||
;;
|
||||
*)
|
||||
error_exit "unknown coroutine backend $coroutine"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
case $coroutine in
|
||||
libucontext)
|
||||
git_submodules="${git_submodules} subprojects/libucontext"
|
||||
mkdir -p libucontext
|
||||
coroutine_impl=ucontext
|
||||
libucontext="enabled"
|
||||
;;
|
||||
*)
|
||||
coroutine_impl=$coroutine
|
||||
libucontext="disabled"
|
||||
;;
|
||||
esac
|
||||
|
||||
if test "$coroutine_pool" = ""; then
|
||||
coroutine_pool=yes
|
||||
fi
|
||||
@@ -5937,6 +5996,9 @@ if test "$default_devices" = "yes" ; then
|
||||
else
|
||||
echo "CONFIG_MINIKCONF_MODE=--allnoconfig" >> $config_host_mak
|
||||
fi
|
||||
if test "$host_block_device_support" = "yes" ; then
|
||||
echo "CONFIG_HOST_BLOCK_DEVICE=y" >> $config_host_mak
|
||||
fi
|
||||
if test "$debug_tcg" = "yes" ; then
|
||||
echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
|
||||
fi
|
||||
@@ -5986,6 +6048,10 @@ if test "$darwin" = "yes" ; then
|
||||
echo "CONFIG_DARWIN=y" >> $config_host_mak
|
||||
fi
|
||||
|
||||
if test "$ios" = "yes" ; then
|
||||
echo "CONFIG_IOS=y" >> $config_host_mak
|
||||
fi
|
||||
|
||||
if test "$solaris" = "yes" ; then
|
||||
echo "CONFIG_SOLARIS=y" >> $config_host_mak
|
||||
fi
|
||||
@@ -6444,7 +6510,7 @@ if test "$rbd" = "yes" ; then
|
||||
echo "RBD_LIBS=$rbd_libs" >> $config_host_mak
|
||||
fi
|
||||
|
||||
echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
|
||||
echo "CONFIG_COROUTINE_BACKEND=$coroutine_impl" >> $config_host_mak
|
||||
if test "$coroutine_pool" = "yes" ; then
|
||||
echo "CONFIG_COROUTINE_POOL=1" >> $config_host_mak
|
||||
else
|
||||
@@ -6950,6 +7016,7 @@ echo "cpp_link_args = [${LDFLAGS:+$(meson_quote $LDFLAGS)}]" >> $cross
|
||||
echo "[binaries]" >> $cross
|
||||
echo "c = [$(meson_quote $cc)]" >> $cross
|
||||
test -n "$cxx" && echo "cpp = [$(meson_quote $cxx)]" >> $cross
|
||||
test -n "$objcc" && echo "objc = [$(meson_quote $objcc)]" >> $cross
|
||||
echo "ar = [$(meson_quote $ar)]" >> $cross
|
||||
echo "nm = [$(meson_quote $nm)]" >> $cross
|
||||
echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
|
||||
@@ -6957,9 +7024,13 @@ echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
|
||||
if has $sdl2_config; then
|
||||
echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
|
||||
fi
|
||||
echo "strip = [$(meson_quote $strip)]" >> $cross
|
||||
if test "$shared_lib" = "true"; then
|
||||
echo "strip = [$(meson_quote $strip), '-x']" >> $cross
|
||||
else
|
||||
echo "strip = [$(meson_quote $strip)]" >> $cross
|
||||
fi
|
||||
echo "windres = [$(meson_quote $windres)]" >> $cross
|
||||
if test -n "$cross_prefix"; then
|
||||
if test "$cross_compile" = "yes"; then
|
||||
cross_arg="--cross-file config-meson.cross"
|
||||
echo "[host_machine]" >> $cross
|
||||
if test "$mingw32" = "yes" ; then
|
||||
@@ -6968,10 +7039,16 @@ if test -n "$cross_prefix"; then
|
||||
if test "$linux" = "yes" ; then
|
||||
echo "system = 'linux'" >> $cross
|
||||
fi
|
||||
if test "$darwin" = "yes" ; then
|
||||
echo "system = 'darwin'" >> $cross
|
||||
fi
|
||||
case "$ARCH" in
|
||||
i386|x86_64)
|
||||
i386)
|
||||
echo "cpu_family = 'x86'" >> $cross
|
||||
;;
|
||||
x86_64)
|
||||
echo "cpu_family = 'x86_64'" >> $cross
|
||||
;;
|
||||
ppc64le)
|
||||
echo "cpu_family = 'ppc64'" >> $cross
|
||||
;;
|
||||
@@ -7022,11 +7099,11 @@ NINJA=$ninja $meson setup \
|
||||
-Dcocoa=$cocoa -Dmpath=$mpath -Dsdl=$sdl -Dsdl_image=$sdl_image \
|
||||
-Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \
|
||||
-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f -Dvirtiofsd=$virtiofsd \
|
||||
-Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt \
|
||||
-Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt -Ducontext=$libucontext \
|
||||
-Diconv=$iconv -Dcurses=$curses -Dlibudev=$libudev\
|
||||
-Ddocs=$docs -Dsphinx_build=$sphinx_build -Dinstall_blobs=$blobs \
|
||||
-Dvhost_user_blk_server=$vhost_user_blk_server \
|
||||
-Dfuse=$fuse -Dfuse_lseek=$fuse_lseek \
|
||||
-Dfuse=$fuse -Dfuse_lseek=$fuse_lseek -Dshared-lib=$shared_lib \
|
||||
$cross_arg \
|
||||
"$PWD" "$source_path"
|
||||
|
||||
|
||||
@@ -299,7 +299,7 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size)
|
||||
}
|
||||
|
||||
/* Disassemble this for me please... (debugging). */
|
||||
void disas(FILE *out, void *code, unsigned long size)
|
||||
void disas(FILE *out, const void *code, unsigned long size)
|
||||
{
|
||||
uintptr_t pc;
|
||||
int count;
|
||||
|
||||
+1
-1
@@ -229,7 +229,7 @@ bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size)
|
||||
}
|
||||
|
||||
/* Disassemble SIZE bytes at CODE for the host. */
|
||||
bool cap_disas_host(disassemble_info *info, void *code, size_t size)
|
||||
bool cap_disas_host(disassemble_info *info, const void *code, size_t size)
|
||||
{
|
||||
csh handle;
|
||||
const uint8_t *cbuf;
|
||||
|
||||
@@ -35,3 +35,4 @@ Contents:
|
||||
clocks
|
||||
qom
|
||||
block-coroutine-wrapper
|
||||
ios
|
||||
@@ -0,0 +1,28 @@
|
||||
===========
|
||||
iOS Support
|
||||
===========
|
||||
|
||||
To run qemu on the iOS platform, some modifications were required. Most of the
|
||||
modifications are conditioned on the ``CONFIG_IOS`` and configuration variable.
|
||||
|
||||
Build support
|
||||
-------------
|
||||
|
||||
For the code to compile, certain changes in the block driver and the slirp
|
||||
driver had to be made. There is no ``system()`` call, so it has been replaced
|
||||
with an assertion error. There should be no code path that call system() from
|
||||
iOS.
|
||||
|
||||
``ucontext`` support is broken on iOS. The implementation from ``libucontext``
|
||||
is used instead.
|
||||
|
||||
JIT support
|
||||
-----------
|
||||
|
||||
On iOS, allocating RWX pages require special entitlements not usually granted to
|
||||
apps. However, it is possible to use `bulletproof JIT`_ with a development
|
||||
certificate. This means that we need to allocate one chunk of memory with RX
|
||||
permissions and then mirror map the same memory with RW permissions. We generate
|
||||
code to the mirror mapping and execute the original mapping.
|
||||
|
||||
.. _bulletproof JIT: https://www.blackhat.com/docs/us-16/materials/us-16-Krstic.pdf
|
||||
@@ -61,6 +61,7 @@ if config_all_devices.has_key('CONFIG_VIRTIO_GPU')
|
||||
virtio_gpu_ss.add(when: ['CONFIG_VIRTIO_GPU', 'CONFIG_VIRGL'],
|
||||
if_true: [files('virtio-gpu-3d.c'), pixman, virgl])
|
||||
virtio_gpu_ss.add(when: 'CONFIG_VHOST_USER_GPU', if_true: files('vhost-user-gpu.c'))
|
||||
virtio_gpu_ss.add(when: 'CONFIG_FW_CFG_DMA', if_true: files('virtio-ramfb.c'))
|
||||
hw_display_modules += {'virtio-gpu': virtio_gpu_ss}
|
||||
endif
|
||||
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "hw/pci/pci.h"
|
||||
#include "ui/console.h"
|
||||
#include "hw/qdev-properties.h"
|
||||
#include "hw/virtio/virtio-gpu-pci.h"
|
||||
#include "qapi/error.h"
|
||||
#include "hw/display/ramfb.h"
|
||||
#include "qom/object.h"
|
||||
|
||||
/*
|
||||
* virtio-ramfb-base: This extends VirtioPCIProxy.
|
||||
*/
|
||||
#define TYPE_VIRTIO_RAMFB_BASE "virtio-ramfb-base"
|
||||
OBJECT_DECLARE_TYPE(VirtIORAMFBBase, VirtIORAMFBBaseClass,
|
||||
VIRTIO_RAMFB_BASE)
|
||||
|
||||
struct VirtIORAMFBBase {
|
||||
VirtIOPCIProxy parent_obj;
|
||||
|
||||
VirtIOGPUBase *vgpu;
|
||||
RAMFBState *ramfb;
|
||||
};
|
||||
|
||||
struct VirtIORAMFBBaseClass {
|
||||
VirtioPCIClass parent_class;
|
||||
|
||||
DeviceReset parent_reset;
|
||||
};
|
||||
|
||||
static void virtio_ramfb_invalidate_display(void *opaque)
|
||||
{
|
||||
VirtIORAMFBBase *vramfb = opaque;
|
||||
VirtIOGPUBase *g = vramfb->vgpu;
|
||||
|
||||
if (g->enable) {
|
||||
g->hw_ops->invalidate(g);
|
||||
}
|
||||
}
|
||||
|
||||
static void virtio_ramfb_update_display(void *opaque)
|
||||
{
|
||||
VirtIORAMFBBase *vramfb = opaque;
|
||||
VirtIOGPUBase *g = vramfb->vgpu;
|
||||
|
||||
if (g->enable) {
|
||||
g->hw_ops->gfx_update(g);
|
||||
} else {
|
||||
ramfb_display_update(g->scanout[0].con, vramfb->ramfb);
|
||||
}
|
||||
}
|
||||
|
||||
static int virtio_ramfb_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
|
||||
{
|
||||
VirtIORAMFBBase *vramfb = opaque;
|
||||
VirtIOGPUBase *g = vramfb->vgpu;
|
||||
|
||||
if (g->hw_ops->ui_info) {
|
||||
return g->hw_ops->ui_info(g, idx, info);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void virtio_ramfb_gl_block(void *opaque, bool block)
|
||||
{
|
||||
VirtIORAMFBBase *vramfb = opaque;
|
||||
VirtIOGPUBase *g = vramfb->vgpu;
|
||||
|
||||
if (g->hw_ops->gl_block) {
|
||||
g->hw_ops->gl_block(g, block);
|
||||
}
|
||||
}
|
||||
|
||||
static const GraphicHwOps virtio_ramfb_ops = {
|
||||
.invalidate = virtio_ramfb_invalidate_display,
|
||||
.gfx_update = virtio_ramfb_update_display,
|
||||
.ui_info = virtio_ramfb_ui_info,
|
||||
.gl_block = virtio_ramfb_gl_block,
|
||||
};
|
||||
|
||||
static const VMStateDescription vmstate_virtio_ramfb = {
|
||||
.name = "virtio-ramfb",
|
||||
.version_id = 2,
|
||||
.minimum_version_id = 2,
|
||||
.fields = (VMStateField[]) {
|
||||
/* no pci stuff here, saving the virtio device will handle that */
|
||||
/* FIXME */
|
||||
VMSTATE_END_OF_LIST()
|
||||
}
|
||||
};
|
||||
|
||||
/* RAMFB device wrapper around PCI device around virtio GPU */
|
||||
static void virtio_ramfb_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
|
||||
{
|
||||
VirtIORAMFBBase *vramfb = VIRTIO_RAMFB_BASE(vpci_dev);
|
||||
VirtIOGPUBase *g = vramfb->vgpu;
|
||||
int i;
|
||||
|
||||
/* init virtio bits */
|
||||
virtio_pci_force_virtio_1(vpci_dev);
|
||||
if (!qdev_realize(DEVICE(g), BUS(&vpci_dev->bus), errp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* init ramfb */
|
||||
vramfb->ramfb = ramfb_setup(errp);
|
||||
graphic_console_set_hwops(g->scanout[0].con, &virtio_ramfb_ops, vramfb);
|
||||
|
||||
for (i = 0; i < g->conf.max_outputs; i++) {
|
||||
object_property_set_link(OBJECT(g->scanout[i].con), "device",
|
||||
OBJECT(vpci_dev), &error_abort);
|
||||
}
|
||||
}
|
||||
|
||||
static void virtio_ramfb_reset(DeviceState *dev)
|
||||
{
|
||||
VirtIORAMFBBaseClass *klass = VIRTIO_RAMFB_BASE_GET_CLASS(dev);
|
||||
|
||||
/* reset virtio-gpu */
|
||||
klass->parent_reset(dev);
|
||||
}
|
||||
|
||||
static Property virtio_ramfb_base_properties[] = {
|
||||
DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
|
||||
DEFINE_PROP_END_OF_LIST(),
|
||||
};
|
||||
|
||||
static void virtio_ramfb_base_class_init(ObjectClass *klass, void *data)
|
||||
{
|
||||
DeviceClass *dc = DEVICE_CLASS(klass);
|
||||
VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
|
||||
VirtIORAMFBBaseClass *v = VIRTIO_RAMFB_BASE_CLASS(klass);
|
||||
PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
|
||||
|
||||
set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
|
||||
device_class_set_props(dc, virtio_ramfb_base_properties);
|
||||
dc->vmsd = &vmstate_virtio_ramfb;
|
||||
dc->hotpluggable = false;
|
||||
device_class_set_parent_reset(dc, virtio_ramfb_reset,
|
||||
&v->parent_reset);
|
||||
|
||||
k->realize = virtio_ramfb_realize;
|
||||
pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER;
|
||||
}
|
||||
|
||||
static TypeInfo virtio_ramfb_base_info = {
|
||||
.name = TYPE_VIRTIO_RAMFB_BASE,
|
||||
.parent = TYPE_VIRTIO_PCI,
|
||||
.instance_size = sizeof(VirtIORAMFBBase),
|
||||
.class_size = sizeof(VirtIORAMFBBaseClass),
|
||||
.class_init = virtio_ramfb_base_class_init,
|
||||
.abstract = true,
|
||||
};
|
||||
|
||||
#define TYPE_VIRTIO_RAMFB "virtio-ramfb"
|
||||
|
||||
typedef struct VirtIORAMFB VirtIORAMFB;
|
||||
DECLARE_INSTANCE_CHECKER(VirtIORAMFB, VIRTIO_RAMFB,
|
||||
TYPE_VIRTIO_RAMFB)
|
||||
|
||||
struct VirtIORAMFB {
|
||||
VirtIORAMFBBase parent_obj;
|
||||
|
||||
VirtIOGPU vdev;
|
||||
};
|
||||
|
||||
static void virtio_ramfb_inst_initfn(Object *obj)
|
||||
{
|
||||
VirtIORAMFB *dev = VIRTIO_RAMFB(obj);
|
||||
|
||||
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
||||
TYPE_VIRTIO_GPU);
|
||||
VIRTIO_RAMFB_BASE(dev)->vgpu = VIRTIO_GPU_BASE(&dev->vdev);
|
||||
}
|
||||
|
||||
static VirtioPCIDeviceTypeInfo virtio_ramfb_info = {
|
||||
.generic_name = TYPE_VIRTIO_RAMFB,
|
||||
.parent = TYPE_VIRTIO_RAMFB_BASE,
|
||||
.instance_size = sizeof(VirtIORAMFB),
|
||||
.instance_init = virtio_ramfb_inst_initfn,
|
||||
};
|
||||
|
||||
static void virtio_ramfb_register_types(void)
|
||||
{
|
||||
type_register_static(&virtio_ramfb_base_info);
|
||||
virtio_pci_types_register(&virtio_ramfb_info);
|
||||
}
|
||||
|
||||
type_init(virtio_ramfb_register_types)
|
||||
@@ -358,7 +358,7 @@ typedef struct disassemble_info {
|
||||
(bfd_vma addr, struct disassemble_info * info);
|
||||
|
||||
/* These are for buffer_read_memory. */
|
||||
bfd_byte *buffer;
|
||||
const bfd_byte *buffer;
|
||||
bfd_vma buffer_vma;
|
||||
int buffer_length;
|
||||
|
||||
@@ -462,7 +462,7 @@ int print_insn_rx(bfd_vma, disassemble_info *);
|
||||
|
||||
#ifdef CONFIG_CAPSTONE
|
||||
bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size);
|
||||
bool cap_disas_host(disassemble_info *info, void *code, size_t size);
|
||||
bool cap_disas_host(disassemble_info *info, const void *code, size_t size);
|
||||
bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count);
|
||||
bool cap_disas_plugin(disassemble_info *info, uint64_t pc, size_t size);
|
||||
#else
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "cpu.h"
|
||||
|
||||
/* Disassemble this for me please... (debugging). */
|
||||
void disas(FILE *out, void *code, unsigned long size);
|
||||
void disas(FILE *out, const void *code, unsigned long size);
|
||||
void target_disas(FILE *out, CPUState *cpu, target_ulong code,
|
||||
target_ulong size);
|
||||
|
||||
|
||||
@@ -448,7 +448,7 @@ int probe_access_flags(CPUArchState *env, target_ulong addr,
|
||||
* Note: the address of search data can be obtained by adding @size to @ptr.
|
||||
*/
|
||||
struct tb_tc {
|
||||
void *ptr; /* pointer to the translated code */
|
||||
const void *ptr; /* pointer to the translated code */
|
||||
size_t size;
|
||||
};
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ static inline void gen_io_end(void)
|
||||
tcg_temp_free_i32(tmp);
|
||||
}
|
||||
|
||||
static inline void gen_tb_start(TranslationBlock *tb)
|
||||
static inline void gen_tb_start(const TranslationBlock *tb)
|
||||
{
|
||||
TCGv_i32 count, imm;
|
||||
|
||||
@@ -71,7 +71,7 @@ static inline void gen_tb_start(TranslationBlock *tb)
|
||||
tcg_temp_free_i32(count);
|
||||
}
|
||||
|
||||
static inline void gen_tb_end(TranslationBlock *tb, int num_insns)
|
||||
static inline void gen_tb_end(const TranslationBlock *tb, int num_insns)
|
||||
{
|
||||
if (tb_cflags(tb) & CF_USE_ICOUNT) {
|
||||
/* Update the num_insn immediate parameter now that we know
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ static inline void log_target_disas(CPUState *cpu, target_ulong start,
|
||||
rcu_read_unlock();
|
||||
}
|
||||
|
||||
static inline void log_disas(void *code, unsigned long size)
|
||||
static inline void log_disas(const void *code, unsigned long size)
|
||||
{
|
||||
QemuLogFile *logfile;
|
||||
rcu_read_lock();
|
||||
|
||||
@@ -67,7 +67,7 @@ typedef enum DisasJumpType {
|
||||
* Architecture-agnostic disassembly context.
|
||||
*/
|
||||
typedef struct DisasContextBase {
|
||||
TranslationBlock *tb;
|
||||
const TranslationBlock *tb;
|
||||
target_ulong pc_first;
|
||||
target_ulong pc_next;
|
||||
DisasJumpType is_jmp;
|
||||
|
||||
@@ -189,7 +189,8 @@ struct CPUClass {
|
||||
void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
|
||||
Error **errp);
|
||||
void (*set_pc)(CPUState *cpu, vaddr value);
|
||||
void (*synchronize_from_tb)(CPUState *cpu, struct TranslationBlock *tb);
|
||||
void (*synchronize_from_tb)(CPUState *cpu,
|
||||
const struct TranslationBlock *tb);
|
||||
bool (*tlb_fill)(CPUState *cpu, vaddr address, int size,
|
||||
MMUAccessType access_type, int mmu_idx,
|
||||
bool probe, uintptr_t retaddr);
|
||||
@@ -280,6 +281,7 @@ struct KVMState;
|
||||
struct kvm_run;
|
||||
|
||||
struct hax_vcpu_state;
|
||||
struct hvf_vcpu_state;
|
||||
|
||||
#define TB_JMP_CACHE_BITS 12
|
||||
#define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
|
||||
@@ -463,7 +465,7 @@ struct CPUState {
|
||||
|
||||
struct hax_vcpu_state *hax_vcpu;
|
||||
|
||||
int hvf_fd;
|
||||
struct hvf_vcpu_state *hvf;
|
||||
|
||||
/* track IOMMUs whose translations we've cached in the TCG TLB */
|
||||
GArray *iommu_notifiers;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Flush the host cpu caches.
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
#ifndef QEMU_CACHEFLUSH_H
|
||||
#define QEMU_CACHEFLUSH_H
|
||||
|
||||
/**
|
||||
* flush_idcache_range:
|
||||
* @rx: instruction address
|
||||
* @rw: data address
|
||||
* @len: length to flush
|
||||
*
|
||||
* Flush @len bytes of the data cache at @rw and the icache at @rx
|
||||
* to bring them in sync. The two addresses may be different virtual
|
||||
* mappings of the same physical page(s).
|
||||
*/
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__) || defined(__s390__)
|
||||
|
||||
static inline void flush_idcache_range(uintptr_t rx, uintptr_t rw, size_t len)
|
||||
{
|
||||
/* icache is coherent and does not require flushing. */
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void flush_idcache_range(uintptr_t rx, uintptr_t rw, size_t len);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* QEMU_CACHEFLUSH_H */
|
||||
@@ -686,4 +686,18 @@ char *qemu_get_host_name(Error **errp);
|
||||
*/
|
||||
size_t qemu_get_host_physmem(void);
|
||||
|
||||
/**
|
||||
* iOS does not support system() so we replace it with an assertion failure.
|
||||
*/
|
||||
#ifdef CONFIG_IOS
|
||||
#define system ios_does_not_support_system
|
||||
static inline int ios_does_not_support_system(const char *command)
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
#endif /* CONFIG_IOS */
|
||||
|
||||
void qemu_thread_jit_write(void);
|
||||
void qemu_thread_jit_execute(void);
|
||||
|
||||
#endif
|
||||
@@ -19,6 +19,8 @@
|
||||
#ifdef CONFIG_HVF
|
||||
uint32_t hvf_get_supported_cpuid(uint32_t func, uint32_t idx,
|
||||
int reg);
|
||||
struct ARMCPU;
|
||||
void hvf_arm_set_cpu_features_from_host(struct ARMCPU *cpu);
|
||||
extern bool hvf_allowed;
|
||||
#define hvf_enabled() (hvf_allowed)
|
||||
#else /* !CONFIG_HVF */
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* QEMU Hypervisor.framework (HVF) support
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
/* header to be included in HVF-specific code */
|
||||
|
||||
#ifndef HVF_INT_H
|
||||
#define HVF_INT_H
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#ifdef __aarch64__
|
||||
#include <Hypervisor/Hypervisor.h>
|
||||
#else
|
||||
#include <Hypervisor/hv.h>
|
||||
#endif
|
||||
|
||||
/* hvf_slot flags */
|
||||
#define HVF_SLOT_LOG (1 << 0)
|
||||
|
||||
typedef struct hvf_slot {
|
||||
uint64_t start;
|
||||
uint64_t size;
|
||||
uint8_t *mem;
|
||||
int slot_id;
|
||||
uint32_t flags;
|
||||
MemoryRegion *region;
|
||||
} hvf_slot;
|
||||
|
||||
typedef struct hvf_vcpu_caps {
|
||||
uint64_t vmx_cap_pinbased;
|
||||
uint64_t vmx_cap_procbased;
|
||||
uint64_t vmx_cap_procbased2;
|
||||
uint64_t vmx_cap_entry;
|
||||
uint64_t vmx_cap_exit;
|
||||
uint64_t vmx_cap_preemption_timer;
|
||||
} hvf_vcpu_caps;
|
||||
|
||||
struct HVFState {
|
||||
AccelState parent;
|
||||
hvf_slot slots[32];
|
||||
int num_slots;
|
||||
|
||||
hvf_vcpu_caps *hvf_caps;
|
||||
};
|
||||
extern HVFState *hvf_state;
|
||||
|
||||
struct hvf_vcpu_state {
|
||||
uint64_t fd;
|
||||
void *exit;
|
||||
sigset_t unblock_ipi_mask;
|
||||
};
|
||||
|
||||
void assert_hvf_ok(hv_return_t ret);
|
||||
int hvf_get_registers(CPUState *cpu);
|
||||
int hvf_put_registers(CPUState *cpu);
|
||||
int hvf_arch_init_vcpu(CPUState *cpu);
|
||||
void hvf_arch_vcpu_destroy(CPUState *cpu);
|
||||
int hvf_vcpu_exec(CPUState *cpu);
|
||||
hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t);
|
||||
void hvf_kick_vcpu_thread(CPUState *cpu);
|
||||
|
||||
#endif
|
||||
@@ -8,7 +8,8 @@
|
||||
#ifndef SYSEMU_TCG_H
|
||||
#define SYSEMU_TCG_H
|
||||
|
||||
void tcg_exec_init(unsigned long tb_size);
|
||||
void tcg_exec_init(unsigned long tb_size, int splitwx);
|
||||
|
||||
#ifdef CONFIG_TCG
|
||||
extern bool tcg_allowed;
|
||||
#define tcg_enabled() (tcg_allowed)
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Apple Silicon functions for JIT handling
|
||||
*
|
||||
* Copyright (c) 2020 osy
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TCG_APPLE_JIT_H
|
||||
#define TCG_APPLE_JIT_H
|
||||
|
||||
/*
|
||||
* APRR handling
|
||||
* Credits to: https://siguza.github.io/APRR/
|
||||
* Reversed from /usr/lib/system/libsystem_pthread.dylib
|
||||
*/
|
||||
|
||||
#if defined(__aarch64__) && defined(CONFIG_DARWIN)
|
||||
|
||||
#define _COMM_PAGE_START_ADDRESS (0x0000000FFFFFC000ULL) /* In TTBR0 */
|
||||
#define _COMM_PAGE_APRR_SUPPORT (_COMM_PAGE_START_ADDRESS + 0x10C)
|
||||
#define _COMM_PAGE_APPR_WRITE_ENABLE (_COMM_PAGE_START_ADDRESS + 0x110)
|
||||
#define _COMM_PAGE_APRR_WRITE_DISABLE (_COMM_PAGE_START_ADDRESS + 0x118)
|
||||
|
||||
static __attribute__((__always_inline__)) bool jit_write_protect_supported(void)
|
||||
{
|
||||
/* Access shared kernel page at fixed memory location. */
|
||||
uint8_t aprr_support = *(volatile uint8_t *)_COMM_PAGE_APRR_SUPPORT;
|
||||
return aprr_support > 0;
|
||||
}
|
||||
|
||||
/* write protect enable = write disable */
|
||||
static __attribute__((__always_inline__)) void jit_write_protect(int enabled)
|
||||
{
|
||||
/* Access shared kernel page at fixed memory location. */
|
||||
uint8_t aprr_support = *(volatile uint8_t *)_COMM_PAGE_APRR_SUPPORT;
|
||||
if (aprr_support == 0 || aprr_support > 3) {
|
||||
return;
|
||||
} else if (aprr_support == 1) {
|
||||
__asm__ __volatile__ (
|
||||
"mov x0, %0\n"
|
||||
"ldr x0, [x0]\n"
|
||||
"msr S3_4_c15_c2_7, x0\n"
|
||||
"isb sy\n"
|
||||
:: "r" (enabled ? _COMM_PAGE_APRR_WRITE_DISABLE
|
||||
: _COMM_PAGE_APPR_WRITE_ENABLE)
|
||||
: "memory", "x0"
|
||||
);
|
||||
} else {
|
||||
__asm__ __volatile__ (
|
||||
"mov x0, %0\n"
|
||||
"ldr x0, [x0]\n"
|
||||
"msr S3_6_c15_c1_5, x0\n"
|
||||
"isb sy\n"
|
||||
:: "r" (enabled ? _COMM_PAGE_APRR_WRITE_DISABLE
|
||||
: _COMM_PAGE_APPR_WRITE_ENABLE)
|
||||
: "memory", "x0"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#else /* defined(__aarch64__) && defined(CONFIG_DARWIN) */
|
||||
|
||||
static __attribute__((__always_inline__)) bool jit_write_protect_supported(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static __attribute__((__always_inline__)) void jit_write_protect(int enabled)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* define TCG_APPLE_JIT_H */
|
||||
@@ -805,7 +805,7 @@ static inline void tcg_gen_insn_start(target_ulong pc, target_ulong a1,
|
||||
* be NULL and @idx should be 0. Otherwise, @tb should be valid and
|
||||
* @idx should be one of the TB_EXIT_ values.
|
||||
*/
|
||||
void tcg_gen_exit_tb(TranslationBlock *tb, unsigned idx);
|
||||
void tcg_gen_exit_tb(const TranslationBlock *tb, unsigned idx);
|
||||
|
||||
/**
|
||||
* tcg_gen_goto_tb() - output goto_tb TCG operation
|
||||
|
||||
+45
-11
@@ -261,7 +261,7 @@ struct TCGLabel {
|
||||
unsigned refs : 16;
|
||||
union {
|
||||
uintptr_t value;
|
||||
tcg_insn_unit *value_ptr;
|
||||
const tcg_insn_unit *value_ptr;
|
||||
} u;
|
||||
QSIMPLEQ_HEAD(, TCGRelocation) relocs;
|
||||
QSIMPLEQ_ENTRY(TCGLabel) next;
|
||||
@@ -621,8 +621,6 @@ struct TCGContext {
|
||||
here, because there's too much arithmetic throughout that relies
|
||||
on addition and subtraction working on bytes. Rely on the GCC
|
||||
extension that allows arithmetic on void*. */
|
||||
void *code_gen_prologue;
|
||||
void *code_gen_epilogue;
|
||||
void *code_gen_buffer;
|
||||
size_t code_gen_buffer_size;
|
||||
void *code_gen_ptr;
|
||||
@@ -679,8 +677,31 @@ struct TCGContext {
|
||||
|
||||
extern TCGContext tcg_init_ctx;
|
||||
extern __thread TCGContext *tcg_ctx;
|
||||
extern const void *tcg_code_gen_epilogue;
|
||||
extern uintptr_t tcg_splitwx_diff;
|
||||
extern TCGv_env cpu_env;
|
||||
|
||||
static inline bool in_code_gen_buffer(const void *p)
|
||||
{
|
||||
const TCGContext *s = &tcg_init_ctx;
|
||||
return (size_t)(p - s->code_gen_buffer) <= s->code_gen_buffer_size;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DEBUG_TCG
|
||||
const void *tcg_splitwx_to_rx(void *rw);
|
||||
void *tcg_splitwx_to_rw(const void *rx);
|
||||
#else
|
||||
static inline const void *tcg_splitwx_to_rx(void *rw)
|
||||
{
|
||||
return rw ? rw + tcg_splitwx_diff : NULL;
|
||||
}
|
||||
|
||||
static inline void *tcg_splitwx_to_rw(const void *rx)
|
||||
{
|
||||
return rx ? (void *)rx - tcg_splitwx_diff : NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline size_t temp_idx(TCGTemp *ts)
|
||||
{
|
||||
ptrdiff_t n = ts - tcg_ctx->temps;
|
||||
@@ -1101,7 +1122,7 @@ static inline TCGLabel *arg_label(TCGArg i)
|
||||
* correct result.
|
||||
*/
|
||||
|
||||
static inline ptrdiff_t tcg_ptr_byte_diff(void *a, void *b)
|
||||
static inline ptrdiff_t tcg_ptr_byte_diff(const void *a, const void *b)
|
||||
{
|
||||
return a - b;
|
||||
}
|
||||
@@ -1115,9 +1136,22 @@ static inline ptrdiff_t tcg_ptr_byte_diff(void *a, void *b)
|
||||
* to the destination address.
|
||||
*/
|
||||
|
||||
static inline ptrdiff_t tcg_pcrel_diff(TCGContext *s, void *target)
|
||||
static inline ptrdiff_t tcg_pcrel_diff(TCGContext *s, const void *target)
|
||||
{
|
||||
return tcg_ptr_byte_diff(target, s->code_ptr);
|
||||
return tcg_ptr_byte_diff(target, tcg_splitwx_to_rx(s->code_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* tcg_tbrel_diff
|
||||
* @s: the tcg context
|
||||
* @target: address of the target
|
||||
*
|
||||
* Produce a difference, from the beginning of the current TB code
|
||||
* to the destination address.
|
||||
*/
|
||||
static inline ptrdiff_t tcg_tbrel_diff(TCGContext *s, const void *target)
|
||||
{
|
||||
return tcg_ptr_byte_diff(target, tcg_splitwx_to_rx(s->code_buf));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1222,14 +1256,14 @@ static inline unsigned get_mmuidx(TCGMemOpIdx oi)
|
||||
#define TB_EXIT_IDXMAX 1
|
||||
#define TB_EXIT_REQUESTED 3
|
||||
|
||||
#ifdef HAVE_TCG_QEMU_TB_EXEC
|
||||
uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t *tb_ptr);
|
||||
#ifdef CONFIG_TCG_INTERPRETER
|
||||
uintptr_t tcg_qemu_tb_exec(CPUArchState *env, const void *tb_ptr);
|
||||
#else
|
||||
# define tcg_qemu_tb_exec(env, tb_ptr) \
|
||||
((uintptr_t (*)(void *, void *))tcg_ctx->code_gen_prologue)(env, tb_ptr)
|
||||
typedef uintptr_t tcg_prologue_fn(CPUArchState *env, const void *tb_ptr);
|
||||
extern tcg_prologue_fn *tcg_qemu_tb_exec;
|
||||
#endif
|
||||
|
||||
void tcg_register_jit(void *buf, size_t buf_size);
|
||||
void tcg_register_jit(const void *buf, size_t buf_size);
|
||||
|
||||
#if TCG_TARGET_MAYBE_vec
|
||||
/* Return zero if the tuple (opc, type, vece) is unsupportable;
|
||||
|
||||
+1
-1
@@ -703,7 +703,7 @@ int main(int argc, char **argv, char **envp)
|
||||
cpu_type = parse_cpu_option(cpu_model);
|
||||
|
||||
/* init tcg before creating CPUs and to get qemu_host_page_size */
|
||||
tcg_exec_init(0);
|
||||
tcg_exec_init(0, false);
|
||||
|
||||
cpu = cpu_create(cpu_type);
|
||||
env = cpu->env_ptr;
|
||||
|
||||
+58
-9
@@ -74,16 +74,25 @@ else
|
||||
endif
|
||||
|
||||
accelerator_targets = { 'CONFIG_KVM': kvm_targets }
|
||||
|
||||
if cpu in ['x86', 'x86_64']
|
||||
hvf_targets = ['x86_64-softmmu']
|
||||
elif cpu in ['aarch64']
|
||||
hvf_targets = ['aarch64-softmmu']
|
||||
else
|
||||
hvf_targets = []
|
||||
endif
|
||||
|
||||
if cpu in ['x86', 'x86_64', 'arm', 'aarch64']
|
||||
# i368 emulator provides xenpv machine type for multiple architectures
|
||||
accelerator_targets += {
|
||||
'CONFIG_XEN': ['i386-softmmu', 'x86_64-softmmu'],
|
||||
'CONFIG_HVF': hvf_targets,
|
||||
}
|
||||
endif
|
||||
if cpu in ['x86', 'x86_64']
|
||||
accelerator_targets += {
|
||||
'CONFIG_HAX': ['i386-softmmu', 'x86_64-softmmu'],
|
||||
'CONFIG_HVF': ['x86_64-softmmu'],
|
||||
'CONFIG_WHPX': ['i386-softmmu', 'x86_64-softmmu'],
|
||||
}
|
||||
endif
|
||||
@@ -181,7 +190,7 @@ if targetos == 'windows'
|
||||
include_directories: include_directories('.'))
|
||||
elif targetos == 'darwin'
|
||||
coref = dependency('appleframeworks', modules: 'CoreFoundation')
|
||||
iokit = dependency('appleframeworks', modules: 'IOKit')
|
||||
iokit = dependency('appleframeworks', modules: 'IOKit', required: 'CONFIG_IOS' not in config_host)
|
||||
cocoa = dependency('appleframeworks', modules: 'Cocoa', required: get_option('cocoa'))
|
||||
elif targetos == 'sunos'
|
||||
socket = [cc.find_library('socket'),
|
||||
@@ -1205,6 +1214,8 @@ if have_system
|
||||
slirp_deps = []
|
||||
if targetos == 'windows'
|
||||
slirp_deps = cc.find_library('iphlpapi')
|
||||
elif targetos == 'darwin'
|
||||
slirp_deps = cc.find_library('resolv')
|
||||
endif
|
||||
slirp_conf = configuration_data()
|
||||
slirp_conf.set('SLIRP_MAJOR_VERSION', meson.project_version().split('.')[0])
|
||||
@@ -1308,9 +1319,17 @@ if not fdt.found() and fdt_required.length() > 0
|
||||
error('fdt not available but required by targets ' + ', '.join(fdt_required))
|
||||
endif
|
||||
|
||||
ucontext = dependency('libucontext', required : false)
|
||||
if not ucontext.found() and get_option('ucontext').enabled()
|
||||
libucontext_proj = subproject('libucontext',
|
||||
default_options: ['freestanding=true'])
|
||||
ucontext = libucontext_proj.get_variable('libucontext_dep')
|
||||
endif
|
||||
|
||||
config_host_data.set('CONFIG_CAPSTONE', capstone.found())
|
||||
config_host_data.set('CONFIG_FDT', fdt.found())
|
||||
config_host_data.set('CONFIG_SLIRP', slirp.found())
|
||||
config_host_data.set('CONFIG_LIBUCONTEXT', ucontext.found())
|
||||
|
||||
#####################
|
||||
# Generated sources #
|
||||
@@ -1528,7 +1547,7 @@ util_ss.add_all(trace_ss)
|
||||
util_ss = util_ss.apply(config_all, strict: false)
|
||||
libqemuutil = static_library('qemuutil',
|
||||
sources: util_ss.sources() + stub_ss.sources() + genh,
|
||||
dependencies: [util_ss.dependencies(), m, glib, socket, malloc])
|
||||
dependencies: [util_ss.dependencies(), m, glib, socket, malloc, ucontext])
|
||||
qemuutil = declare_dependency(link_with: libqemuutil,
|
||||
sources: genh + version_res)
|
||||
|
||||
@@ -1831,14 +1850,31 @@ foreach target : target_dirs
|
||||
arch_srcs += target_specific.sources()
|
||||
arch_deps += target_specific.dependencies()
|
||||
|
||||
lib = static_library('qemu-' + target,
|
||||
if get_option('shared-lib')
|
||||
build_lib_args = {
|
||||
'target_type': 'shared_library',
|
||||
'install': true,
|
||||
'dependencies': arch_deps + deps,
|
||||
'link_language': link_language,
|
||||
'link_depends': [block_syms, qemu_syms],
|
||||
'link_args': link_args + cc.get_supported_link_arguments(['-Wl,-U,_qemu_main'])
|
||||
}
|
||||
else
|
||||
build_lib_args = {
|
||||
'target_type': 'static_library',
|
||||
'install': false,
|
||||
'dependencies': arch_deps,
|
||||
'name_suffix': 'fa'
|
||||
}
|
||||
endif
|
||||
|
||||
lib = build_target('qemu-' + target,
|
||||
sources: arch_srcs + genh,
|
||||
dependencies: arch_deps,
|
||||
objects: objects,
|
||||
include_directories: target_inc,
|
||||
c_args: c_args,
|
||||
build_by_default: false,
|
||||
name_suffix: 'fa')
|
||||
kwargs: build_lib_args)
|
||||
|
||||
if target.endswith('-softmmu')
|
||||
execs = [{
|
||||
@@ -1872,17 +1908,27 @@ foreach target : target_dirs
|
||||
'dependencies': []
|
||||
}]
|
||||
endif
|
||||
if get_option('shared-lib')
|
||||
build_exe_args = {
|
||||
'link_with': lib,
|
||||
'link_args': link_args + cc.get_supported_link_arguments(['-Wl,--exclude-libs,ALL'])
|
||||
}
|
||||
else
|
||||
build_exe_args = {
|
||||
'objects': lib.extract_all_objects(recursive: true),
|
||||
'link_args': link_args
|
||||
}
|
||||
endif
|
||||
foreach exe: execs
|
||||
emulators += {exe['name']:
|
||||
executable(exe['name'], exe['sources'],
|
||||
install: true,
|
||||
c_args: c_args,
|
||||
dependencies: arch_deps + deps + exe['dependencies'],
|
||||
objects: lib.extract_all_objects(recursive: true),
|
||||
link_language: link_language,
|
||||
link_depends: [block_syms, qemu_syms] + exe.get('link_depends', []),
|
||||
link_args: link_args,
|
||||
gui_app: exe['gui'])
|
||||
gui_app: exe['gui'],
|
||||
kwargs: build_exe_args)
|
||||
}
|
||||
|
||||
if 'CONFIG_TRACE_SYSTEMTAP' in config_host
|
||||
@@ -2027,6 +2073,7 @@ endif
|
||||
summary_info += {'Doc directory': get_option('docdir')}
|
||||
summary_info += {'Build directory': meson.current_build_dir()}
|
||||
summary_info += {'Source path': meson.current_source_dir()}
|
||||
summary_info += {'build shared lib': get_option('shared-lib')}
|
||||
summary_info += {'GIT binary': config_host['GIT']}
|
||||
summary_info += {'GIT submodules': config_host['GIT_SUBMODULES']}
|
||||
summary_info += {'C compiler': meson.get_compiler('c').cmd_array()[0]}
|
||||
@@ -2188,6 +2235,7 @@ if targetos == 'windows'
|
||||
summary_info += {'QGA MSI support': config_host.has_key('CONFIG_QGA_MSI')}
|
||||
endif
|
||||
summary_info += {'seccomp support': config_host.has_key('CONFIG_SECCOMP')}
|
||||
summary_info += {'libucontext support': ucontext.found()}
|
||||
summary_info += {'coroutine backend': config_host['CONFIG_COROUTINE_BACKEND']}
|
||||
summary_info += {'coroutine pool': config_host['CONFIG_COROUTINE_POOL'] == '1'}
|
||||
summary_info += {'debug stack usage': config_host.has_key('CONFIG_DEBUG_STACK_USAGE')}
|
||||
@@ -2219,6 +2267,7 @@ summary_info += {'vvfat support': config_host.has_key('CONFIG_VVFAT')}
|
||||
summary_info += {'qed support': config_host.has_key('CONFIG_QED')}
|
||||
summary_info += {'parallels support': config_host.has_key('CONFIG_PARALLELS')}
|
||||
summary_info += {'sheepdog support': config_host.has_key('CONFIG_SHEEPDOG')}
|
||||
summary_info += {'host block dev support': config_host.has_key('CONFIG_HOST_BLOCK_DEVICE')}
|
||||
summary_info += {'capstone': capstone_opt == 'disabled' ? false : capstone_opt}
|
||||
summary_info += {'libpmem support': config_host.has_key('CONFIG_LIBPMEM')}
|
||||
summary_info += {'libdaxctl support': config_host.has_key('CONFIG_LIBDAXCTL')}
|
||||
|
||||
@@ -6,6 +6,8 @@ option('qemu_firmwarepath', type : 'string', value : '',
|
||||
description: 'search PATH for firmware files')
|
||||
option('sphinx_build', type : 'string', value : '',
|
||||
description: 'Use specified sphinx-build [$sphinx_build] for building document (default to be empty)')
|
||||
option('shared-lib', type : 'boolean', value : false,
|
||||
description: 'build QEMU as a shared library')
|
||||
|
||||
option('docs', type : 'feature', value : 'auto',
|
||||
description: 'Documentations build support')
|
||||
@@ -70,6 +72,8 @@ option('fuse', type: 'feature', value: 'auto',
|
||||
description: 'FUSE block device export')
|
||||
option('fuse_lseek', type : 'feature', value : 'auto',
|
||||
description: 'SEEK_HOLE/SEEK_DATA support for FUSE exports')
|
||||
option('ucontext', type : 'feature', value : 'disabled',
|
||||
description: 'libucontext support')
|
||||
|
||||
option('capstone', type: 'combo', value: 'auto',
|
||||
choices: ['disabled', 'enabled', 'auto', 'system', 'internal'],
|
||||
|
||||
+8
-8
@@ -27,7 +27,7 @@
|
||||
#include "net/slirp.h"
|
||||
|
||||
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(CONFIG_IOS)
|
||||
#include <pwd.h>
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
@@ -90,7 +90,7 @@ typedef struct SlirpState {
|
||||
Slirp *slirp;
|
||||
Notifier poll_notifier;
|
||||
Notifier exit_notifier;
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(CONFIG_IOS)
|
||||
gchar *smb_dir;
|
||||
#endif
|
||||
GSList *fwd;
|
||||
@@ -103,7 +103,7 @@ static QTAILQ_HEAD(, SlirpState) slirp_stacks =
|
||||
static int slirp_hostfwd(SlirpState *s, const char *redir_str, Error **errp);
|
||||
static int slirp_guestfwd(SlirpState *s, const char *config_str, Error **errp);
|
||||
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(CONFIG_IOS)
|
||||
static int slirp_smb(SlirpState *s, const char *exported_dir,
|
||||
struct in_addr vserver_addr, Error **errp);
|
||||
static void slirp_smb_cleanup(SlirpState *s);
|
||||
@@ -368,7 +368,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,
|
||||
struct in6_addr ip6_prefix;
|
||||
struct in6_addr ip6_host;
|
||||
struct in6_addr ip6_dns;
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(CONFIG_IOS)
|
||||
struct in_addr smbsrv = { .s_addr = 0 };
|
||||
#endif
|
||||
NetClientState *nc;
|
||||
@@ -478,7 +478,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(CONFIG_IOS)
|
||||
if (vsmbserver && !inet_aton(vsmbserver, &smbsrv)) {
|
||||
error_setg(errp, "Failed to parse SMB address");
|
||||
return -1;
|
||||
@@ -593,7 +593,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(CONFIG_IOS)
|
||||
if (smb_export) {
|
||||
if (slirp_smb(s, smb_export, smbsrv, errp) < 0) {
|
||||
goto error;
|
||||
@@ -785,7 +785,7 @@ void hmp_hostfwd_add(Monitor *mon, const QDict *qdict)
|
||||
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(CONFIG_IOS)
|
||||
|
||||
/* automatic user mode samba server configuration */
|
||||
static void slirp_smb_cleanup(SlirpState *s)
|
||||
@@ -900,7 +900,7 @@ static int slirp_smb(SlirpState* s, const char *exported_dir,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* !defined(_WIN32) */
|
||||
#endif /* !defined(_WIN32) && !defined(CONFIG_IOS) */
|
||||
|
||||
static int guestfwd_can_read(void *opaque)
|
||||
{
|
||||
|
||||
@@ -959,7 +959,8 @@
|
||||
'discriminator': 'driver',
|
||||
'data': {
|
||||
'file': 'BlockStatsSpecificFile',
|
||||
'host_device': 'BlockStatsSpecificFile',
|
||||
'host_device': { 'type': 'BlockStatsSpecificFile',
|
||||
'if': 'defined(CONFIG_HOST_BLOCK_DEVICE)' },
|
||||
'nvme': 'BlockStatsSpecificNvme' } }
|
||||
|
||||
##
|
||||
@@ -2827,7 +2828,9 @@
|
||||
{ 'enum': 'BlockdevDriver',
|
||||
'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs',
|
||||
'cloop', 'compress', 'copy-on-read', 'dmg', 'file', 'ftp', 'ftps',
|
||||
'gluster', 'host_cdrom', 'host_device', 'http', 'https', 'iscsi',
|
||||
'gluster', 'host_cdrom',
|
||||
{'name': 'host_device', 'if': 'defined(CONFIG_HOST_BLOCK_DEVICE)' },
|
||||
'http', 'https', 'iscsi',
|
||||
'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels',
|
||||
'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd',
|
||||
{ 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' },
|
||||
@@ -3995,7 +3998,8 @@
|
||||
'ftps': 'BlockdevOptionsCurlFtps',
|
||||
'gluster': 'BlockdevOptionsGluster',
|
||||
'host_cdrom': 'BlockdevOptionsFile',
|
||||
'host_device':'BlockdevOptionsFile',
|
||||
'host_device': { 'type': 'BlockdevOptionsFile',
|
||||
'if': 'defined(CONFIG_HOST_BLOCK_DEVICE)' },
|
||||
'http': 'BlockdevOptionsCurlHttp',
|
||||
'https': 'BlockdevOptionsCurlHttps',
|
||||
'iscsi': 'BlockdevOptionsIscsi',
|
||||
|
||||
@@ -34,6 +34,12 @@
|
||||
|
||||
#ifndef CONFIG_HAS_ENVIRON
|
||||
#ifdef __APPLE__
|
||||
#include "TargetConditionals.h"
|
||||
#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
|
||||
#define APPLE_USE_CRT_EXTERNS
|
||||
#endif
|
||||
#endif
|
||||
#ifdef APPLE_USE_CRT_EXTERNS
|
||||
#include <crt_externs.h>
|
||||
#define environ (*_NSGetEnviron())
|
||||
#else
|
||||
|
||||
+1
-1
Submodule slirp updated: 8f43a99191...92413be689.
@@ -26,6 +26,45 @@
|
||||
#include "qemu-common.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
|
||||
#ifdef CONFIG_DARWIN
|
||||
#include <pthread.h>
|
||||
#include <sys/event.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
const char __attribute__((section("__TEXT,__info_plist"))) info_plist[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
|
||||
"<plist version=\"1.0\">\n"
|
||||
"<dict>\n"
|
||||
" <key>CFBundleIdentifier</key>\n"
|
||||
" <string>org.qemu.QEMU</string>\n"
|
||||
"</dict>\n"
|
||||
"</plist>\n";
|
||||
|
||||
// http://mac-os-x.10953.n7.nabble.com/Ensure-NSTask-terminates-when-parent-application-does-td31477.html
|
||||
static void *WatchForParentTermination(void *args)
|
||||
{
|
||||
pid_t ppid = getppid(); // get parent pid
|
||||
|
||||
int kq = kqueue();
|
||||
if (kq != -1) {
|
||||
struct kevent procEvent; // wait for parent to exit
|
||||
EV_SET(&procEvent, // kevent
|
||||
ppid, // ident
|
||||
EVFILT_PROC, // filter
|
||||
EV_ADD, // flags
|
||||
NOTE_EXIT, // fflags
|
||||
0, // data
|
||||
0); // udata
|
||||
kevent(kq, &procEvent, 1, &procEvent, 1, NULL);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
return NULL;
|
||||
}
|
||||
#endif // CONFIG_DARWIN
|
||||
|
||||
#ifdef CONFIG_SDL
|
||||
#if defined(__APPLE__) || defined(main)
|
||||
#include <SDL.h>
|
||||
@@ -47,6 +86,11 @@ int main(int argc, char **argv)
|
||||
int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
qemu_init(argc, argv, envp);
|
||||
#ifdef CONFIG_DARWIN
|
||||
pthread_t thread;
|
||||
pthread_create(&thread, NULL, WatchForParentTermination, NULL);
|
||||
pthread_detach(thread);
|
||||
#endif
|
||||
qemu_main_loop();
|
||||
qemu_cleanup();
|
||||
|
||||
|
||||
+2
-1
@@ -22,6 +22,7 @@
|
||||
#include "qapi/error.h"
|
||||
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/cacheflush.h"
|
||||
#include "cpu.h"
|
||||
#include "exec/exec-all.h"
|
||||
#include "exec/target_page.h"
|
||||
@@ -2946,7 +2947,7 @@ static inline MemTxResult address_space_write_rom_internal(AddressSpace *as,
|
||||
invalidate_and_set_dirty(mr, addr1, l);
|
||||
break;
|
||||
case FLUSH_CACHE:
|
||||
flush_icache_range((uintptr_t)ram_ptr, (uintptr_t)ram_ptr + l);
|
||||
flush_idcache_range((uintptr_t)ram_ptr, (uintptr_t)ram_ptr, l);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Submodule
+1
Submodule subprojects/libucontext added at fc3b5e724e.
+10
-6
@@ -54,7 +54,8 @@ static void arm_cpu_set_pc(CPUState *cs, vaddr value)
|
||||
}
|
||||
}
|
||||
|
||||
static void arm_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
|
||||
static void arm_cpu_synchronize_from_tb(CPUState *cs,
|
||||
const TranslationBlock *tb)
|
||||
{
|
||||
ARMCPU *cpu = ARM_CPU(cs);
|
||||
CPUARMState *env = &cpu->env;
|
||||
@@ -1062,8 +1063,8 @@ static void arm_cpu_initfn(Object *obj)
|
||||
cpu->psci_version = 1; /* By default assume PSCI v0.1 */
|
||||
cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
|
||||
|
||||
if (tcg_enabled()) {
|
||||
cpu->psci_version = 2; /* TCG implements PSCI 0.2 */
|
||||
if (tcg_enabled() || hvf_enabled()) {
|
||||
cpu->psci_version = 2; /* TCG and HVF implement PSCI 0.2 */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2276,12 +2277,16 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef CONFIG_KVM
|
||||
#if defined(CONFIG_KVM) || defined(CONFIG_HVF)
|
||||
static void arm_host_initfn(Object *obj)
|
||||
{
|
||||
ARMCPU *cpu = ARM_CPU(obj);
|
||||
|
||||
#ifdef CONFIG_KVM
|
||||
kvm_arm_set_cpu_features_from_host(cpu);
|
||||
#else
|
||||
hvf_arm_set_cpu_features_from_host(cpu);
|
||||
#endif
|
||||
if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
|
||||
aarch64_add_sve_properties(obj);
|
||||
}
|
||||
@@ -2293,7 +2298,6 @@ static const TypeInfo host_arm_cpu_type_info = {
|
||||
.parent = TYPE_AARCH64_CPU,
|
||||
.instance_init = arm_host_initfn,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
static void arm_cpu_instance_init(Object *obj)
|
||||
@@ -2352,7 +2356,7 @@ static void arm_cpu_register_types(void)
|
||||
|
||||
type_register_static(&arm_cpu_type_info);
|
||||
|
||||
#ifdef CONFIG_KVM
|
||||
#if defined(CONFIG_KVM) || defined(CONFIG_HVF)
|
||||
type_register_static(&host_arm_cpu_type_info);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -2855,6 +2855,8 @@ bool write_cpustate_to_list(ARMCPU *cpu, bool kvm_sync);
|
||||
#define ARM_CPU_TYPE_NAME(name) (name ARM_CPU_TYPE_SUFFIX)
|
||||
#define CPU_RESOLVING_TYPE TYPE_ARM_CPU
|
||||
|
||||
#define TYPE_ARM_HOST_CPU "host-" TYPE_ARM_CPU
|
||||
|
||||
#define cpu_signal_handler cpu_arm_signal_handler
|
||||
#define cpu_list arm_cpu_list
|
||||
|
||||
|
||||
@@ -0,0 +1,856 @@
|
||||
/*
|
||||
* QEMU Hypervisor.framework support for Apple Silicon
|
||||
|
||||
* Copyright 2020 Alexander Graf <agraf@csgraf.de>
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu-common.h"
|
||||
#include "qemu/error-report.h"
|
||||
|
||||
#include "sysemu/runstate.h"
|
||||
#include "sysemu/hvf.h"
|
||||
#include "sysemu/hvf_int.h"
|
||||
#include "sysemu/hw_accel.h"
|
||||
|
||||
#include <mach/mach_time.h>
|
||||
|
||||
#include "exec/address-spaces.h"
|
||||
#include "hw/irq.h"
|
||||
#include "hw/intc/gicv3_internal.h"
|
||||
#include "qemu/main-loop.h"
|
||||
#include "sysemu/accel.h"
|
||||
#include "sysemu/cpus.h"
|
||||
#include "target/arm/cpu.h"
|
||||
#include "target/arm/internals.h"
|
||||
|
||||
#define HVF_DEBUG 0
|
||||
#define DPRINTF(...) \
|
||||
if (HVF_DEBUG) { \
|
||||
fprintf(stderr, "HVF %s:%d ", __func__, __LINE__); \
|
||||
fprintf(stderr, __VA_ARGS__); \
|
||||
fprintf(stderr, "\n"); \
|
||||
}
|
||||
|
||||
#define HVF_SYSREG(crn, crm, op0, op1, op2) \
|
||||
ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP, crn, crm, op0, op1, op2)
|
||||
#define PL1_WRITE_MASK 0x4
|
||||
|
||||
#define SYSREG(op0, op1, op2, crn, crm) \
|
||||
((op0 << 20) | (op2 << 17) | (op1 << 14) | (crn << 10) | (crm << 1))
|
||||
#define SYSREG_MASK SYSREG(0x3, 0x7, 0x7, 0xf, 0xf)
|
||||
#define SYSREG_CNTPCT_EL0 SYSREG(3, 3, 1, 14, 0)
|
||||
#define SYSREG_PMCCNTR_EL0 SYSREG(3, 3, 0, 9, 13)
|
||||
|
||||
#define SYSREG_ICC_AP0R0_EL1 SYSREG(3, 0, 4, 12, 8)
|
||||
#define SYSREG_ICC_AP0R1_EL1 SYSREG(3, 0, 5, 12, 8)
|
||||
#define SYSREG_ICC_AP0R2_EL1 SYSREG(3, 0, 6, 12, 8)
|
||||
#define SYSREG_ICC_AP0R3_EL1 SYSREG(3, 0, 7, 12, 8)
|
||||
#define SYSREG_ICC_AP1R0_EL1 SYSREG(3, 0, 0, 12, 9)
|
||||
#define SYSREG_ICC_AP1R1_EL1 SYSREG(3, 0, 1, 12, 9)
|
||||
#define SYSREG_ICC_AP1R2_EL1 SYSREG(3, 0, 2, 12, 9)
|
||||
#define SYSREG_ICC_AP1R3_EL1 SYSREG(3, 0, 3, 12, 9)
|
||||
#define SYSREG_ICC_ASGI1R_EL1 SYSREG(3, 0, 6, 12, 11)
|
||||
#define SYSREG_ICC_BPR0_EL1 SYSREG(3, 0, 3, 12, 8)
|
||||
#define SYSREG_ICC_BPR1_EL1 SYSREG(3, 0, 3, 12, 12)
|
||||
#define SYSREG_ICC_CTLR_EL1 SYSREG(3, 0, 4, 12, 12)
|
||||
#define SYSREG_ICC_DIR_EL1 SYSREG(3, 0, 1, 12, 11)
|
||||
#define SYSREG_ICC_EOIR0_EL1 SYSREG(3, 0, 1, 12, 8)
|
||||
#define SYSREG_ICC_EOIR1_EL1 SYSREG(3, 0, 1, 12, 12)
|
||||
#define SYSREG_ICC_HPPIR0_EL1 SYSREG(3, 0, 2, 12, 8)
|
||||
#define SYSREG_ICC_HPPIR1_EL1 SYSREG(3, 0, 2, 12, 12)
|
||||
#define SYSREG_ICC_IAR0_EL1 SYSREG(3, 0, 0, 12, 8)
|
||||
#define SYSREG_ICC_IAR1_EL1 SYSREG(3, 0, 0, 12, 12)
|
||||
#define SYSREG_ICC_IGRPEN0_EL1 SYSREG(3, 0, 6, 12, 12)
|
||||
#define SYSREG_ICC_IGRPEN1_EL1 SYSREG(3, 0, 7, 12, 12)
|
||||
#define SYSREG_ICC_PMR_EL1 SYSREG(3, 0, 0, 4, 6)
|
||||
#define SYSREG_ICC_RPR_EL1 SYSREG(3, 0, 3, 12, 11)
|
||||
#define SYSREG_ICC_SGI0R_EL1 SYSREG(3, 0, 7, 12, 11)
|
||||
#define SYSREG_ICC_SGI1R_EL1 SYSREG(3, 0, 5, 12, 11)
|
||||
#define SYSREG_ICC_SRE_EL1 SYSREG(3, 0, 5, 12, 12)
|
||||
|
||||
#define WFX_IS_WFE (1 << 0)
|
||||
|
||||
struct hvf_reg_match {
|
||||
int reg;
|
||||
uint64_t offset;
|
||||
};
|
||||
|
||||
static const struct hvf_reg_match hvf_reg_match[] = {
|
||||
{ HV_REG_X0, offsetof(CPUARMState, xregs[0]) },
|
||||
{ HV_REG_X1, offsetof(CPUARMState, xregs[1]) },
|
||||
{ HV_REG_X2, offsetof(CPUARMState, xregs[2]) },
|
||||
{ HV_REG_X3, offsetof(CPUARMState, xregs[3]) },
|
||||
{ HV_REG_X4, offsetof(CPUARMState, xregs[4]) },
|
||||
{ HV_REG_X5, offsetof(CPUARMState, xregs[5]) },
|
||||
{ HV_REG_X6, offsetof(CPUARMState, xregs[6]) },
|
||||
{ HV_REG_X7, offsetof(CPUARMState, xregs[7]) },
|
||||
{ HV_REG_X8, offsetof(CPUARMState, xregs[8]) },
|
||||
{ HV_REG_X9, offsetof(CPUARMState, xregs[9]) },
|
||||
{ HV_REG_X10, offsetof(CPUARMState, xregs[10]) },
|
||||
{ HV_REG_X11, offsetof(CPUARMState, xregs[11]) },
|
||||
{ HV_REG_X12, offsetof(CPUARMState, xregs[12]) },
|
||||
{ HV_REG_X13, offsetof(CPUARMState, xregs[13]) },
|
||||
{ HV_REG_X14, offsetof(CPUARMState, xregs[14]) },
|
||||
{ HV_REG_X15, offsetof(CPUARMState, xregs[15]) },
|
||||
{ HV_REG_X16, offsetof(CPUARMState, xregs[16]) },
|
||||
{ HV_REG_X17, offsetof(CPUARMState, xregs[17]) },
|
||||
{ HV_REG_X18, offsetof(CPUARMState, xregs[18]) },
|
||||
{ HV_REG_X19, offsetof(CPUARMState, xregs[19]) },
|
||||
{ HV_REG_X20, offsetof(CPUARMState, xregs[20]) },
|
||||
{ HV_REG_X21, offsetof(CPUARMState, xregs[21]) },
|
||||
{ HV_REG_X22, offsetof(CPUARMState, xregs[22]) },
|
||||
{ HV_REG_X23, offsetof(CPUARMState, xregs[23]) },
|
||||
{ HV_REG_X24, offsetof(CPUARMState, xregs[24]) },
|
||||
{ HV_REG_X25, offsetof(CPUARMState, xregs[25]) },
|
||||
{ HV_REG_X26, offsetof(CPUARMState, xregs[26]) },
|
||||
{ HV_REG_X27, offsetof(CPUARMState, xregs[27]) },
|
||||
{ HV_REG_X28, offsetof(CPUARMState, xregs[28]) },
|
||||
{ HV_REG_X29, offsetof(CPUARMState, xregs[29]) },
|
||||
{ HV_REG_X30, offsetof(CPUARMState, xregs[30]) },
|
||||
{ HV_REG_PC, offsetof(CPUARMState, pc) },
|
||||
};
|
||||
|
||||
struct hvf_sreg_match {
|
||||
int reg;
|
||||
uint32_t key;
|
||||
};
|
||||
|
||||
static const struct hvf_sreg_match hvf_sreg_match[] = {
|
||||
{ HV_SYS_REG_DBGBVR0_EL1, HVF_SYSREG(0, 0, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR0_EL1, HVF_SYSREG(0, 0, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR0_EL1, HVF_SYSREG(0, 0, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR0_EL1, HVF_SYSREG(0, 0, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR1_EL1, HVF_SYSREG(0, 1, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR1_EL1, HVF_SYSREG(0, 1, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR1_EL1, HVF_SYSREG(0, 1, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR1_EL1, HVF_SYSREG(0, 1, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR2_EL1, HVF_SYSREG(0, 2, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR2_EL1, HVF_SYSREG(0, 2, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR2_EL1, HVF_SYSREG(0, 2, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR2_EL1, HVF_SYSREG(0, 2, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR3_EL1, HVF_SYSREG(0, 3, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR3_EL1, HVF_SYSREG(0, 3, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR3_EL1, HVF_SYSREG(0, 3, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR3_EL1, HVF_SYSREG(0, 3, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR4_EL1, HVF_SYSREG(0, 4, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR4_EL1, HVF_SYSREG(0, 4, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR4_EL1, HVF_SYSREG(0, 4, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR4_EL1, HVF_SYSREG(0, 4, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR5_EL1, HVF_SYSREG(0, 5, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR5_EL1, HVF_SYSREG(0, 5, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR5_EL1, HVF_SYSREG(0, 5, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR5_EL1, HVF_SYSREG(0, 5, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR6_EL1, HVF_SYSREG(0, 6, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR6_EL1, HVF_SYSREG(0, 6, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR6_EL1, HVF_SYSREG(0, 6, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR6_EL1, HVF_SYSREG(0, 6, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR7_EL1, HVF_SYSREG(0, 7, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR7_EL1, HVF_SYSREG(0, 7, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR7_EL1, HVF_SYSREG(0, 7, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR7_EL1, HVF_SYSREG(0, 7, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR8_EL1, HVF_SYSREG(0, 8, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR8_EL1, HVF_SYSREG(0, 8, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR8_EL1, HVF_SYSREG(0, 8, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR8_EL1, HVF_SYSREG(0, 8, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR9_EL1, HVF_SYSREG(0, 9, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR9_EL1, HVF_SYSREG(0, 9, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR9_EL1, HVF_SYSREG(0, 9, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR9_EL1, HVF_SYSREG(0, 9, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR10_EL1, HVF_SYSREG(0, 10, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR10_EL1, HVF_SYSREG(0, 10, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR10_EL1, HVF_SYSREG(0, 10, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR10_EL1, HVF_SYSREG(0, 10, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR11_EL1, HVF_SYSREG(0, 11, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR11_EL1, HVF_SYSREG(0, 11, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR11_EL1, HVF_SYSREG(0, 11, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR11_EL1, HVF_SYSREG(0, 11, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR12_EL1, HVF_SYSREG(0, 12, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR12_EL1, HVF_SYSREG(0, 12, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR12_EL1, HVF_SYSREG(0, 12, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR12_EL1, HVF_SYSREG(0, 12, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR13_EL1, HVF_SYSREG(0, 13, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR13_EL1, HVF_SYSREG(0, 13, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR13_EL1, HVF_SYSREG(0, 13, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR13_EL1, HVF_SYSREG(0, 13, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR14_EL1, HVF_SYSREG(0, 14, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR14_EL1, HVF_SYSREG(0, 14, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR14_EL1, HVF_SYSREG(0, 14, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR14_EL1, HVF_SYSREG(0, 14, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR15_EL1, HVF_SYSREG(0, 15, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR15_EL1, HVF_SYSREG(0, 15, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR15_EL1, HVF_SYSREG(0, 15, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR15_EL1, HVF_SYSREG(0, 15, 14, 0, 7) },
|
||||
|
||||
#ifdef SYNC_NO_RAW_REGS
|
||||
/*
|
||||
* The registers below are manually synced on init because they are
|
||||
* marked as NO_RAW. We still list them to make number space sync easier.
|
||||
*/
|
||||
{ HV_SYS_REG_MDCCINT_EL1, HVF_SYSREG(0, 2, 2, 0, 0) },
|
||||
{ HV_SYS_REG_MIDR_EL1, HVF_SYSREG(0, 0, 3, 0, 0) },
|
||||
{ HV_SYS_REG_MPIDR_EL1, HVF_SYSREG(0, 0, 3, 0, 5) },
|
||||
{ HV_SYS_REG_ID_AA64PFR0_EL1, HVF_SYSREG(0, 4, 3, 0, 0) },
|
||||
#endif
|
||||
{ HV_SYS_REG_ID_AA64PFR1_EL1, HVF_SYSREG(0, 4, 3, 0, 2) },
|
||||
{ HV_SYS_REG_ID_AA64DFR0_EL1, HVF_SYSREG(0, 5, 3, 0, 0) },
|
||||
{ HV_SYS_REG_ID_AA64DFR1_EL1, HVF_SYSREG(0, 5, 3, 0, 1) },
|
||||
{ HV_SYS_REG_ID_AA64ISAR0_EL1, HVF_SYSREG(0, 6, 3, 0, 0) },
|
||||
{ HV_SYS_REG_ID_AA64ISAR1_EL1, HVF_SYSREG(0, 6, 3, 0, 1) },
|
||||
#ifdef SYNC_NO_MMFR0
|
||||
/* We keep the hardware MMFR0 around. HW limits are there anyway */
|
||||
{ HV_SYS_REG_ID_AA64MMFR0_EL1, HVF_SYSREG(0, 7, 3, 0, 0) },
|
||||
#endif
|
||||
{ HV_SYS_REG_ID_AA64MMFR1_EL1, HVF_SYSREG(0, 7, 3, 0, 1) },
|
||||
{ HV_SYS_REG_ID_AA64MMFR2_EL1, HVF_SYSREG(0, 7, 3, 0, 2) },
|
||||
|
||||
{ HV_SYS_REG_MDSCR_EL1, HVF_SYSREG(0, 2, 2, 0, 2) },
|
||||
{ HV_SYS_REG_SCTLR_EL1, HVF_SYSREG(1, 0, 3, 0, 0) },
|
||||
{ HV_SYS_REG_CPACR_EL1, HVF_SYSREG(1, 0, 3, 0, 2) },
|
||||
{ HV_SYS_REG_TTBR0_EL1, HVF_SYSREG(2, 0, 3, 0, 0) },
|
||||
{ HV_SYS_REG_TTBR1_EL1, HVF_SYSREG(2, 0, 3, 0, 1) },
|
||||
{ HV_SYS_REG_TCR_EL1, HVF_SYSREG(2, 0, 3, 0, 2) },
|
||||
|
||||
{ HV_SYS_REG_APIAKEYLO_EL1, HVF_SYSREG(2, 1, 3, 0, 0) },
|
||||
{ HV_SYS_REG_APIAKEYHI_EL1, HVF_SYSREG(2, 1, 3, 0, 1) },
|
||||
{ HV_SYS_REG_APIBKEYLO_EL1, HVF_SYSREG(2, 1, 3, 0, 2) },
|
||||
{ HV_SYS_REG_APIBKEYHI_EL1, HVF_SYSREG(2, 1, 3, 0, 3) },
|
||||
{ HV_SYS_REG_APDAKEYLO_EL1, HVF_SYSREG(2, 2, 3, 0, 0) },
|
||||
{ HV_SYS_REG_APDAKEYHI_EL1, HVF_SYSREG(2, 2, 3, 0, 1) },
|
||||
{ HV_SYS_REG_APDBKEYLO_EL1, HVF_SYSREG(2, 2, 3, 0, 2) },
|
||||
{ HV_SYS_REG_APDBKEYHI_EL1, HVF_SYSREG(2, 2, 3, 0, 3) },
|
||||
{ HV_SYS_REG_APGAKEYLO_EL1, HVF_SYSREG(2, 3, 3, 0, 0) },
|
||||
{ HV_SYS_REG_APGAKEYHI_EL1, HVF_SYSREG(2, 3, 3, 0, 1) },
|
||||
|
||||
{ HV_SYS_REG_SPSR_EL1, HVF_SYSREG(4, 0, 3, 1, 0) },
|
||||
{ HV_SYS_REG_ELR_EL1, HVF_SYSREG(4, 0, 3, 0, 1) },
|
||||
{ HV_SYS_REG_SP_EL0, HVF_SYSREG(4, 1, 3, 0, 0) },
|
||||
{ HV_SYS_REG_AFSR0_EL1, HVF_SYSREG(5, 1, 3, 0, 0) },
|
||||
{ HV_SYS_REG_AFSR1_EL1, HVF_SYSREG(5, 1, 3, 0, 1) },
|
||||
{ HV_SYS_REG_ESR_EL1, HVF_SYSREG(5, 2, 3, 0, 0) },
|
||||
{ HV_SYS_REG_FAR_EL1, HVF_SYSREG(6, 0, 3, 0, 0) },
|
||||
{ HV_SYS_REG_PAR_EL1, HVF_SYSREG(7, 4, 3, 0, 0) },
|
||||
{ HV_SYS_REG_MAIR_EL1, HVF_SYSREG(10, 2, 3, 0, 0) },
|
||||
{ HV_SYS_REG_AMAIR_EL1, HVF_SYSREG(10, 3, 3, 0, 0) },
|
||||
{ HV_SYS_REG_VBAR_EL1, HVF_SYSREG(12, 0, 3, 0, 0) },
|
||||
{ HV_SYS_REG_CONTEXTIDR_EL1, HVF_SYSREG(13, 0, 3, 0, 1) },
|
||||
{ HV_SYS_REG_TPIDR_EL1, HVF_SYSREG(13, 0, 3, 0, 4) },
|
||||
{ HV_SYS_REG_CNTKCTL_EL1, HVF_SYSREG(14, 1, 3, 0, 0) },
|
||||
{ HV_SYS_REG_CSSELR_EL1, HVF_SYSREG(0, 0, 3, 2, 0) },
|
||||
{ HV_SYS_REG_TPIDR_EL0, HVF_SYSREG(13, 0, 3, 3, 2) },
|
||||
{ HV_SYS_REG_TPIDRRO_EL0, HVF_SYSREG(13, 0, 3, 3, 3) },
|
||||
{ HV_SYS_REG_CNTV_CTL_EL0, HVF_SYSREG(14, 3, 3, 3, 1) },
|
||||
{ HV_SYS_REG_CNTV_CVAL_EL0, HVF_SYSREG(14, 3, 3, 3, 2) },
|
||||
{ HV_SYS_REG_SP_EL1, HVF_SYSREG(4, 1, 3, 4, 0) },
|
||||
};
|
||||
|
||||
int hvf_get_registers(CPUState *cpu)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
CPUARMState *env = &arm_cpu->env;
|
||||
hv_return_t ret;
|
||||
uint64_t val;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(hvf_reg_match); i++) {
|
||||
ret = hv_vcpu_get_reg(cpu->hvf->fd, hvf_reg_match[i].reg, &val);
|
||||
*(uint64_t *)((void *)env + hvf_reg_match[i].offset) = val;
|
||||
assert_hvf_ok(ret);
|
||||
}
|
||||
|
||||
val = 0;
|
||||
ret = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_FPCR, &val);
|
||||
assert_hvf_ok(ret);
|
||||
vfp_set_fpcr(env, val);
|
||||
|
||||
val = 0;
|
||||
ret = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_FPSR, &val);
|
||||
assert_hvf_ok(ret);
|
||||
vfp_set_fpsr(env, val);
|
||||
|
||||
ret = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_CPSR, &val);
|
||||
assert_hvf_ok(ret);
|
||||
pstate_write(env, val);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(hvf_sreg_match); i++) {
|
||||
ret = hv_vcpu_get_sys_reg(cpu->hvf->fd, hvf_sreg_match[i].reg, &val);
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
arm_cpu->cpreg_values[i] = val;
|
||||
}
|
||||
write_list_to_cpustate(arm_cpu);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hvf_put_registers(CPUState *cpu)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
CPUARMState *env = &arm_cpu->env;
|
||||
hv_return_t ret;
|
||||
uint64_t val;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(hvf_reg_match); i++) {
|
||||
val = *(uint64_t *)((void *)env + hvf_reg_match[i].offset);
|
||||
ret = hv_vcpu_set_reg(cpu->hvf->fd, hvf_reg_match[i].reg, val);
|
||||
|
||||
assert_hvf_ok(ret);
|
||||
}
|
||||
|
||||
ret = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_FPCR, vfp_get_fpcr(env));
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
ret = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_FPSR, vfp_get_fpsr(env));
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
ret = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_CPSR, pstate_read(env));
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
write_cpustate_to_list(arm_cpu, false);
|
||||
for (i = 0; i < ARRAY_SIZE(hvf_sreg_match); i++) {
|
||||
val = arm_cpu->cpreg_values[i];
|
||||
ret = hv_vcpu_set_sys_reg(cpu->hvf->fd, hvf_sreg_match[i].reg, val);
|
||||
assert_hvf_ok(ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void flush_cpu_state(CPUState *cpu)
|
||||
{
|
||||
if (cpu->vcpu_dirty) {
|
||||
hvf_put_registers(cpu);
|
||||
cpu->vcpu_dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void hvf_set_reg(CPUState *cpu, int rt, uint64_t val)
|
||||
{
|
||||
hv_return_t r;
|
||||
|
||||
flush_cpu_state(cpu);
|
||||
|
||||
if (rt < 31) {
|
||||
r = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_X0 + rt, val);
|
||||
assert_hvf_ok(r);
|
||||
}
|
||||
}
|
||||
|
||||
static uint64_t hvf_get_reg(CPUState *cpu, int rt)
|
||||
{
|
||||
uint64_t val = 0;
|
||||
hv_return_t r;
|
||||
|
||||
flush_cpu_state(cpu);
|
||||
|
||||
if (rt < 31) {
|
||||
r = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_X0 + rt, &val);
|
||||
assert_hvf_ok(r);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void hvf_arm_set_cpu_features_from_host(ARMCPU *cpu)
|
||||
{
|
||||
ARMISARegisters host_isar;
|
||||
const struct isar_regs {
|
||||
int reg;
|
||||
uint64_t *val;
|
||||
} regs[] = {
|
||||
{ HV_SYS_REG_ID_AA64PFR0_EL1, &host_isar.id_aa64pfr0 },
|
||||
{ HV_SYS_REG_ID_AA64PFR1_EL1, &host_isar.id_aa64pfr1 },
|
||||
{ HV_SYS_REG_ID_AA64DFR0_EL1, &host_isar.id_aa64dfr0 },
|
||||
{ HV_SYS_REG_ID_AA64DFR1_EL1, &host_isar.id_aa64dfr1 },
|
||||
{ HV_SYS_REG_ID_AA64ISAR0_EL1, &host_isar.id_aa64isar0 },
|
||||
{ HV_SYS_REG_ID_AA64ISAR1_EL1, &host_isar.id_aa64isar1 },
|
||||
{ HV_SYS_REG_ID_AA64MMFR0_EL1, &host_isar.id_aa64mmfr0 },
|
||||
{ HV_SYS_REG_ID_AA64MMFR1_EL1, &host_isar.id_aa64mmfr1 },
|
||||
{ HV_SYS_REG_ID_AA64MMFR2_EL1, &host_isar.id_aa64mmfr2 },
|
||||
};
|
||||
hv_vcpu_t fd;
|
||||
hv_vcpu_exit_t *exit;
|
||||
int i;
|
||||
|
||||
cpu->dtb_compatible = "arm,arm-v8";
|
||||
cpu->env.features = (1ULL << ARM_FEATURE_V8) |
|
||||
(1ULL << ARM_FEATURE_NEON) |
|
||||
(1ULL << ARM_FEATURE_AARCH64) |
|
||||
(1ULL << ARM_FEATURE_PMU) |
|
||||
(1ULL << ARM_FEATURE_GENERIC_TIMER);
|
||||
|
||||
/* We set up a small vcpu to extract host registers */
|
||||
|
||||
assert_hvf_ok(hv_vcpu_create(&fd, &exit, NULL));
|
||||
for (i = 0; i < ARRAY_SIZE(regs); i++) {
|
||||
assert_hvf_ok(hv_vcpu_get_sys_reg(fd, regs[i].reg, regs[i].val));
|
||||
}
|
||||
assert_hvf_ok(hv_vcpu_get_sys_reg(fd, HV_SYS_REG_MIDR_EL1, &cpu->midr));
|
||||
assert_hvf_ok(hv_vcpu_destroy(fd));
|
||||
|
||||
cpu->isar = host_isar;
|
||||
cpu->reset_sctlr = 0x00c50078;
|
||||
}
|
||||
|
||||
void hvf_arch_vcpu_destroy(CPUState *cpu)
|
||||
{
|
||||
}
|
||||
|
||||
int hvf_arch_init_vcpu(CPUState *cpu)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
CPUARMState *env = &arm_cpu->env;
|
||||
uint32_t sregs_match_len = ARRAY_SIZE(hvf_sreg_match);
|
||||
uint64_t pfr;
|
||||
hv_return_t ret;
|
||||
int i;
|
||||
|
||||
env->aarch64 = 1;
|
||||
asm volatile("mrs %0, cntfrq_el0" : "=r"(arm_cpu->gt_cntfrq_hz));
|
||||
|
||||
/* Allocate enough space for our sysreg sync */
|
||||
arm_cpu->cpreg_indexes = g_renew(uint64_t, arm_cpu->cpreg_indexes,
|
||||
sregs_match_len);
|
||||
arm_cpu->cpreg_values = g_renew(uint64_t, arm_cpu->cpreg_values,
|
||||
sregs_match_len);
|
||||
arm_cpu->cpreg_vmstate_indexes = g_renew(uint64_t,
|
||||
arm_cpu->cpreg_vmstate_indexes,
|
||||
sregs_match_len);
|
||||
arm_cpu->cpreg_vmstate_values = g_renew(uint64_t,
|
||||
arm_cpu->cpreg_vmstate_values,
|
||||
sregs_match_len);
|
||||
|
||||
memset(arm_cpu->cpreg_values, 0, sregs_match_len * sizeof(uint64_t));
|
||||
arm_cpu->cpreg_array_len = sregs_match_len;
|
||||
arm_cpu->cpreg_vmstate_array_len = sregs_match_len;
|
||||
|
||||
/* Populate cp list for all known sysregs */
|
||||
for (i = 0; i < sregs_match_len; i++) {
|
||||
const ARMCPRegInfo *ri;
|
||||
|
||||
arm_cpu->cpreg_indexes[i] = cpreg_to_kvm_id(hvf_sreg_match[i].key);
|
||||
|
||||
ri = get_arm_cp_reginfo(arm_cpu->cp_regs, hvf_sreg_match[i].key);
|
||||
if (ri) {
|
||||
assert(!(ri->type & ARM_CP_NO_RAW));
|
||||
}
|
||||
}
|
||||
write_cpustate_to_list(arm_cpu, false);
|
||||
|
||||
/* Set CP_NO_RAW system registers on init */
|
||||
ret = hv_vcpu_set_sys_reg(cpu->hvf->fd, HV_SYS_REG_MIDR_EL1,
|
||||
arm_cpu->midr);
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
ret = hv_vcpu_set_sys_reg(cpu->hvf->fd, HV_SYS_REG_MPIDR_EL1,
|
||||
arm_cpu->mp_affinity);
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
ret = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_ID_AA64PFR0_EL1, &pfr);
|
||||
assert_hvf_ok(ret);
|
||||
pfr |= env->gicv3state ? (1 << 24) : 0;
|
||||
ret = hv_vcpu_set_sys_reg(cpu->hvf->fd, HV_SYS_REG_ID_AA64PFR0_EL1, pfr);
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
/* We're limited to underlying hardware caps, override internal versions */
|
||||
ret = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_ID_AA64MMFR0_EL1,
|
||||
&arm_cpu->isar.id_aa64mmfr0);
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hvf_kick_vcpu_thread(CPUState *cpu)
|
||||
{
|
||||
cpus_kick_thread(cpu);
|
||||
hv_vcpus_exit(&cpu->hvf->fd, 1);
|
||||
}
|
||||
|
||||
static uint32_t hvf_reg2cp_reg(uint32_t reg)
|
||||
{
|
||||
return ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP,
|
||||
(reg >> 10) & 0xf,
|
||||
(reg >> 1) & 0xf,
|
||||
(reg >> 20) & 0x3,
|
||||
(reg >> 14) & 0x7,
|
||||
(reg >> 17) & 0x7);
|
||||
}
|
||||
|
||||
static uint64_t hvf_sysreg_read_cp(CPUState *cpu, uint32_t reg)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
CPUARMState *env = &arm_cpu->env;
|
||||
const ARMCPRegInfo *ri;
|
||||
uint64_t val = 0;
|
||||
|
||||
ri = get_arm_cp_reginfo(arm_cpu->cp_regs, hvf_reg2cp_reg(reg));
|
||||
if (ri) {
|
||||
if (ri->type & ARM_CP_CONST) {
|
||||
val = ri->resetvalue;
|
||||
} else if (ri->readfn) {
|
||||
val = ri->readfn(env, ri);
|
||||
} else {
|
||||
val = CPREG_FIELD64(env, ri);
|
||||
}
|
||||
DPRINTF("vgic read from %s [val=%016llx]", ri->name, val);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static uint64_t hvf_sysreg_read(CPUState *cpu, uint32_t reg)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
uint64_t val = 0;
|
||||
|
||||
switch (reg) {
|
||||
case SYSREG_CNTPCT_EL0:
|
||||
val = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) /
|
||||
gt_cntfrq_period_ns(arm_cpu);
|
||||
break;
|
||||
case SYSREG_PMCCNTR_EL0:
|
||||
val = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
|
||||
break;
|
||||
case SYSREG_ICC_AP0R0_EL1:
|
||||
case SYSREG_ICC_AP0R1_EL1:
|
||||
case SYSREG_ICC_AP0R2_EL1:
|
||||
case SYSREG_ICC_AP0R3_EL1:
|
||||
case SYSREG_ICC_AP1R0_EL1:
|
||||
case SYSREG_ICC_AP1R1_EL1:
|
||||
case SYSREG_ICC_AP1R2_EL1:
|
||||
case SYSREG_ICC_AP1R3_EL1:
|
||||
case SYSREG_ICC_ASGI1R_EL1:
|
||||
case SYSREG_ICC_BPR0_EL1:
|
||||
case SYSREG_ICC_BPR1_EL1:
|
||||
case SYSREG_ICC_DIR_EL1:
|
||||
case SYSREG_ICC_EOIR0_EL1:
|
||||
case SYSREG_ICC_EOIR1_EL1:
|
||||
case SYSREG_ICC_HPPIR0_EL1:
|
||||
case SYSREG_ICC_HPPIR1_EL1:
|
||||
case SYSREG_ICC_IAR0_EL1:
|
||||
case SYSREG_ICC_IAR1_EL1:
|
||||
case SYSREG_ICC_IGRPEN0_EL1:
|
||||
case SYSREG_ICC_IGRPEN1_EL1:
|
||||
case SYSREG_ICC_PMR_EL1:
|
||||
case SYSREG_ICC_SGI0R_EL1:
|
||||
case SYSREG_ICC_SGI1R_EL1:
|
||||
case SYSREG_ICC_SRE_EL1:
|
||||
val = hvf_sysreg_read_cp(cpu, reg);
|
||||
break;
|
||||
case SYSREG_ICC_CTLR_EL1:
|
||||
val = hvf_sysreg_read_cp(cpu, reg);
|
||||
|
||||
/* AP0R registers above 0 don't trap, expose less PRIs to fit */
|
||||
val &= ~ICC_CTLR_EL1_PRIBITS_MASK;
|
||||
val |= 4 << ICC_CTLR_EL1_PRIBITS_SHIFT;
|
||||
break;
|
||||
default:
|
||||
DPRINTF("unhandled sysreg read %08x (op0=%d op1=%d op2=%d "
|
||||
"crn=%d crm=%d)", reg, (reg >> 20) & 0x3,
|
||||
(reg >> 14) & 0x7, (reg >> 17) & 0x7,
|
||||
(reg >> 10) & 0xf, (reg >> 1) & 0xf);
|
||||
break;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static void hvf_sysreg_write_cp(CPUState *cpu, uint32_t reg, uint64_t val)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
CPUARMState *env = &arm_cpu->env;
|
||||
const ARMCPRegInfo *ri;
|
||||
|
||||
ri = get_arm_cp_reginfo(arm_cpu->cp_regs, hvf_reg2cp_reg(reg));
|
||||
|
||||
if (ri) {
|
||||
if (ri->writefn) {
|
||||
ri->writefn(env, ri, val);
|
||||
} else {
|
||||
CPREG_FIELD64(env, ri) = val;
|
||||
}
|
||||
DPRINTF("vgic write to %s [val=%016llx]", ri->name, val);
|
||||
}
|
||||
}
|
||||
|
||||
static void hvf_sysreg_write(CPUState *cpu, uint32_t reg, uint64_t val)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
|
||||
switch (reg) {
|
||||
case SYSREG_CNTPCT_EL0:
|
||||
break;
|
||||
case SYSREG_ICC_AP0R0_EL1:
|
||||
case SYSREG_ICC_AP0R1_EL1:
|
||||
case SYSREG_ICC_AP0R2_EL1:
|
||||
case SYSREG_ICC_AP0R3_EL1:
|
||||
case SYSREG_ICC_AP1R0_EL1:
|
||||
case SYSREG_ICC_AP1R1_EL1:
|
||||
case SYSREG_ICC_AP1R2_EL1:
|
||||
case SYSREG_ICC_AP1R3_EL1:
|
||||
case SYSREG_ICC_ASGI1R_EL1:
|
||||
case SYSREG_ICC_BPR0_EL1:
|
||||
case SYSREG_ICC_BPR1_EL1:
|
||||
case SYSREG_ICC_CTLR_EL1:
|
||||
case SYSREG_ICC_DIR_EL1:
|
||||
case SYSREG_ICC_HPPIR0_EL1:
|
||||
case SYSREG_ICC_HPPIR1_EL1:
|
||||
case SYSREG_ICC_IAR0_EL1:
|
||||
case SYSREG_ICC_IAR1_EL1:
|
||||
case SYSREG_ICC_IGRPEN0_EL1:
|
||||
case SYSREG_ICC_IGRPEN1_EL1:
|
||||
case SYSREG_ICC_PMR_EL1:
|
||||
case SYSREG_ICC_SGI0R_EL1:
|
||||
case SYSREG_ICC_SGI1R_EL1:
|
||||
case SYSREG_ICC_SRE_EL1:
|
||||
hvf_sysreg_write_cp(cpu, reg, val);
|
||||
break;
|
||||
case SYSREG_ICC_EOIR0_EL1:
|
||||
case SYSREG_ICC_EOIR1_EL1:
|
||||
hvf_sysreg_write_cp(cpu, reg, val);
|
||||
qemu_set_irq(arm_cpu->gt_timer_outputs[GTIMER_VIRT], 0);
|
||||
hv_vcpu_set_vtimer_mask(cpu->hvf->fd, false);
|
||||
default:
|
||||
DPRINTF("unhandled sysreg write %08x", reg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int hvf_inject_interrupts(CPUState *cpu)
|
||||
{
|
||||
if (cpu->interrupt_request & CPU_INTERRUPT_FIQ) {
|
||||
DPRINTF("injecting FIQ");
|
||||
hv_vcpu_set_pending_interrupt(cpu->hvf->fd, HV_INTERRUPT_TYPE_FIQ, true);
|
||||
}
|
||||
|
||||
if (cpu->interrupt_request & CPU_INTERRUPT_HARD) {
|
||||
DPRINTF("injecting IRQ");
|
||||
hv_vcpu_set_pending_interrupt(cpu->hvf->fd, HV_INTERRUPT_TYPE_IRQ, true);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void hvf_wait_for_ipi(CPUState *cpu, struct timespec *ts)
|
||||
{
|
||||
/*
|
||||
* Use pselect to sleep so that other threads can IPI us while we're
|
||||
* sleeping.
|
||||
*/
|
||||
qatomic_mb_set(&cpu->thread_kicked, false);
|
||||
qemu_mutex_unlock_iothread();
|
||||
pselect(0, 0, 0, 0, ts, &cpu->hvf->unblock_ipi_mask);
|
||||
qemu_mutex_lock_iothread();
|
||||
}
|
||||
|
||||
int hvf_vcpu_exec(CPUState *cpu)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
CPUARMState *env = &arm_cpu->env;
|
||||
hv_vcpu_exit_t *hvf_exit = cpu->hvf->exit;
|
||||
hv_return_t r;
|
||||
|
||||
while (1) {
|
||||
bool advance_pc = false;
|
||||
|
||||
qemu_wait_io_event_common(cpu);
|
||||
flush_cpu_state(cpu);
|
||||
|
||||
if (hvf_inject_interrupts(cpu)) {
|
||||
return EXCP_INTERRUPT;
|
||||
}
|
||||
|
||||
if (cpu->halted) {
|
||||
return EXCP_HLT;
|
||||
}
|
||||
|
||||
qemu_mutex_unlock_iothread();
|
||||
assert_hvf_ok(hv_vcpu_run(cpu->hvf->fd));
|
||||
|
||||
/* handle VMEXIT */
|
||||
uint64_t exit_reason = hvf_exit->reason;
|
||||
uint64_t syndrome = hvf_exit->exception.syndrome;
|
||||
uint32_t ec = syn_get_ec(syndrome);
|
||||
|
||||
qemu_mutex_lock_iothread();
|
||||
switch (exit_reason) {
|
||||
case HV_EXIT_REASON_EXCEPTION:
|
||||
/* This is the main one, handle below. */
|
||||
break;
|
||||
case HV_EXIT_REASON_VTIMER_ACTIVATED:
|
||||
qemu_set_irq(arm_cpu->gt_timer_outputs[GTIMER_VIRT], 1);
|
||||
continue;
|
||||
case HV_EXIT_REASON_CANCELED:
|
||||
/* we got kicked, no exit to process */
|
||||
continue;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
||||
switch (ec) {
|
||||
case EC_DATAABORT: {
|
||||
bool isv = syndrome & ARM_EL_ISV;
|
||||
bool iswrite = (syndrome >> 6) & 1;
|
||||
bool s1ptw = (syndrome >> 7) & 1;
|
||||
uint32_t sas = (syndrome >> 22) & 3;
|
||||
uint32_t len = 1 << sas;
|
||||
uint32_t srt = (syndrome >> 16) & 0x1f;
|
||||
uint64_t val = 0;
|
||||
|
||||
DPRINTF("data abort: [pc=0x%llx va=0x%016llx pa=0x%016llx isv=%x "
|
||||
"iswrite=%x s1ptw=%x len=%d srt=%d]\n",
|
||||
env->pc, hvf_exit->exception.virtual_address,
|
||||
hvf_exit->exception.physical_address, isv, iswrite,
|
||||
s1ptw, len, srt);
|
||||
|
||||
assert(isv);
|
||||
|
||||
if (iswrite) {
|
||||
val = hvf_get_reg(cpu, srt);
|
||||
address_space_write(&address_space_memory,
|
||||
hvf_exit->exception.physical_address,
|
||||
MEMTXATTRS_UNSPECIFIED, &val, len);
|
||||
|
||||
/*
|
||||
* We do not have a callback to see if the timer is out of
|
||||
* pending state. That means every MMIO write could
|
||||
* potentially be an EOI ends the vtimer. Until we get an
|
||||
* actual callback, let's just see if the timer is still
|
||||
* pending on every possible toggle point.
|
||||
*/
|
||||
qemu_set_irq(arm_cpu->gt_timer_outputs[GTIMER_VIRT], 0);
|
||||
hv_vcpu_set_vtimer_mask(cpu->hvf->fd, false);
|
||||
} else {
|
||||
address_space_read(&address_space_memory,
|
||||
hvf_exit->exception.physical_address,
|
||||
MEMTXATTRS_UNSPECIFIED, &val, len);
|
||||
hvf_set_reg(cpu, srt, val);
|
||||
}
|
||||
|
||||
advance_pc = true;
|
||||
break;
|
||||
}
|
||||
case EC_SYSTEMREGISTERTRAP: {
|
||||
bool isread = (syndrome >> 0) & 1;
|
||||
uint32_t rt = (syndrome >> 5) & 0x1f;
|
||||
uint32_t reg = syndrome & SYSREG_MASK;
|
||||
uint64_t val = 0;
|
||||
|
||||
DPRINTF("sysreg %s operation reg=%08x (op0=%d op1=%d op2=%d "
|
||||
"crn=%d crm=%d)", (isread) ? "read" : "write",
|
||||
reg, (reg >> 20) & 0x3,
|
||||
(reg >> 14) & 0x7, (reg >> 17) & 0x7,
|
||||
(reg >> 10) & 0xf, (reg >> 1) & 0xf);
|
||||
|
||||
if (isread) {
|
||||
hvf_set_reg(cpu, rt, hvf_sysreg_read(cpu, reg));
|
||||
} else {
|
||||
val = hvf_get_reg(cpu, rt);
|
||||
hvf_sysreg_write(cpu, reg, val);
|
||||
}
|
||||
|
||||
advance_pc = true;
|
||||
break;
|
||||
}
|
||||
case EC_WFX_TRAP:
|
||||
advance_pc = true;
|
||||
if (!(syndrome & WFX_IS_WFE) && !(cpu->interrupt_request &
|
||||
(CPU_INTERRUPT_HARD | CPU_INTERRUPT_FIQ))) {
|
||||
|
||||
uint64_t ctl;
|
||||
r = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_CNTV_CTL_EL0,
|
||||
&ctl);
|
||||
assert_hvf_ok(r);
|
||||
|
||||
if (!(ctl & 1) || (ctl & 2)) {
|
||||
/* Timer disabled or masked, just wait for an IPI. */
|
||||
hvf_wait_for_ipi(cpu, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
uint64_t cval;
|
||||
r = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_CNTV_CVAL_EL0,
|
||||
&cval);
|
||||
assert_hvf_ok(r);
|
||||
|
||||
int64_t ticks_to_sleep = cval - mach_absolute_time();
|
||||
if (ticks_to_sleep < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
uint64_t seconds = ticks_to_sleep / arm_cpu->gt_cntfrq_hz;
|
||||
uint64_t nanos =
|
||||
(ticks_to_sleep - arm_cpu->gt_cntfrq_hz * seconds) *
|
||||
1000000000 / arm_cpu->gt_cntfrq_hz;
|
||||
|
||||
/*
|
||||
* Don't sleep for less than 2ms. This is believed to improve
|
||||
* latency of message passing workloads.
|
||||
*/
|
||||
if (!seconds && nanos < 2000000) {
|
||||
break;
|
||||
}
|
||||
|
||||
struct timespec ts = { seconds, nanos };
|
||||
hvf_wait_for_ipi(cpu, &ts);
|
||||
}
|
||||
break;
|
||||
case EC_AA64_HVC:
|
||||
cpu_synchronize_state(cpu);
|
||||
if (arm_is_psci_call(arm_cpu, EXCP_HVC)) {
|
||||
arm_handle_psci_call(arm_cpu);
|
||||
} else {
|
||||
DPRINTF("unknown HVC! %016llx", env->xregs[0]);
|
||||
env->xregs[0] = -1;
|
||||
}
|
||||
break;
|
||||
case EC_AA64_SMC:
|
||||
cpu_synchronize_state(cpu);
|
||||
if (arm_is_psci_call(arm_cpu, EXCP_SMC)) {
|
||||
arm_handle_psci_call(arm_cpu);
|
||||
} else {
|
||||
DPRINTF("unknown SMC! %016llx", env->xregs[0]);
|
||||
env->xregs[0] = -1;
|
||||
}
|
||||
env->pc += 4;
|
||||
break;
|
||||
default:
|
||||
cpu_synchronize_state(cpu);
|
||||
DPRINTF("exit: %llx [ec=0x%x pc=0x%llx]", syndrome, ec, env->pc);
|
||||
error_report("%llx: unhandled exit %llx", env->pc, exit_reason);
|
||||
}
|
||||
|
||||
if (advance_pc) {
|
||||
uint64_t pc;
|
||||
|
||||
flush_cpu_state(cpu);
|
||||
|
||||
r = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_PC, &pc);
|
||||
assert_hvf_ok(r);
|
||||
pc += 4;
|
||||
r = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_PC, pc);
|
||||
assert_hvf_ok(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
arm_softmmu_ss.add(when: [hvf, 'CONFIG_HVF'], if_true: files(
|
||||
'hvf.c',
|
||||
))
|
||||
@@ -214,8 +214,6 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try,
|
||||
*/
|
||||
void kvm_arm_destroy_scratch_host_vcpu(int *fdarray);
|
||||
|
||||
#define TYPE_ARM_HOST_CPU "host-" TYPE_ARM_CPU
|
||||
|
||||
/**
|
||||
* ARMHostCPUFeatures: information about the host CPU (identified
|
||||
* by asking the host kernel)
|
||||
|
||||
@@ -56,5 +56,7 @@ arm_softmmu_ss.add(files(
|
||||
'psci.c',
|
||||
))
|
||||
|
||||
subdir('hvf')
|
||||
|
||||
target_arch += {'arm': arm_ss}
|
||||
target_softmmu_arch += {'arm': arm_softmmu_ss}
|
||||
@@ -410,7 +410,7 @@ static inline bool use_goto_tb(DisasContext *s, int n, uint64_t dest)
|
||||
|
||||
static inline void gen_goto_tb(DisasContext *s, int n, uint64_t dest)
|
||||
{
|
||||
TranslationBlock *tb;
|
||||
const TranslationBlock *tb;
|
||||
|
||||
tb = s->base.tb;
|
||||
if (use_goto_tb(s, n, dest)) {
|
||||
|
||||
+2
-1
@@ -41,7 +41,8 @@ static bool avr_cpu_has_work(CPUState *cs)
|
||||
&& cpu_interrupts_enabled(env);
|
||||
}
|
||||
|
||||
static void avr_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
|
||||
static void avr_cpu_synchronize_from_tb(CPUState *cs,
|
||||
const TranslationBlock *tb)
|
||||
{
|
||||
AVRCPU *cpu = AVR_CPU(cs);
|
||||
CPUAVRState *env = &cpu->env;
|
||||
|
||||
+2
-1
@@ -35,7 +35,8 @@ static void hppa_cpu_set_pc(CPUState *cs, vaddr value)
|
||||
cpu->env.iaoq_b = value + 4;
|
||||
}
|
||||
|
||||
static void hppa_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
|
||||
static void hppa_cpu_synchronize_from_tb(CPUState *cs,
|
||||
const TranslationBlock *tb)
|
||||
{
|
||||
HPPACPU *cpu = HPPA_CPU(cs);
|
||||
|
||||
|
||||
+2
-1
@@ -7047,7 +7047,8 @@ static void x86_cpu_set_pc(CPUState *cs, vaddr value)
|
||||
cpu->env.eip = value;
|
||||
}
|
||||
|
||||
static void x86_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
|
||||
static void x86_cpu_synchronize_from_tb(CPUState *cs,
|
||||
const TranslationBlock *tb)
|
||||
{
|
||||
X86CPU *cpu = X86_CPU(cs);
|
||||
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008 IBM Corporation
|
||||
* 2008 Red Hat, Inc.
|
||||
* Copyright 2011 Intel Corporation
|
||||
* Copyright 2016 Veertu, Inc.
|
||||
* Copyright 2017 The Android Open Source Project
|
||||
*
|
||||
* QEMU Hypervisor.framework support
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2 of the GNU General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This file contain code under public domain from the hvdos project:
|
||||
* https://github.com/mist64/hvdos
|
||||
*
|
||||
* Parts Copyright (c) 2011 NetApp, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/main-loop.h"
|
||||
#include "sysemu/hvf.h"
|
||||
#include "sysemu/runstate.h"
|
||||
#include "target/i386/cpu.h"
|
||||
#include "qemu/guest-random.h"
|
||||
|
||||
#include "hvf-cpus.h"
|
||||
|
||||
/*
|
||||
* The HVF-specific vCPU thread function. This one should only run when the host
|
||||
* CPU supports the VMX "unrestricted guest" feature.
|
||||
*/
|
||||
static void *hvf_cpu_thread_fn(void *arg)
|
||||
{
|
||||
CPUState *cpu = arg;
|
||||
|
||||
int r;
|
||||
|
||||
assert(hvf_enabled());
|
||||
|
||||
rcu_register_thread();
|
||||
|
||||
qemu_mutex_lock_iothread();
|
||||
qemu_thread_get_self(cpu->thread);
|
||||
|
||||
cpu->thread_id = qemu_get_thread_id();
|
||||
cpu->can_do_io = 1;
|
||||
current_cpu = cpu;
|
||||
|
||||
hvf_init_vcpu(cpu);
|
||||
|
||||
/* signal CPU creation */
|
||||
cpu_thread_signal_created(cpu);
|
||||
qemu_guest_random_seed_thread_part2(cpu->random_seed);
|
||||
|
||||
do {
|
||||
if (cpu_can_run(cpu)) {
|
||||
r = hvf_vcpu_exec(cpu);
|
||||
if (r == EXCP_DEBUG) {
|
||||
cpu_handle_guest_debug(cpu);
|
||||
}
|
||||
}
|
||||
qemu_wait_io_event(cpu);
|
||||
} while (!cpu->unplug || cpu_can_run(cpu));
|
||||
|
||||
hvf_vcpu_destroy(cpu);
|
||||
cpu_thread_signal_destroyed(cpu);
|
||||
qemu_mutex_unlock_iothread();
|
||||
rcu_unregister_thread();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void hvf_start_vcpu_thread(CPUState *cpu)
|
||||
{
|
||||
char thread_name[VCPU_THREAD_NAME_SIZE];
|
||||
|
||||
/*
|
||||
* HVF currently does not support TCG, and only runs in
|
||||
* unrestricted-guest mode.
|
||||
*/
|
||||
assert(hvf_enabled());
|
||||
|
||||
cpu->thread = g_malloc0(sizeof(QemuThread));
|
||||
cpu->halt_cond = g_malloc0(sizeof(QemuCond));
|
||||
qemu_cond_init(cpu->halt_cond);
|
||||
|
||||
snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HVF",
|
||||
cpu->cpu_index);
|
||||
qemu_thread_create(cpu->thread, thread_name, hvf_cpu_thread_fn,
|
||||
cpu, QEMU_THREAD_JOINABLE);
|
||||
}
|
||||
|
||||
const CpusAccel hvf_cpus = {
|
||||
.create_vcpu_thread = hvf_start_vcpu_thread,
|
||||
|
||||
.synchronize_post_reset = hvf_cpu_synchronize_post_reset,
|
||||
.synchronize_post_init = hvf_cpu_synchronize_post_init,
|
||||
.synchronize_state = hvf_cpu_synchronize_state,
|
||||
.synchronize_pre_loadvm = hvf_cpu_synchronize_pre_loadvm,
|
||||
};
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Accelerator CPUS Interface
|
||||
*
|
||||
* Copyright 2020 SUSE LLC
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
#ifndef HVF_CPUS_H
|
||||
#define HVF_CPUS_H
|
||||
|
||||
#include "sysemu/cpus.h"
|
||||
|
||||
extern const CpusAccel hvf_cpus;
|
||||
|
||||
int hvf_init_vcpu(CPUState *);
|
||||
int hvf_vcpu_exec(CPUState *);
|
||||
void hvf_cpu_synchronize_state(CPUState *);
|
||||
void hvf_cpu_synchronize_post_reset(CPUState *);
|
||||
void hvf_cpu_synchronize_post_init(CPUState *);
|
||||
void hvf_cpu_synchronize_pre_loadvm(CPUState *);
|
||||
void hvf_vcpu_destroy(CPUState *);
|
||||
|
||||
#endif /* HVF_CPUS_H */
|
||||
@@ -18,64 +18,17 @@
|
||||
|
||||
#include "sysemu/accel.h"
|
||||
#include "sysemu/hvf.h"
|
||||
#include "sysemu/hvf_int.h"
|
||||
#include "cpu.h"
|
||||
#include "x86.h"
|
||||
|
||||
#define HVF_MAX_VCPU 0x10
|
||||
|
||||
extern struct hvf_state hvf_global;
|
||||
|
||||
struct hvf_vm {
|
||||
int id;
|
||||
struct hvf_vcpu_state *vcpus[HVF_MAX_VCPU];
|
||||
};
|
||||
|
||||
struct hvf_state {
|
||||
uint32_t version;
|
||||
struct hvf_vm *vm;
|
||||
uint64_t mem_quota;
|
||||
};
|
||||
|
||||
/* hvf_slot flags */
|
||||
#define HVF_SLOT_LOG (1 << 0)
|
||||
|
||||
typedef struct hvf_slot {
|
||||
uint64_t start;
|
||||
uint64_t size;
|
||||
uint8_t *mem;
|
||||
int slot_id;
|
||||
uint32_t flags;
|
||||
MemoryRegion *region;
|
||||
} hvf_slot;
|
||||
|
||||
typedef struct hvf_vcpu_caps {
|
||||
uint64_t vmx_cap_pinbased;
|
||||
uint64_t vmx_cap_procbased;
|
||||
uint64_t vmx_cap_procbased2;
|
||||
uint64_t vmx_cap_entry;
|
||||
uint64_t vmx_cap_exit;
|
||||
uint64_t vmx_cap_preemption_timer;
|
||||
} hvf_vcpu_caps;
|
||||
|
||||
struct HVFState {
|
||||
AccelState parent;
|
||||
hvf_slot slots[32];
|
||||
int num_slots;
|
||||
|
||||
hvf_vcpu_caps *hvf_caps;
|
||||
};
|
||||
extern HVFState *hvf_state;
|
||||
|
||||
void hvf_set_phys_mem(MemoryRegionSection *, bool);
|
||||
void hvf_handle_io(CPUArchState *, uint16_t, void *, int, int, int);
|
||||
hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t);
|
||||
|
||||
#ifdef NEED_CPU_H
|
||||
/* Functions exported to host specific mode */
|
||||
|
||||
/* Host specific functions */
|
||||
int hvf_inject_interrupt(CPUArchState *env, int vector);
|
||||
int hvf_vcpu_run(struct hvf_vcpu_state *vcpu);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+54
-408
@@ -51,6 +51,7 @@
|
||||
#include "qemu/error-report.h"
|
||||
|
||||
#include "sysemu/hvf.h"
|
||||
#include "sysemu/hvf_int.h"
|
||||
#include "sysemu/runstate.h"
|
||||
#include "hvf-i386.h"
|
||||
#include "vmcs.h"
|
||||
@@ -72,171 +73,6 @@
|
||||
#include "sysemu/accel.h"
|
||||
#include "target/i386/cpu.h"
|
||||
|
||||
#include "hvf-cpus.h"
|
||||
|
||||
HVFState *hvf_state;
|
||||
|
||||
static void assert_hvf_ok(hv_return_t ret)
|
||||
{
|
||||
if (ret == HV_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (ret) {
|
||||
case HV_ERROR:
|
||||
error_report("Error: HV_ERROR");
|
||||
break;
|
||||
case HV_BUSY:
|
||||
error_report("Error: HV_BUSY");
|
||||
break;
|
||||
case HV_BAD_ARGUMENT:
|
||||
error_report("Error: HV_BAD_ARGUMENT");
|
||||
break;
|
||||
case HV_NO_RESOURCES:
|
||||
error_report("Error: HV_NO_RESOURCES");
|
||||
break;
|
||||
case HV_NO_DEVICE:
|
||||
error_report("Error: HV_NO_DEVICE");
|
||||
break;
|
||||
case HV_UNSUPPORTED:
|
||||
error_report("Error: HV_UNSUPPORTED");
|
||||
break;
|
||||
default:
|
||||
error_report("Unknown Error");
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
/* Memory slots */
|
||||
hvf_slot *hvf_find_overlap_slot(uint64_t start, uint64_t size)
|
||||
{
|
||||
hvf_slot *slot;
|
||||
int x;
|
||||
for (x = 0; x < hvf_state->num_slots; ++x) {
|
||||
slot = &hvf_state->slots[x];
|
||||
if (slot->size && start < (slot->start + slot->size) &&
|
||||
(start + size) > slot->start) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mac_slot {
|
||||
int present;
|
||||
uint64_t size;
|
||||
uint64_t gpa_start;
|
||||
uint64_t gva;
|
||||
};
|
||||
|
||||
struct mac_slot mac_slots[32];
|
||||
|
||||
static int do_hvf_set_memory(hvf_slot *slot, hv_memory_flags_t flags)
|
||||
{
|
||||
struct mac_slot *macslot;
|
||||
hv_return_t ret;
|
||||
|
||||
macslot = &mac_slots[slot->slot_id];
|
||||
|
||||
if (macslot->present) {
|
||||
if (macslot->size != slot->size) {
|
||||
macslot->present = 0;
|
||||
ret = hv_vm_unmap(macslot->gpa_start, macslot->size);
|
||||
assert_hvf_ok(ret);
|
||||
}
|
||||
}
|
||||
|
||||
if (!slot->size) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
macslot->present = 1;
|
||||
macslot->gpa_start = slot->start;
|
||||
macslot->size = slot->size;
|
||||
ret = hv_vm_map((hv_uvaddr_t)slot->mem, slot->start, slot->size, flags);
|
||||
assert_hvf_ok(ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hvf_set_phys_mem(MemoryRegionSection *section, bool add)
|
||||
{
|
||||
hvf_slot *mem;
|
||||
MemoryRegion *area = section->mr;
|
||||
bool writeable = !area->readonly && !area->rom_device;
|
||||
hv_memory_flags_t flags;
|
||||
|
||||
if (!memory_region_is_ram(area)) {
|
||||
if (writeable) {
|
||||
return;
|
||||
} else if (!memory_region_is_romd(area)) {
|
||||
/*
|
||||
* If the memory device is not in romd_mode, then we actually want
|
||||
* to remove the hvf memory slot so all accesses will trap.
|
||||
*/
|
||||
add = false;
|
||||
}
|
||||
}
|
||||
|
||||
mem = hvf_find_overlap_slot(
|
||||
section->offset_within_address_space,
|
||||
int128_get64(section->size));
|
||||
|
||||
if (mem && add) {
|
||||
if (mem->size == int128_get64(section->size) &&
|
||||
mem->start == section->offset_within_address_space &&
|
||||
mem->mem == (memory_region_get_ram_ptr(area) +
|
||||
section->offset_within_region)) {
|
||||
return; /* Same region was attempted to register, go away. */
|
||||
}
|
||||
}
|
||||
|
||||
/* Region needs to be reset. set the size to 0 and remap it. */
|
||||
if (mem) {
|
||||
mem->size = 0;
|
||||
if (do_hvf_set_memory(mem, 0)) {
|
||||
error_report("Failed to reset overlapping slot");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
if (!add) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (area->readonly ||
|
||||
(!memory_region_is_ram(area) && memory_region_is_romd(area))) {
|
||||
flags = HV_MEMORY_READ | HV_MEMORY_EXEC;
|
||||
} else {
|
||||
flags = HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC;
|
||||
}
|
||||
|
||||
/* Now make a new slot. */
|
||||
int x;
|
||||
|
||||
for (x = 0; x < hvf_state->num_slots; ++x) {
|
||||
mem = &hvf_state->slots[x];
|
||||
if (!mem->size) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (x == hvf_state->num_slots) {
|
||||
error_report("No free slots");
|
||||
abort();
|
||||
}
|
||||
|
||||
mem->size = int128_get64(section->size);
|
||||
mem->mem = memory_region_get_ram_ptr(area) + section->offset_within_region;
|
||||
mem->start = section->offset_within_address_space;
|
||||
mem->region = area;
|
||||
|
||||
if (do_hvf_set_memory(mem, flags)) {
|
||||
error_report("Error registering new memory slot");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
void vmx_update_tpr(CPUState *cpu)
|
||||
{
|
||||
/* TODO: need integrate APIC handling */
|
||||
@@ -244,11 +80,11 @@ void vmx_update_tpr(CPUState *cpu)
|
||||
int tpr = cpu_get_apic_tpr(x86_cpu->apic_state) << 4;
|
||||
int irr = apic_get_highest_priority_irr(x86_cpu->apic_state);
|
||||
|
||||
wreg(cpu->hvf_fd, HV_X86_TPR, tpr);
|
||||
wreg(cpu->hvf->fd, HV_X86_TPR, tpr);
|
||||
if (irr == -1) {
|
||||
wvmcs(cpu->hvf_fd, VMCS_TPR_THRESHOLD, 0);
|
||||
wvmcs(cpu->hvf->fd, VMCS_TPR_THRESHOLD, 0);
|
||||
} else {
|
||||
wvmcs(cpu->hvf_fd, VMCS_TPR_THRESHOLD, (irr > tpr) ? tpr >> 4 :
|
||||
wvmcs(cpu->hvf->fd, VMCS_TPR_THRESHOLD, (irr > tpr) ? tpr >> 4 :
|
||||
irr >> 4);
|
||||
}
|
||||
}
|
||||
@@ -256,7 +92,7 @@ void vmx_update_tpr(CPUState *cpu)
|
||||
static void update_apic_tpr(CPUState *cpu)
|
||||
{
|
||||
X86CPU *x86_cpu = X86_CPU(cpu);
|
||||
int tpr = rreg(cpu->hvf_fd, HV_X86_TPR) >> 4;
|
||||
int tpr = rreg(cpu->hvf->fd, HV_X86_TPR) >> 4;
|
||||
cpu_set_apic_tpr(x86_cpu->apic_state, tpr);
|
||||
}
|
||||
|
||||
@@ -276,56 +112,6 @@ void hvf_handle_io(CPUArchState *env, uint16_t port, void *buffer,
|
||||
}
|
||||
}
|
||||
|
||||
static void do_hvf_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg)
|
||||
{
|
||||
if (!cpu->vcpu_dirty) {
|
||||
hvf_get_registers(cpu);
|
||||
cpu->vcpu_dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void hvf_cpu_synchronize_state(CPUState *cpu)
|
||||
{
|
||||
if (!cpu->vcpu_dirty) {
|
||||
run_on_cpu(cpu, do_hvf_cpu_synchronize_state, RUN_ON_CPU_NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void do_hvf_cpu_synchronize_post_reset(CPUState *cpu,
|
||||
run_on_cpu_data arg)
|
||||
{
|
||||
hvf_put_registers(cpu);
|
||||
cpu->vcpu_dirty = false;
|
||||
}
|
||||
|
||||
void hvf_cpu_synchronize_post_reset(CPUState *cpu)
|
||||
{
|
||||
run_on_cpu(cpu, do_hvf_cpu_synchronize_post_reset, RUN_ON_CPU_NULL);
|
||||
}
|
||||
|
||||
static void do_hvf_cpu_synchronize_post_init(CPUState *cpu,
|
||||
run_on_cpu_data arg)
|
||||
{
|
||||
hvf_put_registers(cpu);
|
||||
cpu->vcpu_dirty = false;
|
||||
}
|
||||
|
||||
void hvf_cpu_synchronize_post_init(CPUState *cpu)
|
||||
{
|
||||
run_on_cpu(cpu, do_hvf_cpu_synchronize_post_init, RUN_ON_CPU_NULL);
|
||||
}
|
||||
|
||||
static void do_hvf_cpu_synchronize_pre_loadvm(CPUState *cpu,
|
||||
run_on_cpu_data arg)
|
||||
{
|
||||
cpu->vcpu_dirty = true;
|
||||
}
|
||||
|
||||
void hvf_cpu_synchronize_pre_loadvm(CPUState *cpu)
|
||||
{
|
||||
run_on_cpu(cpu, do_hvf_cpu_synchronize_pre_loadvm, RUN_ON_CPU_NULL);
|
||||
}
|
||||
|
||||
static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual)
|
||||
{
|
||||
int read, write;
|
||||
@@ -370,109 +156,19 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual)
|
||||
return false;
|
||||
}
|
||||
|
||||
static void hvf_set_dirty_tracking(MemoryRegionSection *section, bool on)
|
||||
{
|
||||
hvf_slot *slot;
|
||||
|
||||
slot = hvf_find_overlap_slot(
|
||||
section->offset_within_address_space,
|
||||
int128_get64(section->size));
|
||||
|
||||
/* protect region against writes; begin tracking it */
|
||||
if (on) {
|
||||
slot->flags |= HVF_SLOT_LOG;
|
||||
hv_vm_protect((hv_gpaddr_t)slot->start, (size_t)slot->size,
|
||||
HV_MEMORY_READ);
|
||||
/* stop tracking region*/
|
||||
} else {
|
||||
slot->flags &= ~HVF_SLOT_LOG;
|
||||
hv_vm_protect((hv_gpaddr_t)slot->start, (size_t)slot->size,
|
||||
HV_MEMORY_READ | HV_MEMORY_WRITE);
|
||||
}
|
||||
}
|
||||
|
||||
static void hvf_log_start(MemoryListener *listener,
|
||||
MemoryRegionSection *section, int old, int new)
|
||||
{
|
||||
if (old != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
hvf_set_dirty_tracking(section, 1);
|
||||
}
|
||||
|
||||
static void hvf_log_stop(MemoryListener *listener,
|
||||
MemoryRegionSection *section, int old, int new)
|
||||
{
|
||||
if (new != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
hvf_set_dirty_tracking(section, 0);
|
||||
}
|
||||
|
||||
static void hvf_log_sync(MemoryListener *listener,
|
||||
MemoryRegionSection *section)
|
||||
{
|
||||
/*
|
||||
* sync of dirty pages is handled elsewhere; just make sure we keep
|
||||
* tracking the region.
|
||||
*/
|
||||
hvf_set_dirty_tracking(section, 1);
|
||||
}
|
||||
|
||||
static void hvf_region_add(MemoryListener *listener,
|
||||
MemoryRegionSection *section)
|
||||
{
|
||||
hvf_set_phys_mem(section, true);
|
||||
}
|
||||
|
||||
static void hvf_region_del(MemoryListener *listener,
|
||||
MemoryRegionSection *section)
|
||||
{
|
||||
hvf_set_phys_mem(section, false);
|
||||
}
|
||||
|
||||
static MemoryListener hvf_memory_listener = {
|
||||
.priority = 10,
|
||||
.region_add = hvf_region_add,
|
||||
.region_del = hvf_region_del,
|
||||
.log_start = hvf_log_start,
|
||||
.log_stop = hvf_log_stop,
|
||||
.log_sync = hvf_log_sync,
|
||||
};
|
||||
|
||||
void hvf_vcpu_destroy(CPUState *cpu)
|
||||
void hvf_arch_vcpu_destroy(CPUState *cpu)
|
||||
{
|
||||
X86CPU *x86_cpu = X86_CPU(cpu);
|
||||
CPUX86State *env = &x86_cpu->env;
|
||||
|
||||
hv_return_t ret = hv_vcpu_destroy((hv_vcpuid_t)cpu->hvf_fd);
|
||||
g_free(env->hvf_mmio_buf);
|
||||
assert_hvf_ok(ret);
|
||||
}
|
||||
|
||||
static void dummy_signal(int sig)
|
||||
{
|
||||
}
|
||||
|
||||
int hvf_init_vcpu(CPUState *cpu)
|
||||
int hvf_arch_init_vcpu(CPUState *cpu)
|
||||
{
|
||||
|
||||
X86CPU *x86cpu = X86_CPU(cpu);
|
||||
CPUX86State *env = &x86cpu->env;
|
||||
int r;
|
||||
|
||||
/* init cpu signals */
|
||||
sigset_t set;
|
||||
struct sigaction sigact;
|
||||
|
||||
memset(&sigact, 0, sizeof(sigact));
|
||||
sigact.sa_handler = dummy_signal;
|
||||
sigaction(SIG_IPI, &sigact, NULL);
|
||||
|
||||
pthread_sigmask(SIG_BLOCK, NULL, &set);
|
||||
sigdelset(&set, SIG_IPI);
|
||||
|
||||
init_emu();
|
||||
init_decoder();
|
||||
@@ -480,10 +176,6 @@ int hvf_init_vcpu(CPUState *cpu)
|
||||
hvf_state->hvf_caps = g_new0(struct hvf_vcpu_caps, 1);
|
||||
env->hvf_mmio_buf = g_new(char, 4096);
|
||||
|
||||
r = hv_vcpu_create((hv_vcpuid_t *)&cpu->hvf_fd, HV_VCPU_DEFAULT);
|
||||
cpu->vcpu_dirty = 1;
|
||||
assert_hvf_ok(r);
|
||||
|
||||
if (hv_vmx_read_capability(HV_VMX_CAP_PINBASED,
|
||||
&hvf_state->hvf_caps->vmx_cap_pinbased)) {
|
||||
abort();
|
||||
@@ -502,43 +194,43 @@ int hvf_init_vcpu(CPUState *cpu)
|
||||
}
|
||||
|
||||
/* set VMCS control fields */
|
||||
wvmcs(cpu->hvf_fd, VMCS_PIN_BASED_CTLS,
|
||||
wvmcs(cpu->hvf->fd, VMCS_PIN_BASED_CTLS,
|
||||
cap2ctrl(hvf_state->hvf_caps->vmx_cap_pinbased,
|
||||
VMCS_PIN_BASED_CTLS_EXTINT |
|
||||
VMCS_PIN_BASED_CTLS_NMI |
|
||||
VMCS_PIN_BASED_CTLS_VNMI));
|
||||
wvmcs(cpu->hvf_fd, VMCS_PRI_PROC_BASED_CTLS,
|
||||
wvmcs(cpu->hvf->fd, VMCS_PRI_PROC_BASED_CTLS,
|
||||
cap2ctrl(hvf_state->hvf_caps->vmx_cap_procbased,
|
||||
VMCS_PRI_PROC_BASED_CTLS_HLT |
|
||||
VMCS_PRI_PROC_BASED_CTLS_MWAIT |
|
||||
VMCS_PRI_PROC_BASED_CTLS_TSC_OFFSET |
|
||||
VMCS_PRI_PROC_BASED_CTLS_TPR_SHADOW) |
|
||||
VMCS_PRI_PROC_BASED_CTLS_SEC_CONTROL);
|
||||
wvmcs(cpu->hvf_fd, VMCS_SEC_PROC_BASED_CTLS,
|
||||
wvmcs(cpu->hvf->fd, VMCS_SEC_PROC_BASED_CTLS,
|
||||
cap2ctrl(hvf_state->hvf_caps->vmx_cap_procbased2,
|
||||
VMCS_PRI_PROC_BASED2_CTLS_APIC_ACCESSES));
|
||||
|
||||
wvmcs(cpu->hvf_fd, VMCS_ENTRY_CTLS, cap2ctrl(hvf_state->hvf_caps->vmx_cap_entry,
|
||||
wvmcs(cpu->hvf->fd, VMCS_ENTRY_CTLS, cap2ctrl(hvf_state->hvf_caps->vmx_cap_entry,
|
||||
0));
|
||||
wvmcs(cpu->hvf_fd, VMCS_EXCEPTION_BITMAP, 0); /* Double fault */
|
||||
wvmcs(cpu->hvf->fd, VMCS_EXCEPTION_BITMAP, 0); /* Double fault */
|
||||
|
||||
wvmcs(cpu->hvf_fd, VMCS_TPR_THRESHOLD, 0);
|
||||
wvmcs(cpu->hvf->fd, VMCS_TPR_THRESHOLD, 0);
|
||||
|
||||
x86cpu = X86_CPU(cpu);
|
||||
x86cpu->env.xsave_buf = qemu_memalign(4096, 4096);
|
||||
|
||||
hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_STAR, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_LSTAR, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_CSTAR, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_FMASK, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_FSBASE, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_GSBASE, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_KERNELGSBASE, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_TSC_AUX, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_IA32_TSC, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_IA32_SYSENTER_CS, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_IA32_SYSENTER_EIP, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf_fd, MSR_IA32_SYSENTER_ESP, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf->fd, MSR_STAR, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf->fd, MSR_LSTAR, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf->fd, MSR_CSTAR, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf->fd, MSR_FMASK, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf->fd, MSR_FSBASE, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf->fd, MSR_GSBASE, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf->fd, MSR_KERNELGSBASE, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf->fd, MSR_TSC_AUX, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf->fd, MSR_IA32_TSC, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf->fd, MSR_IA32_SYSENTER_CS, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf->fd, MSR_IA32_SYSENTER_EIP, 1);
|
||||
hv_vcpu_enable_native_msr(cpu->hvf->fd, MSR_IA32_SYSENTER_ESP, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -579,16 +271,16 @@ static void hvf_store_events(CPUState *cpu, uint32_t ins_len, uint64_t idtvec_in
|
||||
}
|
||||
if (idtvec_info & VMCS_IDT_VEC_ERRCODE_VALID) {
|
||||
env->has_error_code = true;
|
||||
env->error_code = rvmcs(cpu->hvf_fd, VMCS_IDT_VECTORING_ERROR);
|
||||
env->error_code = rvmcs(cpu->hvf->fd, VMCS_IDT_VECTORING_ERROR);
|
||||
}
|
||||
}
|
||||
if ((rvmcs(cpu->hvf_fd, VMCS_GUEST_INTERRUPTIBILITY) &
|
||||
if ((rvmcs(cpu->hvf->fd, VMCS_GUEST_INTERRUPTIBILITY) &
|
||||
VMCS_INTERRUPTIBILITY_NMI_BLOCKING)) {
|
||||
env->hflags2 |= HF2_NMI_MASK;
|
||||
} else {
|
||||
env->hflags2 &= ~HF2_NMI_MASK;
|
||||
}
|
||||
if (rvmcs(cpu->hvf_fd, VMCS_GUEST_INTERRUPTIBILITY) &
|
||||
if (rvmcs(cpu->hvf->fd, VMCS_GUEST_INTERRUPTIBILITY) &
|
||||
(VMCS_INTERRUPTIBILITY_STI_BLOCKING |
|
||||
VMCS_INTERRUPTIBILITY_MOVSS_BLOCKING)) {
|
||||
env->hflags |= HF_INHIBIT_IRQ_MASK;
|
||||
@@ -625,20 +317,20 @@ int hvf_vcpu_exec(CPUState *cpu)
|
||||
return EXCP_HLT;
|
||||
}
|
||||
|
||||
hv_return_t r = hv_vcpu_run(cpu->hvf_fd);
|
||||
hv_return_t r = hv_vcpu_run(cpu->hvf->fd);
|
||||
assert_hvf_ok(r);
|
||||
|
||||
/* handle VMEXIT */
|
||||
uint64_t exit_reason = rvmcs(cpu->hvf_fd, VMCS_EXIT_REASON);
|
||||
uint64_t exit_qual = rvmcs(cpu->hvf_fd, VMCS_EXIT_QUALIFICATION);
|
||||
uint32_t ins_len = (uint32_t)rvmcs(cpu->hvf_fd,
|
||||
uint64_t exit_reason = rvmcs(cpu->hvf->fd, VMCS_EXIT_REASON);
|
||||
uint64_t exit_qual = rvmcs(cpu->hvf->fd, VMCS_EXIT_QUALIFICATION);
|
||||
uint32_t ins_len = (uint32_t)rvmcs(cpu->hvf->fd,
|
||||
VMCS_EXIT_INSTRUCTION_LENGTH);
|
||||
|
||||
uint64_t idtvec_info = rvmcs(cpu->hvf_fd, VMCS_IDT_VECTORING_INFO);
|
||||
uint64_t idtvec_info = rvmcs(cpu->hvf->fd, VMCS_IDT_VECTORING_INFO);
|
||||
|
||||
hvf_store_events(cpu, ins_len, idtvec_info);
|
||||
rip = rreg(cpu->hvf_fd, HV_X86_RIP);
|
||||
env->eflags = rreg(cpu->hvf_fd, HV_X86_RFLAGS);
|
||||
rip = rreg(cpu->hvf->fd, HV_X86_RIP);
|
||||
env->eflags = rreg(cpu->hvf->fd, HV_X86_RFLAGS);
|
||||
|
||||
qemu_mutex_lock_iothread();
|
||||
|
||||
@@ -668,7 +360,7 @@ int hvf_vcpu_exec(CPUState *cpu)
|
||||
case EXIT_REASON_EPT_FAULT:
|
||||
{
|
||||
hvf_slot *slot;
|
||||
uint64_t gpa = rvmcs(cpu->hvf_fd, VMCS_GUEST_PHYSICAL_ADDRESS);
|
||||
uint64_t gpa = rvmcs(cpu->hvf->fd, VMCS_GUEST_PHYSICAL_ADDRESS);
|
||||
|
||||
if (((idtvec_info & VMCS_IDT_VEC_VALID) == 0) &&
|
||||
((exit_qual & EXIT_QUAL_NMIUDTI) != 0)) {
|
||||
@@ -713,7 +405,7 @@ int hvf_vcpu_exec(CPUState *cpu)
|
||||
store_regs(cpu);
|
||||
break;
|
||||
} else if (!string && !in) {
|
||||
RAX(env) = rreg(cpu->hvf_fd, HV_X86_RAX);
|
||||
RAX(env) = rreg(cpu->hvf->fd, HV_X86_RAX);
|
||||
hvf_handle_io(env, port, &RAX(env), 1, size, 1);
|
||||
macvm_set_rip(cpu, rip + ins_len);
|
||||
break;
|
||||
@@ -729,17 +421,17 @@ int hvf_vcpu_exec(CPUState *cpu)
|
||||
break;
|
||||
}
|
||||
case EXIT_REASON_CPUID: {
|
||||
uint32_t rax = (uint32_t)rreg(cpu->hvf_fd, HV_X86_RAX);
|
||||
uint32_t rbx = (uint32_t)rreg(cpu->hvf_fd, HV_X86_RBX);
|
||||
uint32_t rcx = (uint32_t)rreg(cpu->hvf_fd, HV_X86_RCX);
|
||||
uint32_t rdx = (uint32_t)rreg(cpu->hvf_fd, HV_X86_RDX);
|
||||
uint32_t rax = (uint32_t)rreg(cpu->hvf->fd, HV_X86_RAX);
|
||||
uint32_t rbx = (uint32_t)rreg(cpu->hvf->fd, HV_X86_RBX);
|
||||
uint32_t rcx = (uint32_t)rreg(cpu->hvf->fd, HV_X86_RCX);
|
||||
uint32_t rdx = (uint32_t)rreg(cpu->hvf->fd, HV_X86_RDX);
|
||||
|
||||
cpu_x86_cpuid(env, rax, rcx, &rax, &rbx, &rcx, &rdx);
|
||||
|
||||
wreg(cpu->hvf_fd, HV_X86_RAX, rax);
|
||||
wreg(cpu->hvf_fd, HV_X86_RBX, rbx);
|
||||
wreg(cpu->hvf_fd, HV_X86_RCX, rcx);
|
||||
wreg(cpu->hvf_fd, HV_X86_RDX, rdx);
|
||||
wreg(cpu->hvf->fd, HV_X86_RAX, rax);
|
||||
wreg(cpu->hvf->fd, HV_X86_RBX, rbx);
|
||||
wreg(cpu->hvf->fd, HV_X86_RCX, rcx);
|
||||
wreg(cpu->hvf->fd, HV_X86_RDX, rdx);
|
||||
|
||||
macvm_set_rip(cpu, rip + ins_len);
|
||||
break;
|
||||
@@ -747,16 +439,16 @@ int hvf_vcpu_exec(CPUState *cpu)
|
||||
case EXIT_REASON_XSETBV: {
|
||||
X86CPU *x86_cpu = X86_CPU(cpu);
|
||||
CPUX86State *env = &x86_cpu->env;
|
||||
uint32_t eax = (uint32_t)rreg(cpu->hvf_fd, HV_X86_RAX);
|
||||
uint32_t ecx = (uint32_t)rreg(cpu->hvf_fd, HV_X86_RCX);
|
||||
uint32_t edx = (uint32_t)rreg(cpu->hvf_fd, HV_X86_RDX);
|
||||
uint32_t eax = (uint32_t)rreg(cpu->hvf->fd, HV_X86_RAX);
|
||||
uint32_t ecx = (uint32_t)rreg(cpu->hvf->fd, HV_X86_RCX);
|
||||
uint32_t edx = (uint32_t)rreg(cpu->hvf->fd, HV_X86_RDX);
|
||||
|
||||
if (ecx) {
|
||||
macvm_set_rip(cpu, rip + ins_len);
|
||||
break;
|
||||
}
|
||||
env->xcr0 = ((uint64_t)edx << 32) | eax;
|
||||
wreg(cpu->hvf_fd, HV_X86_XCR0, env->xcr0 | 1);
|
||||
wreg(cpu->hvf->fd, HV_X86_XCR0, env->xcr0 | 1);
|
||||
macvm_set_rip(cpu, rip + ins_len);
|
||||
break;
|
||||
}
|
||||
@@ -795,11 +487,11 @@ int hvf_vcpu_exec(CPUState *cpu)
|
||||
|
||||
switch (cr) {
|
||||
case 0x0: {
|
||||
macvm_set_cr0(cpu->hvf_fd, RRX(env, reg));
|
||||
macvm_set_cr0(cpu->hvf->fd, RRX(env, reg));
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
macvm_set_cr4(cpu->hvf_fd, RRX(env, reg));
|
||||
macvm_set_cr4(cpu->hvf->fd, RRX(env, reg));
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
@@ -835,7 +527,7 @@ int hvf_vcpu_exec(CPUState *cpu)
|
||||
break;
|
||||
}
|
||||
case EXIT_REASON_TASK_SWITCH: {
|
||||
uint64_t vinfo = rvmcs(cpu->hvf_fd, VMCS_IDT_VECTORING_INFO);
|
||||
uint64_t vinfo = rvmcs(cpu->hvf->fd, VMCS_IDT_VECTORING_INFO);
|
||||
x68_segment_selector sel = {.sel = exit_qual & 0xffff};
|
||||
vmx_handle_task_switch(cpu, sel, (exit_qual >> 30) & 0x3,
|
||||
vinfo & VMCS_INTR_VALID, vinfo & VECTORING_INFO_VECTOR_MASK, vinfo
|
||||
@@ -848,8 +540,8 @@ int hvf_vcpu_exec(CPUState *cpu)
|
||||
break;
|
||||
}
|
||||
case EXIT_REASON_RDPMC:
|
||||
wreg(cpu->hvf_fd, HV_X86_RAX, 0);
|
||||
wreg(cpu->hvf_fd, HV_X86_RDX, 0);
|
||||
wreg(cpu->hvf->fd, HV_X86_RAX, 0);
|
||||
wreg(cpu->hvf->fd, HV_X86_RDX, 0);
|
||||
macvm_set_rip(cpu, rip + ins_len);
|
||||
break;
|
||||
case VMX_REASON_VMCALL:
|
||||
@@ -865,49 +557,3 @@ int hvf_vcpu_exec(CPUState *cpu)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool hvf_allowed;
|
||||
|
||||
static int hvf_accel_init(MachineState *ms)
|
||||
{
|
||||
int x;
|
||||
hv_return_t ret;
|
||||
HVFState *s;
|
||||
|
||||
ret = hv_vm_create(HV_VM_DEFAULT);
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
s = g_new0(HVFState, 1);
|
||||
|
||||
s->num_slots = 32;
|
||||
for (x = 0; x < s->num_slots; ++x) {
|
||||
s->slots[x].size = 0;
|
||||
s->slots[x].slot_id = x;
|
||||
}
|
||||
|
||||
hvf_state = s;
|
||||
memory_listener_register(&hvf_memory_listener, &address_space_memory);
|
||||
cpus_register_accel(&hvf_cpus);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void hvf_accel_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
AccelClass *ac = ACCEL_CLASS(oc);
|
||||
ac->name = "HVF";
|
||||
ac->init_machine = hvf_accel_init;
|
||||
ac->allowed = &hvf_allowed;
|
||||
}
|
||||
|
||||
static const TypeInfo hvf_accel_type = {
|
||||
.name = TYPE_HVF_ACCEL,
|
||||
.parent = TYPE_ACCEL,
|
||||
.class_init = hvf_accel_class_init,
|
||||
};
|
||||
|
||||
static void hvf_type_init(void)
|
||||
{
|
||||
type_register_static(&hvf_accel_type);
|
||||
}
|
||||
|
||||
type_init(hvf_type_init);
|
||||
@@ -1,6 +1,5 @@
|
||||
i386_softmmu_ss.add(when: [hvf, 'CONFIG_HVF'], if_true: files(
|
||||
'hvf.c',
|
||||
'hvf-cpus.c',
|
||||
'x86.c',
|
||||
'x86_cpuid.c',
|
||||
'x86_decode.c',
|
||||
|
||||
+13
-11
@@ -30,6 +30,8 @@
|
||||
#include "vmcs.h"
|
||||
#include "cpu.h"
|
||||
#include "x86.h"
|
||||
#include "sysemu/hvf.h"
|
||||
#include "sysemu/hvf_int.h"
|
||||
|
||||
#include "exec/address-spaces.h"
|
||||
|
||||
@@ -179,15 +181,15 @@ static inline void macvm_set_rip(CPUState *cpu, uint64_t rip)
|
||||
uint64_t val;
|
||||
|
||||
/* BUG, should take considering overlap.. */
|
||||
wreg(cpu->hvf_fd, HV_X86_RIP, rip);
|
||||
wreg(cpu->hvf->fd, HV_X86_RIP, rip);
|
||||
env->eip = rip;
|
||||
|
||||
/* after moving forward in rip, we need to clean INTERRUPTABILITY */
|
||||
val = rvmcs(cpu->hvf_fd, VMCS_GUEST_INTERRUPTIBILITY);
|
||||
val = rvmcs(cpu->hvf->fd, VMCS_GUEST_INTERRUPTIBILITY);
|
||||
if (val & (VMCS_INTERRUPTIBILITY_STI_BLOCKING |
|
||||
VMCS_INTERRUPTIBILITY_MOVSS_BLOCKING)) {
|
||||
env->hflags &= ~HF_INHIBIT_IRQ_MASK;
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_INTERRUPTIBILITY,
|
||||
wvmcs(cpu->hvf->fd, VMCS_GUEST_INTERRUPTIBILITY,
|
||||
val & ~(VMCS_INTERRUPTIBILITY_STI_BLOCKING |
|
||||
VMCS_INTERRUPTIBILITY_MOVSS_BLOCKING));
|
||||
}
|
||||
@@ -199,9 +201,9 @@ static inline void vmx_clear_nmi_blocking(CPUState *cpu)
|
||||
CPUX86State *env = &x86_cpu->env;
|
||||
|
||||
env->hflags2 &= ~HF2_NMI_MASK;
|
||||
uint32_t gi = (uint32_t) rvmcs(cpu->hvf_fd, VMCS_GUEST_INTERRUPTIBILITY);
|
||||
uint32_t gi = (uint32_t) rvmcs(cpu->hvf->fd, VMCS_GUEST_INTERRUPTIBILITY);
|
||||
gi &= ~VMCS_INTERRUPTIBILITY_NMI_BLOCKING;
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_INTERRUPTIBILITY, gi);
|
||||
wvmcs(cpu->hvf->fd, VMCS_GUEST_INTERRUPTIBILITY, gi);
|
||||
}
|
||||
|
||||
static inline void vmx_set_nmi_blocking(CPUState *cpu)
|
||||
@@ -210,16 +212,16 @@ static inline void vmx_set_nmi_blocking(CPUState *cpu)
|
||||
CPUX86State *env = &x86_cpu->env;
|
||||
|
||||
env->hflags2 |= HF2_NMI_MASK;
|
||||
uint32_t gi = (uint32_t)rvmcs(cpu->hvf_fd, VMCS_GUEST_INTERRUPTIBILITY);
|
||||
uint32_t gi = (uint32_t)rvmcs(cpu->hvf->fd, VMCS_GUEST_INTERRUPTIBILITY);
|
||||
gi |= VMCS_INTERRUPTIBILITY_NMI_BLOCKING;
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_INTERRUPTIBILITY, gi);
|
||||
wvmcs(cpu->hvf->fd, VMCS_GUEST_INTERRUPTIBILITY, gi);
|
||||
}
|
||||
|
||||
static inline void vmx_set_nmi_window_exiting(CPUState *cpu)
|
||||
{
|
||||
uint64_t val;
|
||||
val = rvmcs(cpu->hvf_fd, VMCS_PRI_PROC_BASED_CTLS);
|
||||
wvmcs(cpu->hvf_fd, VMCS_PRI_PROC_BASED_CTLS, val |
|
||||
val = rvmcs(cpu->hvf->fd, VMCS_PRI_PROC_BASED_CTLS);
|
||||
wvmcs(cpu->hvf->fd, VMCS_PRI_PROC_BASED_CTLS, val |
|
||||
VMCS_PRI_PROC_BASED_CTLS_NMI_WINDOW_EXITING);
|
||||
|
||||
}
|
||||
@@ -228,8 +230,8 @@ static inline void vmx_clear_nmi_window_exiting(CPUState *cpu)
|
||||
{
|
||||
|
||||
uint64_t val;
|
||||
val = rvmcs(cpu->hvf_fd, VMCS_PRI_PROC_BASED_CTLS);
|
||||
wvmcs(cpu->hvf_fd, VMCS_PRI_PROC_BASED_CTLS, val &
|
||||
val = rvmcs(cpu->hvf->fd, VMCS_PRI_PROC_BASED_CTLS);
|
||||
wvmcs(cpu->hvf->fd, VMCS_PRI_PROC_BASED_CTLS, val &
|
||||
~VMCS_PRI_PROC_BASED_CTLS_NMI_WINDOW_EXITING);
|
||||
}
|
||||
|
||||
|
||||
+14
-14
@@ -62,11 +62,11 @@ bool x86_read_segment_descriptor(struct CPUState *cpu,
|
||||
}
|
||||
|
||||
if (GDT_SEL == sel.ti) {
|
||||
base = rvmcs(cpu->hvf_fd, VMCS_GUEST_GDTR_BASE);
|
||||
limit = rvmcs(cpu->hvf_fd, VMCS_GUEST_GDTR_LIMIT);
|
||||
base = rvmcs(cpu->hvf->fd, VMCS_GUEST_GDTR_BASE);
|
||||
limit = rvmcs(cpu->hvf->fd, VMCS_GUEST_GDTR_LIMIT);
|
||||
} else {
|
||||
base = rvmcs(cpu->hvf_fd, VMCS_GUEST_LDTR_BASE);
|
||||
limit = rvmcs(cpu->hvf_fd, VMCS_GUEST_LDTR_LIMIT);
|
||||
base = rvmcs(cpu->hvf->fd, VMCS_GUEST_LDTR_BASE);
|
||||
limit = rvmcs(cpu->hvf->fd, VMCS_GUEST_LDTR_LIMIT);
|
||||
}
|
||||
|
||||
if (sel.index * 8 >= limit) {
|
||||
@@ -85,11 +85,11 @@ bool x86_write_segment_descriptor(struct CPUState *cpu,
|
||||
uint32_t limit;
|
||||
|
||||
if (GDT_SEL == sel.ti) {
|
||||
base = rvmcs(cpu->hvf_fd, VMCS_GUEST_GDTR_BASE);
|
||||
limit = rvmcs(cpu->hvf_fd, VMCS_GUEST_GDTR_LIMIT);
|
||||
base = rvmcs(cpu->hvf->fd, VMCS_GUEST_GDTR_BASE);
|
||||
limit = rvmcs(cpu->hvf->fd, VMCS_GUEST_GDTR_LIMIT);
|
||||
} else {
|
||||
base = rvmcs(cpu->hvf_fd, VMCS_GUEST_LDTR_BASE);
|
||||
limit = rvmcs(cpu->hvf_fd, VMCS_GUEST_LDTR_LIMIT);
|
||||
base = rvmcs(cpu->hvf->fd, VMCS_GUEST_LDTR_BASE);
|
||||
limit = rvmcs(cpu->hvf->fd, VMCS_GUEST_LDTR_LIMIT);
|
||||
}
|
||||
|
||||
if (sel.index * 8 >= limit) {
|
||||
@@ -103,8 +103,8 @@ bool x86_write_segment_descriptor(struct CPUState *cpu,
|
||||
bool x86_read_call_gate(struct CPUState *cpu, struct x86_call_gate *idt_desc,
|
||||
int gate)
|
||||
{
|
||||
target_ulong base = rvmcs(cpu->hvf_fd, VMCS_GUEST_IDTR_BASE);
|
||||
uint32_t limit = rvmcs(cpu->hvf_fd, VMCS_GUEST_IDTR_LIMIT);
|
||||
target_ulong base = rvmcs(cpu->hvf->fd, VMCS_GUEST_IDTR_BASE);
|
||||
uint32_t limit = rvmcs(cpu->hvf->fd, VMCS_GUEST_IDTR_LIMIT);
|
||||
|
||||
memset(idt_desc, 0, sizeof(*idt_desc));
|
||||
if (gate * 8 >= limit) {
|
||||
@@ -118,7 +118,7 @@ bool x86_read_call_gate(struct CPUState *cpu, struct x86_call_gate *idt_desc,
|
||||
|
||||
bool x86_is_protected(struct CPUState *cpu)
|
||||
{
|
||||
uint64_t cr0 = rvmcs(cpu->hvf_fd, VMCS_GUEST_CR0);
|
||||
uint64_t cr0 = rvmcs(cpu->hvf->fd, VMCS_GUEST_CR0);
|
||||
return cr0 & CR0_PE;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ bool x86_is_v8086(struct CPUState *cpu)
|
||||
|
||||
bool x86_is_long_mode(struct CPUState *cpu)
|
||||
{
|
||||
return rvmcs(cpu->hvf_fd, VMCS_GUEST_IA32_EFER) & MSR_EFER_LMA;
|
||||
return rvmcs(cpu->hvf->fd, VMCS_GUEST_IA32_EFER) & MSR_EFER_LMA;
|
||||
}
|
||||
|
||||
bool x86_is_long64_mode(struct CPUState *cpu)
|
||||
@@ -149,13 +149,13 @@ bool x86_is_long64_mode(struct CPUState *cpu)
|
||||
|
||||
bool x86_is_paging_mode(struct CPUState *cpu)
|
||||
{
|
||||
uint64_t cr0 = rvmcs(cpu->hvf_fd, VMCS_GUEST_CR0);
|
||||
uint64_t cr0 = rvmcs(cpu->hvf->fd, VMCS_GUEST_CR0);
|
||||
return cr0 & CR0_PG;
|
||||
}
|
||||
|
||||
bool x86_is_pae_enabled(struct CPUState *cpu)
|
||||
{
|
||||
uint64_t cr4 = rvmcs(cpu->hvf_fd, VMCS_GUEST_CR4);
|
||||
uint64_t cr4 = rvmcs(cpu->hvf->fd, VMCS_GUEST_CR4);
|
||||
return cr4 & CR4_PAE;
|
||||
}
|
||||
|
||||
|
||||
+13
-13
@@ -48,47 +48,47 @@ static const struct vmx_segment_field {
|
||||
|
||||
uint32_t vmx_read_segment_limit(CPUState *cpu, X86Seg seg)
|
||||
{
|
||||
return (uint32_t)rvmcs(cpu->hvf_fd, vmx_segment_fields[seg].limit);
|
||||
return (uint32_t)rvmcs(cpu->hvf->fd, vmx_segment_fields[seg].limit);
|
||||
}
|
||||
|
||||
uint32_t vmx_read_segment_ar(CPUState *cpu, X86Seg seg)
|
||||
{
|
||||
return (uint32_t)rvmcs(cpu->hvf_fd, vmx_segment_fields[seg].ar_bytes);
|
||||
return (uint32_t)rvmcs(cpu->hvf->fd, vmx_segment_fields[seg].ar_bytes);
|
||||
}
|
||||
|
||||
uint64_t vmx_read_segment_base(CPUState *cpu, X86Seg seg)
|
||||
{
|
||||
return rvmcs(cpu->hvf_fd, vmx_segment_fields[seg].base);
|
||||
return rvmcs(cpu->hvf->fd, vmx_segment_fields[seg].base);
|
||||
}
|
||||
|
||||
x68_segment_selector vmx_read_segment_selector(CPUState *cpu, X86Seg seg)
|
||||
{
|
||||
x68_segment_selector sel;
|
||||
sel.sel = rvmcs(cpu->hvf_fd, vmx_segment_fields[seg].selector);
|
||||
sel.sel = rvmcs(cpu->hvf->fd, vmx_segment_fields[seg].selector);
|
||||
return sel;
|
||||
}
|
||||
|
||||
void vmx_write_segment_selector(struct CPUState *cpu, x68_segment_selector selector, X86Seg seg)
|
||||
{
|
||||
wvmcs(cpu->hvf_fd, vmx_segment_fields[seg].selector, selector.sel);
|
||||
wvmcs(cpu->hvf->fd, vmx_segment_fields[seg].selector, selector.sel);
|
||||
}
|
||||
|
||||
void vmx_read_segment_descriptor(struct CPUState *cpu, struct vmx_segment *desc, X86Seg seg)
|
||||
{
|
||||
desc->sel = rvmcs(cpu->hvf_fd, vmx_segment_fields[seg].selector);
|
||||
desc->base = rvmcs(cpu->hvf_fd, vmx_segment_fields[seg].base);
|
||||
desc->limit = rvmcs(cpu->hvf_fd, vmx_segment_fields[seg].limit);
|
||||
desc->ar = rvmcs(cpu->hvf_fd, vmx_segment_fields[seg].ar_bytes);
|
||||
desc->sel = rvmcs(cpu->hvf->fd, vmx_segment_fields[seg].selector);
|
||||
desc->base = rvmcs(cpu->hvf->fd, vmx_segment_fields[seg].base);
|
||||
desc->limit = rvmcs(cpu->hvf->fd, vmx_segment_fields[seg].limit);
|
||||
desc->ar = rvmcs(cpu->hvf->fd, vmx_segment_fields[seg].ar_bytes);
|
||||
}
|
||||
|
||||
void vmx_write_segment_descriptor(CPUState *cpu, struct vmx_segment *desc, X86Seg seg)
|
||||
{
|
||||
const struct vmx_segment_field *sf = &vmx_segment_fields[seg];
|
||||
|
||||
wvmcs(cpu->hvf_fd, sf->base, desc->base);
|
||||
wvmcs(cpu->hvf_fd, sf->limit, desc->limit);
|
||||
wvmcs(cpu->hvf_fd, sf->selector, desc->sel);
|
||||
wvmcs(cpu->hvf_fd, sf->ar_bytes, desc->ar);
|
||||
wvmcs(cpu->hvf->fd, sf->base, desc->base);
|
||||
wvmcs(cpu->hvf->fd, sf->limit, desc->limit);
|
||||
wvmcs(cpu->hvf->fd, sf->selector, desc->sel);
|
||||
wvmcs(cpu->hvf->fd, sf->ar_bytes, desc->ar);
|
||||
}
|
||||
|
||||
void x86_segment_descriptor_to_vmx(struct CPUState *cpu, x68_segment_selector selector, struct x86_segment_descriptor *desc, struct vmx_segment *vmx_desc)
|
||||
|
||||
+31
-31
@@ -673,7 +673,7 @@ void simulate_rdmsr(struct CPUState *cpu)
|
||||
|
||||
switch (msr) {
|
||||
case MSR_IA32_TSC:
|
||||
val = rdtscp() + rvmcs(cpu->hvf_fd, VMCS_TSC_OFFSET);
|
||||
val = rdtscp() + rvmcs(cpu->hvf->fd, VMCS_TSC_OFFSET);
|
||||
break;
|
||||
case MSR_IA32_APICBASE:
|
||||
val = cpu_get_apic_base(X86_CPU(cpu)->apic_state);
|
||||
@@ -682,16 +682,16 @@ void simulate_rdmsr(struct CPUState *cpu)
|
||||
val = x86_cpu->ucode_rev;
|
||||
break;
|
||||
case MSR_EFER:
|
||||
val = rvmcs(cpu->hvf_fd, VMCS_GUEST_IA32_EFER);
|
||||
val = rvmcs(cpu->hvf->fd, VMCS_GUEST_IA32_EFER);
|
||||
break;
|
||||
case MSR_FSBASE:
|
||||
val = rvmcs(cpu->hvf_fd, VMCS_GUEST_FS_BASE);
|
||||
val = rvmcs(cpu->hvf->fd, VMCS_GUEST_FS_BASE);
|
||||
break;
|
||||
case MSR_GSBASE:
|
||||
val = rvmcs(cpu->hvf_fd, VMCS_GUEST_GS_BASE);
|
||||
val = rvmcs(cpu->hvf->fd, VMCS_GUEST_GS_BASE);
|
||||
break;
|
||||
case MSR_KERNELGSBASE:
|
||||
val = rvmcs(cpu->hvf_fd, VMCS_HOST_FS_BASE);
|
||||
val = rvmcs(cpu->hvf->fd, VMCS_HOST_FS_BASE);
|
||||
break;
|
||||
case MSR_STAR:
|
||||
abort();
|
||||
@@ -775,13 +775,13 @@ void simulate_wrmsr(struct CPUState *cpu)
|
||||
cpu_set_apic_base(X86_CPU(cpu)->apic_state, data);
|
||||
break;
|
||||
case MSR_FSBASE:
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_FS_BASE, data);
|
||||
wvmcs(cpu->hvf->fd, VMCS_GUEST_FS_BASE, data);
|
||||
break;
|
||||
case MSR_GSBASE:
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_GS_BASE, data);
|
||||
wvmcs(cpu->hvf->fd, VMCS_GUEST_GS_BASE, data);
|
||||
break;
|
||||
case MSR_KERNELGSBASE:
|
||||
wvmcs(cpu->hvf_fd, VMCS_HOST_FS_BASE, data);
|
||||
wvmcs(cpu->hvf->fd, VMCS_HOST_FS_BASE, data);
|
||||
break;
|
||||
case MSR_STAR:
|
||||
abort();
|
||||
@@ -794,9 +794,9 @@ void simulate_wrmsr(struct CPUState *cpu)
|
||||
break;
|
||||
case MSR_EFER:
|
||||
/*printf("new efer %llx\n", EFER(cpu));*/
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_IA32_EFER, data);
|
||||
wvmcs(cpu->hvf->fd, VMCS_GUEST_IA32_EFER, data);
|
||||
if (data & MSR_EFER_NXE) {
|
||||
hv_vcpu_invalidate_tlb(cpu->hvf_fd);
|
||||
hv_vcpu_invalidate_tlb(cpu->hvf->fd);
|
||||
}
|
||||
break;
|
||||
case MSR_MTRRphysBase(0):
|
||||
@@ -1420,21 +1420,21 @@ void load_regs(struct CPUState *cpu)
|
||||
CPUX86State *env = &x86_cpu->env;
|
||||
|
||||
int i = 0;
|
||||
RRX(env, R_EAX) = rreg(cpu->hvf_fd, HV_X86_RAX);
|
||||
RRX(env, R_EBX) = rreg(cpu->hvf_fd, HV_X86_RBX);
|
||||
RRX(env, R_ECX) = rreg(cpu->hvf_fd, HV_X86_RCX);
|
||||
RRX(env, R_EDX) = rreg(cpu->hvf_fd, HV_X86_RDX);
|
||||
RRX(env, R_ESI) = rreg(cpu->hvf_fd, HV_X86_RSI);
|
||||
RRX(env, R_EDI) = rreg(cpu->hvf_fd, HV_X86_RDI);
|
||||
RRX(env, R_ESP) = rreg(cpu->hvf_fd, HV_X86_RSP);
|
||||
RRX(env, R_EBP) = rreg(cpu->hvf_fd, HV_X86_RBP);
|
||||
RRX(env, R_EAX) = rreg(cpu->hvf->fd, HV_X86_RAX);
|
||||
RRX(env, R_EBX) = rreg(cpu->hvf->fd, HV_X86_RBX);
|
||||
RRX(env, R_ECX) = rreg(cpu->hvf->fd, HV_X86_RCX);
|
||||
RRX(env, R_EDX) = rreg(cpu->hvf->fd, HV_X86_RDX);
|
||||
RRX(env, R_ESI) = rreg(cpu->hvf->fd, HV_X86_RSI);
|
||||
RRX(env, R_EDI) = rreg(cpu->hvf->fd, HV_X86_RDI);
|
||||
RRX(env, R_ESP) = rreg(cpu->hvf->fd, HV_X86_RSP);
|
||||
RRX(env, R_EBP) = rreg(cpu->hvf->fd, HV_X86_RBP);
|
||||
for (i = 8; i < 16; i++) {
|
||||
RRX(env, i) = rreg(cpu->hvf_fd, HV_X86_RAX + i);
|
||||
RRX(env, i) = rreg(cpu->hvf->fd, HV_X86_RAX + i);
|
||||
}
|
||||
|
||||
env->eflags = rreg(cpu->hvf_fd, HV_X86_RFLAGS);
|
||||
env->eflags = rreg(cpu->hvf->fd, HV_X86_RFLAGS);
|
||||
rflags_to_lflags(env);
|
||||
env->eip = rreg(cpu->hvf_fd, HV_X86_RIP);
|
||||
env->eip = rreg(cpu->hvf->fd, HV_X86_RIP);
|
||||
}
|
||||
|
||||
void store_regs(struct CPUState *cpu)
|
||||
@@ -1443,20 +1443,20 @@ void store_regs(struct CPUState *cpu)
|
||||
CPUX86State *env = &x86_cpu->env;
|
||||
|
||||
int i = 0;
|
||||
wreg(cpu->hvf_fd, HV_X86_RAX, RAX(env));
|
||||
wreg(cpu->hvf_fd, HV_X86_RBX, RBX(env));
|
||||
wreg(cpu->hvf_fd, HV_X86_RCX, RCX(env));
|
||||
wreg(cpu->hvf_fd, HV_X86_RDX, RDX(env));
|
||||
wreg(cpu->hvf_fd, HV_X86_RSI, RSI(env));
|
||||
wreg(cpu->hvf_fd, HV_X86_RDI, RDI(env));
|
||||
wreg(cpu->hvf_fd, HV_X86_RBP, RBP(env));
|
||||
wreg(cpu->hvf_fd, HV_X86_RSP, RSP(env));
|
||||
wreg(cpu->hvf->fd, HV_X86_RAX, RAX(env));
|
||||
wreg(cpu->hvf->fd, HV_X86_RBX, RBX(env));
|
||||
wreg(cpu->hvf->fd, HV_X86_RCX, RCX(env));
|
||||
wreg(cpu->hvf->fd, HV_X86_RDX, RDX(env));
|
||||
wreg(cpu->hvf->fd, HV_X86_RSI, RSI(env));
|
||||
wreg(cpu->hvf->fd, HV_X86_RDI, RDI(env));
|
||||
wreg(cpu->hvf->fd, HV_X86_RBP, RBP(env));
|
||||
wreg(cpu->hvf->fd, HV_X86_RSP, RSP(env));
|
||||
for (i = 8; i < 16; i++) {
|
||||
wreg(cpu->hvf_fd, HV_X86_RAX + i, RRX(env, i));
|
||||
wreg(cpu->hvf->fd, HV_X86_RAX + i, RRX(env, i));
|
||||
}
|
||||
|
||||
lflags_to_rflags(env);
|
||||
wreg(cpu->hvf_fd, HV_X86_RFLAGS, env->eflags);
|
||||
wreg(cpu->hvf->fd, HV_X86_RFLAGS, env->eflags);
|
||||
macvm_set_rip(cpu, env->eip);
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ static bool test_pt_entry(struct CPUState *cpu, struct gpt_translation *pt,
|
||||
pt->err_code |= MMU_PAGE_PT;
|
||||
}
|
||||
|
||||
uint32_t cr0 = rvmcs(cpu->hvf_fd, VMCS_GUEST_CR0);
|
||||
uint32_t cr0 = rvmcs(cpu->hvf->fd, VMCS_GUEST_CR0);
|
||||
/* check protection */
|
||||
if (cr0 & CR0_WP) {
|
||||
if (pt->write_access && !pte_write_access(pte)) {
|
||||
@@ -173,7 +173,7 @@ static bool walk_gpt(struct CPUState *cpu, target_ulong addr, int err_code,
|
||||
{
|
||||
int top_level, level;
|
||||
bool is_large = false;
|
||||
target_ulong cr3 = rvmcs(cpu->hvf_fd, VMCS_GUEST_CR3);
|
||||
target_ulong cr3 = rvmcs(cpu->hvf->fd, VMCS_GUEST_CR3);
|
||||
uint64_t page_mask = pae ? PAE_PTE_PAGE_MASK : LEGACY_PTE_PAGE_MASK;
|
||||
|
||||
memset(pt, 0, sizeof(*pt));
|
||||
|
||||
@@ -62,7 +62,7 @@ static void load_state_from_tss32(CPUState *cpu, struct x86_tss_segment32 *tss)
|
||||
X86CPU *x86_cpu = X86_CPU(cpu);
|
||||
CPUX86State *env = &x86_cpu->env;
|
||||
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_CR3, tss->cr3);
|
||||
wvmcs(cpu->hvf->fd, VMCS_GUEST_CR3, tss->cr3);
|
||||
|
||||
env->eip = tss->eip;
|
||||
env->eflags = tss->eflags | 2;
|
||||
@@ -111,11 +111,11 @@ static int task_switch_32(CPUState *cpu, x68_segment_selector tss_sel, x68_segme
|
||||
|
||||
void vmx_handle_task_switch(CPUState *cpu, x68_segment_selector tss_sel, int reason, bool gate_valid, uint8_t gate, uint64_t gate_type)
|
||||
{
|
||||
uint64_t rip = rreg(cpu->hvf_fd, HV_X86_RIP);
|
||||
uint64_t rip = rreg(cpu->hvf->fd, HV_X86_RIP);
|
||||
if (!gate_valid || (gate_type != VMCS_INTR_T_HWEXCEPTION &&
|
||||
gate_type != VMCS_INTR_T_HWINTR &&
|
||||
gate_type != VMCS_INTR_T_NMI)) {
|
||||
int ins_len = rvmcs(cpu->hvf_fd, VMCS_EXIT_INSTRUCTION_LENGTH);
|
||||
int ins_len = rvmcs(cpu->hvf->fd, VMCS_EXIT_INSTRUCTION_LENGTH);
|
||||
macvm_set_rip(cpu, rip + ins_len);
|
||||
return;
|
||||
}
|
||||
@@ -174,12 +174,12 @@ void vmx_handle_task_switch(CPUState *cpu, x68_segment_selector tss_sel, int rea
|
||||
//ret = task_switch_16(cpu, tss_sel, old_tss_sel, old_tss_base, &next_tss_desc);
|
||||
VM_PANIC("task_switch_16");
|
||||
|
||||
macvm_set_cr0(cpu->hvf_fd, rvmcs(cpu->hvf_fd, VMCS_GUEST_CR0) | CR0_TS);
|
||||
macvm_set_cr0(cpu->hvf->fd, rvmcs(cpu->hvf->fd, VMCS_GUEST_CR0) | CR0_TS);
|
||||
x86_segment_descriptor_to_vmx(cpu, tss_sel, &next_tss_desc, &vmx_seg);
|
||||
vmx_write_segment_descriptor(cpu, &vmx_seg, R_TR);
|
||||
|
||||
store_regs(cpu);
|
||||
|
||||
hv_vcpu_invalidate_tlb(cpu->hvf_fd);
|
||||
hv_vcpu_flush(cpu->hvf_fd);
|
||||
hv_vcpu_invalidate_tlb(cpu->hvf->fd);
|
||||
hv_vcpu_flush(cpu->hvf->fd);
|
||||
}
|
||||
+114
-110
@@ -20,6 +20,9 @@
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "qemu-common.h"
|
||||
#include "sysemu/hvf.h"
|
||||
#include "sysemu/hvf_int.h"
|
||||
#include "sysemu/hw_accel.h"
|
||||
#include "x86hvf.h"
|
||||
#include "vmx.h"
|
||||
#include "vmcs.h"
|
||||
@@ -32,8 +35,6 @@
|
||||
#include <Hypervisor/hv.h>
|
||||
#include <Hypervisor/hv_vmx.h>
|
||||
|
||||
#include "hvf-cpus.h"
|
||||
|
||||
void hvf_set_segment(struct CPUState *cpu, struct vmx_segment *vmx_seg,
|
||||
SegmentCache *qseg, bool is_tr)
|
||||
{
|
||||
@@ -81,7 +82,7 @@ void hvf_put_xsave(CPUState *cpu_state)
|
||||
|
||||
x86_cpu_xsave_all_areas(X86_CPU(cpu_state), xsave);
|
||||
|
||||
if (hv_vcpu_write_fpstate(cpu_state->hvf_fd, (void*)xsave, 4096)) {
|
||||
if (hv_vcpu_write_fpstate(cpu_state->hvf->fd, (void*)xsave, 4096)) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
@@ -91,19 +92,19 @@ void hvf_put_segments(CPUState *cpu_state)
|
||||
CPUX86State *env = &X86_CPU(cpu_state)->env;
|
||||
struct vmx_segment seg;
|
||||
|
||||
wvmcs(cpu_state->hvf_fd, VMCS_GUEST_IDTR_LIMIT, env->idt.limit);
|
||||
wvmcs(cpu_state->hvf_fd, VMCS_GUEST_IDTR_BASE, env->idt.base);
|
||||
wvmcs(cpu_state->hvf->fd, VMCS_GUEST_IDTR_LIMIT, env->idt.limit);
|
||||
wvmcs(cpu_state->hvf->fd, VMCS_GUEST_IDTR_BASE, env->idt.base);
|
||||
|
||||
wvmcs(cpu_state->hvf_fd, VMCS_GUEST_GDTR_LIMIT, env->gdt.limit);
|
||||
wvmcs(cpu_state->hvf_fd, VMCS_GUEST_GDTR_BASE, env->gdt.base);
|
||||
wvmcs(cpu_state->hvf->fd, VMCS_GUEST_GDTR_LIMIT, env->gdt.limit);
|
||||
wvmcs(cpu_state->hvf->fd, VMCS_GUEST_GDTR_BASE, env->gdt.base);
|
||||
|
||||
/* wvmcs(cpu_state->hvf_fd, VMCS_GUEST_CR2, env->cr[2]); */
|
||||
wvmcs(cpu_state->hvf_fd, VMCS_GUEST_CR3, env->cr[3]);
|
||||
/* wvmcs(cpu_state->hvf->fd, VMCS_GUEST_CR2, env->cr[2]); */
|
||||
wvmcs(cpu_state->hvf->fd, VMCS_GUEST_CR3, env->cr[3]);
|
||||
vmx_update_tpr(cpu_state);
|
||||
wvmcs(cpu_state->hvf_fd, VMCS_GUEST_IA32_EFER, env->efer);
|
||||
wvmcs(cpu_state->hvf->fd, VMCS_GUEST_IA32_EFER, env->efer);
|
||||
|
||||
macvm_set_cr4(cpu_state->hvf_fd, env->cr[4]);
|
||||
macvm_set_cr0(cpu_state->hvf_fd, env->cr[0]);
|
||||
macvm_set_cr4(cpu_state->hvf->fd, env->cr[4]);
|
||||
macvm_set_cr0(cpu_state->hvf->fd, env->cr[0]);
|
||||
|
||||
hvf_set_segment(cpu_state, &seg, &env->segs[R_CS], false);
|
||||
vmx_write_segment_descriptor(cpu_state, &seg, R_CS);
|
||||
@@ -129,31 +130,31 @@ void hvf_put_segments(CPUState *cpu_state)
|
||||
hvf_set_segment(cpu_state, &seg, &env->ldt, false);
|
||||
vmx_write_segment_descriptor(cpu_state, &seg, R_LDTR);
|
||||
|
||||
hv_vcpu_flush(cpu_state->hvf_fd);
|
||||
hv_vcpu_flush(cpu_state->hvf->fd);
|
||||
}
|
||||
|
||||
void hvf_put_msrs(CPUState *cpu_state)
|
||||
{
|
||||
CPUX86State *env = &X86_CPU(cpu_state)->env;
|
||||
|
||||
hv_vcpu_write_msr(cpu_state->hvf_fd, MSR_IA32_SYSENTER_CS,
|
||||
hv_vcpu_write_msr(cpu_state->hvf->fd, MSR_IA32_SYSENTER_CS,
|
||||
env->sysenter_cs);
|
||||
hv_vcpu_write_msr(cpu_state->hvf_fd, MSR_IA32_SYSENTER_ESP,
|
||||
hv_vcpu_write_msr(cpu_state->hvf->fd, MSR_IA32_SYSENTER_ESP,
|
||||
env->sysenter_esp);
|
||||
hv_vcpu_write_msr(cpu_state->hvf_fd, MSR_IA32_SYSENTER_EIP,
|
||||
hv_vcpu_write_msr(cpu_state->hvf->fd, MSR_IA32_SYSENTER_EIP,
|
||||
env->sysenter_eip);
|
||||
|
||||
hv_vcpu_write_msr(cpu_state->hvf_fd, MSR_STAR, env->star);
|
||||
hv_vcpu_write_msr(cpu_state->hvf->fd, MSR_STAR, env->star);
|
||||
|
||||
#ifdef TARGET_X86_64
|
||||
hv_vcpu_write_msr(cpu_state->hvf_fd, MSR_CSTAR, env->cstar);
|
||||
hv_vcpu_write_msr(cpu_state->hvf_fd, MSR_KERNELGSBASE, env->kernelgsbase);
|
||||
hv_vcpu_write_msr(cpu_state->hvf_fd, MSR_FMASK, env->fmask);
|
||||
hv_vcpu_write_msr(cpu_state->hvf_fd, MSR_LSTAR, env->lstar);
|
||||
hv_vcpu_write_msr(cpu_state->hvf->fd, MSR_CSTAR, env->cstar);
|
||||
hv_vcpu_write_msr(cpu_state->hvf->fd, MSR_KERNELGSBASE, env->kernelgsbase);
|
||||
hv_vcpu_write_msr(cpu_state->hvf->fd, MSR_FMASK, env->fmask);
|
||||
hv_vcpu_write_msr(cpu_state->hvf->fd, MSR_LSTAR, env->lstar);
|
||||
#endif
|
||||
|
||||
hv_vcpu_write_msr(cpu_state->hvf_fd, MSR_GSBASE, env->segs[R_GS].base);
|
||||
hv_vcpu_write_msr(cpu_state->hvf_fd, MSR_FSBASE, env->segs[R_FS].base);
|
||||
hv_vcpu_write_msr(cpu_state->hvf->fd, MSR_GSBASE, env->segs[R_GS].base);
|
||||
hv_vcpu_write_msr(cpu_state->hvf->fd, MSR_FSBASE, env->segs[R_FS].base);
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +164,7 @@ void hvf_get_xsave(CPUState *cpu_state)
|
||||
|
||||
xsave = X86_CPU(cpu_state)->env.xsave_buf;
|
||||
|
||||
if (hv_vcpu_read_fpstate(cpu_state->hvf_fd, (void*)xsave, 4096)) {
|
||||
if (hv_vcpu_read_fpstate(cpu_state->hvf->fd, (void*)xsave, 4096)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
@@ -202,17 +203,17 @@ void hvf_get_segments(CPUState *cpu_state)
|
||||
vmx_read_segment_descriptor(cpu_state, &seg, R_LDTR);
|
||||
hvf_get_segment(&env->ldt, &seg);
|
||||
|
||||
env->idt.limit = rvmcs(cpu_state->hvf_fd, VMCS_GUEST_IDTR_LIMIT);
|
||||
env->idt.base = rvmcs(cpu_state->hvf_fd, VMCS_GUEST_IDTR_BASE);
|
||||
env->gdt.limit = rvmcs(cpu_state->hvf_fd, VMCS_GUEST_GDTR_LIMIT);
|
||||
env->gdt.base = rvmcs(cpu_state->hvf_fd, VMCS_GUEST_GDTR_BASE);
|
||||
env->idt.limit = rvmcs(cpu_state->hvf->fd, VMCS_GUEST_IDTR_LIMIT);
|
||||
env->idt.base = rvmcs(cpu_state->hvf->fd, VMCS_GUEST_IDTR_BASE);
|
||||
env->gdt.limit = rvmcs(cpu_state->hvf->fd, VMCS_GUEST_GDTR_LIMIT);
|
||||
env->gdt.base = rvmcs(cpu_state->hvf->fd, VMCS_GUEST_GDTR_BASE);
|
||||
|
||||
env->cr[0] = rvmcs(cpu_state->hvf_fd, VMCS_GUEST_CR0);
|
||||
env->cr[0] = rvmcs(cpu_state->hvf->fd, VMCS_GUEST_CR0);
|
||||
env->cr[2] = 0;
|
||||
env->cr[3] = rvmcs(cpu_state->hvf_fd, VMCS_GUEST_CR3);
|
||||
env->cr[4] = rvmcs(cpu_state->hvf_fd, VMCS_GUEST_CR4);
|
||||
env->cr[3] = rvmcs(cpu_state->hvf->fd, VMCS_GUEST_CR3);
|
||||
env->cr[4] = rvmcs(cpu_state->hvf->fd, VMCS_GUEST_CR4);
|
||||
|
||||
env->efer = rvmcs(cpu_state->hvf_fd, VMCS_GUEST_IA32_EFER);
|
||||
env->efer = rvmcs(cpu_state->hvf->fd, VMCS_GUEST_IA32_EFER);
|
||||
}
|
||||
|
||||
void hvf_get_msrs(CPUState *cpu_state)
|
||||
@@ -220,27 +221,27 @@ void hvf_get_msrs(CPUState *cpu_state)
|
||||
CPUX86State *env = &X86_CPU(cpu_state)->env;
|
||||
uint64_t tmp;
|
||||
|
||||
hv_vcpu_read_msr(cpu_state->hvf_fd, MSR_IA32_SYSENTER_CS, &tmp);
|
||||
hv_vcpu_read_msr(cpu_state->hvf->fd, MSR_IA32_SYSENTER_CS, &tmp);
|
||||
env->sysenter_cs = tmp;
|
||||
|
||||
hv_vcpu_read_msr(cpu_state->hvf_fd, MSR_IA32_SYSENTER_ESP, &tmp);
|
||||
hv_vcpu_read_msr(cpu_state->hvf->fd, MSR_IA32_SYSENTER_ESP, &tmp);
|
||||
env->sysenter_esp = tmp;
|
||||
|
||||
hv_vcpu_read_msr(cpu_state->hvf_fd, MSR_IA32_SYSENTER_EIP, &tmp);
|
||||
hv_vcpu_read_msr(cpu_state->hvf->fd, MSR_IA32_SYSENTER_EIP, &tmp);
|
||||
env->sysenter_eip = tmp;
|
||||
|
||||
hv_vcpu_read_msr(cpu_state->hvf_fd, MSR_STAR, &env->star);
|
||||
hv_vcpu_read_msr(cpu_state->hvf->fd, MSR_STAR, &env->star);
|
||||
|
||||
#ifdef TARGET_X86_64
|
||||
hv_vcpu_read_msr(cpu_state->hvf_fd, MSR_CSTAR, &env->cstar);
|
||||
hv_vcpu_read_msr(cpu_state->hvf_fd, MSR_KERNELGSBASE, &env->kernelgsbase);
|
||||
hv_vcpu_read_msr(cpu_state->hvf_fd, MSR_FMASK, &env->fmask);
|
||||
hv_vcpu_read_msr(cpu_state->hvf_fd, MSR_LSTAR, &env->lstar);
|
||||
hv_vcpu_read_msr(cpu_state->hvf->fd, MSR_CSTAR, &env->cstar);
|
||||
hv_vcpu_read_msr(cpu_state->hvf->fd, MSR_KERNELGSBASE, &env->kernelgsbase);
|
||||
hv_vcpu_read_msr(cpu_state->hvf->fd, MSR_FMASK, &env->fmask);
|
||||
hv_vcpu_read_msr(cpu_state->hvf->fd, MSR_LSTAR, &env->lstar);
|
||||
#endif
|
||||
|
||||
hv_vcpu_read_msr(cpu_state->hvf_fd, MSR_IA32_APICBASE, &tmp);
|
||||
hv_vcpu_read_msr(cpu_state->hvf->fd, MSR_IA32_APICBASE, &tmp);
|
||||
|
||||
env->tsc = rdtscp() + rvmcs(cpu_state->hvf_fd, VMCS_TSC_OFFSET);
|
||||
env->tsc = rdtscp() + rvmcs(cpu_state->hvf->fd, VMCS_TSC_OFFSET);
|
||||
}
|
||||
|
||||
int hvf_put_registers(CPUState *cpu_state)
|
||||
@@ -248,26 +249,26 @@ int hvf_put_registers(CPUState *cpu_state)
|
||||
X86CPU *x86cpu = X86_CPU(cpu_state);
|
||||
CPUX86State *env = &x86cpu->env;
|
||||
|
||||
wreg(cpu_state->hvf_fd, HV_X86_RAX, env->regs[R_EAX]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_RBX, env->regs[R_EBX]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_RCX, env->regs[R_ECX]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_RDX, env->regs[R_EDX]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_RBP, env->regs[R_EBP]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_RSP, env->regs[R_ESP]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_RSI, env->regs[R_ESI]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_RDI, env->regs[R_EDI]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_R8, env->regs[8]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_R9, env->regs[9]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_R10, env->regs[10]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_R11, env->regs[11]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_R12, env->regs[12]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_R13, env->regs[13]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_R14, env->regs[14]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_R15, env->regs[15]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_RFLAGS, env->eflags);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_RIP, env->eip);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_RAX, env->regs[R_EAX]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_RBX, env->regs[R_EBX]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_RCX, env->regs[R_ECX]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_RDX, env->regs[R_EDX]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_RBP, env->regs[R_EBP]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_RSP, env->regs[R_ESP]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_RSI, env->regs[R_ESI]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_RDI, env->regs[R_EDI]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_R8, env->regs[8]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_R9, env->regs[9]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_R10, env->regs[10]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_R11, env->regs[11]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_R12, env->regs[12]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_R13, env->regs[13]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_R14, env->regs[14]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_R15, env->regs[15]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_RFLAGS, env->eflags);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_RIP, env->eip);
|
||||
|
||||
wreg(cpu_state->hvf_fd, HV_X86_XCR0, env->xcr0);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_XCR0, env->xcr0);
|
||||
|
||||
hvf_put_xsave(cpu_state);
|
||||
|
||||
@@ -275,14 +276,14 @@ int hvf_put_registers(CPUState *cpu_state)
|
||||
|
||||
hvf_put_msrs(cpu_state);
|
||||
|
||||
wreg(cpu_state->hvf_fd, HV_X86_DR0, env->dr[0]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_DR1, env->dr[1]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_DR2, env->dr[2]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_DR3, env->dr[3]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_DR4, env->dr[4]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_DR5, env->dr[5]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_DR6, env->dr[6]);
|
||||
wreg(cpu_state->hvf_fd, HV_X86_DR7, env->dr[7]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_DR0, env->dr[0]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_DR1, env->dr[1]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_DR2, env->dr[2]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_DR3, env->dr[3]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_DR4, env->dr[4]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_DR5, env->dr[5]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_DR6, env->dr[6]);
|
||||
wreg(cpu_state->hvf->fd, HV_X86_DR7, env->dr[7]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -292,40 +293,40 @@ int hvf_get_registers(CPUState *cpu_state)
|
||||
X86CPU *x86cpu = X86_CPU(cpu_state);
|
||||
CPUX86State *env = &x86cpu->env;
|
||||
|
||||
env->regs[R_EAX] = rreg(cpu_state->hvf_fd, HV_X86_RAX);
|
||||
env->regs[R_EBX] = rreg(cpu_state->hvf_fd, HV_X86_RBX);
|
||||
env->regs[R_ECX] = rreg(cpu_state->hvf_fd, HV_X86_RCX);
|
||||
env->regs[R_EDX] = rreg(cpu_state->hvf_fd, HV_X86_RDX);
|
||||
env->regs[R_EBP] = rreg(cpu_state->hvf_fd, HV_X86_RBP);
|
||||
env->regs[R_ESP] = rreg(cpu_state->hvf_fd, HV_X86_RSP);
|
||||
env->regs[R_ESI] = rreg(cpu_state->hvf_fd, HV_X86_RSI);
|
||||
env->regs[R_EDI] = rreg(cpu_state->hvf_fd, HV_X86_RDI);
|
||||
env->regs[8] = rreg(cpu_state->hvf_fd, HV_X86_R8);
|
||||
env->regs[9] = rreg(cpu_state->hvf_fd, HV_X86_R9);
|
||||
env->regs[10] = rreg(cpu_state->hvf_fd, HV_X86_R10);
|
||||
env->regs[11] = rreg(cpu_state->hvf_fd, HV_X86_R11);
|
||||
env->regs[12] = rreg(cpu_state->hvf_fd, HV_X86_R12);
|
||||
env->regs[13] = rreg(cpu_state->hvf_fd, HV_X86_R13);
|
||||
env->regs[14] = rreg(cpu_state->hvf_fd, HV_X86_R14);
|
||||
env->regs[15] = rreg(cpu_state->hvf_fd, HV_X86_R15);
|
||||
env->regs[R_EAX] = rreg(cpu_state->hvf->fd, HV_X86_RAX);
|
||||
env->regs[R_EBX] = rreg(cpu_state->hvf->fd, HV_X86_RBX);
|
||||
env->regs[R_ECX] = rreg(cpu_state->hvf->fd, HV_X86_RCX);
|
||||
env->regs[R_EDX] = rreg(cpu_state->hvf->fd, HV_X86_RDX);
|
||||
env->regs[R_EBP] = rreg(cpu_state->hvf->fd, HV_X86_RBP);
|
||||
env->regs[R_ESP] = rreg(cpu_state->hvf->fd, HV_X86_RSP);
|
||||
env->regs[R_ESI] = rreg(cpu_state->hvf->fd, HV_X86_RSI);
|
||||
env->regs[R_EDI] = rreg(cpu_state->hvf->fd, HV_X86_RDI);
|
||||
env->regs[8] = rreg(cpu_state->hvf->fd, HV_X86_R8);
|
||||
env->regs[9] = rreg(cpu_state->hvf->fd, HV_X86_R9);
|
||||
env->regs[10] = rreg(cpu_state->hvf->fd, HV_X86_R10);
|
||||
env->regs[11] = rreg(cpu_state->hvf->fd, HV_X86_R11);
|
||||
env->regs[12] = rreg(cpu_state->hvf->fd, HV_X86_R12);
|
||||
env->regs[13] = rreg(cpu_state->hvf->fd, HV_X86_R13);
|
||||
env->regs[14] = rreg(cpu_state->hvf->fd, HV_X86_R14);
|
||||
env->regs[15] = rreg(cpu_state->hvf->fd, HV_X86_R15);
|
||||
|
||||
env->eflags = rreg(cpu_state->hvf_fd, HV_X86_RFLAGS);
|
||||
env->eip = rreg(cpu_state->hvf_fd, HV_X86_RIP);
|
||||
env->eflags = rreg(cpu_state->hvf->fd, HV_X86_RFLAGS);
|
||||
env->eip = rreg(cpu_state->hvf->fd, HV_X86_RIP);
|
||||
|
||||
hvf_get_xsave(cpu_state);
|
||||
env->xcr0 = rreg(cpu_state->hvf_fd, HV_X86_XCR0);
|
||||
env->xcr0 = rreg(cpu_state->hvf->fd, HV_X86_XCR0);
|
||||
|
||||
hvf_get_segments(cpu_state);
|
||||
hvf_get_msrs(cpu_state);
|
||||
|
||||
env->dr[0] = rreg(cpu_state->hvf_fd, HV_X86_DR0);
|
||||
env->dr[1] = rreg(cpu_state->hvf_fd, HV_X86_DR1);
|
||||
env->dr[2] = rreg(cpu_state->hvf_fd, HV_X86_DR2);
|
||||
env->dr[3] = rreg(cpu_state->hvf_fd, HV_X86_DR3);
|
||||
env->dr[4] = rreg(cpu_state->hvf_fd, HV_X86_DR4);
|
||||
env->dr[5] = rreg(cpu_state->hvf_fd, HV_X86_DR5);
|
||||
env->dr[6] = rreg(cpu_state->hvf_fd, HV_X86_DR6);
|
||||
env->dr[7] = rreg(cpu_state->hvf_fd, HV_X86_DR7);
|
||||
env->dr[0] = rreg(cpu_state->hvf->fd, HV_X86_DR0);
|
||||
env->dr[1] = rreg(cpu_state->hvf->fd, HV_X86_DR1);
|
||||
env->dr[2] = rreg(cpu_state->hvf->fd, HV_X86_DR2);
|
||||
env->dr[3] = rreg(cpu_state->hvf->fd, HV_X86_DR3);
|
||||
env->dr[4] = rreg(cpu_state->hvf->fd, HV_X86_DR4);
|
||||
env->dr[5] = rreg(cpu_state->hvf->fd, HV_X86_DR5);
|
||||
env->dr[6] = rreg(cpu_state->hvf->fd, HV_X86_DR6);
|
||||
env->dr[7] = rreg(cpu_state->hvf->fd, HV_X86_DR7);
|
||||
|
||||
x86_update_hflags(env);
|
||||
return 0;
|
||||
@@ -334,16 +335,16 @@ int hvf_get_registers(CPUState *cpu_state)
|
||||
static void vmx_set_int_window_exiting(CPUState *cpu)
|
||||
{
|
||||
uint64_t val;
|
||||
val = rvmcs(cpu->hvf_fd, VMCS_PRI_PROC_BASED_CTLS);
|
||||
wvmcs(cpu->hvf_fd, VMCS_PRI_PROC_BASED_CTLS, val |
|
||||
val = rvmcs(cpu->hvf->fd, VMCS_PRI_PROC_BASED_CTLS);
|
||||
wvmcs(cpu->hvf->fd, VMCS_PRI_PROC_BASED_CTLS, val |
|
||||
VMCS_PRI_PROC_BASED_CTLS_INT_WINDOW_EXITING);
|
||||
}
|
||||
|
||||
void vmx_clear_int_window_exiting(CPUState *cpu)
|
||||
{
|
||||
uint64_t val;
|
||||
val = rvmcs(cpu->hvf_fd, VMCS_PRI_PROC_BASED_CTLS);
|
||||
wvmcs(cpu->hvf_fd, VMCS_PRI_PROC_BASED_CTLS, val &
|
||||
val = rvmcs(cpu->hvf->fd, VMCS_PRI_PROC_BASED_CTLS);
|
||||
wvmcs(cpu->hvf->fd, VMCS_PRI_PROC_BASED_CTLS, val &
|
||||
~VMCS_PRI_PROC_BASED_CTLS_INT_WINDOW_EXITING);
|
||||
}
|
||||
|
||||
@@ -379,7 +380,7 @@ bool hvf_inject_interrupts(CPUState *cpu_state)
|
||||
uint64_t info = 0;
|
||||
if (have_event) {
|
||||
info = vector | intr_type | VMCS_INTR_VALID;
|
||||
uint64_t reason = rvmcs(cpu_state->hvf_fd, VMCS_EXIT_REASON);
|
||||
uint64_t reason = rvmcs(cpu_state->hvf->fd, VMCS_EXIT_REASON);
|
||||
if (env->nmi_injected && reason != EXIT_REASON_TASK_SWITCH) {
|
||||
vmx_clear_nmi_blocking(cpu_state);
|
||||
}
|
||||
@@ -388,17 +389,17 @@ bool hvf_inject_interrupts(CPUState *cpu_state)
|
||||
info &= ~(1 << 12); /* clear undefined bit */
|
||||
if (intr_type == VMCS_INTR_T_SWINTR ||
|
||||
intr_type == VMCS_INTR_T_SWEXCEPTION) {
|
||||
wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_INST_LENGTH, env->ins_len);
|
||||
wvmcs(cpu_state->hvf->fd, VMCS_ENTRY_INST_LENGTH, env->ins_len);
|
||||
}
|
||||
|
||||
if (env->has_error_code) {
|
||||
wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_EXCEPTION_ERROR,
|
||||
wvmcs(cpu_state->hvf->fd, VMCS_ENTRY_EXCEPTION_ERROR,
|
||||
env->error_code);
|
||||
/* Indicate that VMCS_ENTRY_EXCEPTION_ERROR is valid */
|
||||
info |= VMCS_INTR_DEL_ERRCODE;
|
||||
}
|
||||
/*printf("reinject %lx err %d\n", info, err);*/
|
||||
wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_INTR_INFO, info);
|
||||
wvmcs(cpu_state->hvf->fd, VMCS_ENTRY_INTR_INFO, info);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -406,7 +407,7 @@ bool hvf_inject_interrupts(CPUState *cpu_state)
|
||||
if (!(env->hflags2 & HF2_NMI_MASK) && !(info & VMCS_INTR_VALID)) {
|
||||
cpu_state->interrupt_request &= ~CPU_INTERRUPT_NMI;
|
||||
info = VMCS_INTR_VALID | VMCS_INTR_T_NMI | EXCP02_NMI;
|
||||
wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_INTR_INFO, info);
|
||||
wvmcs(cpu_state->hvf->fd, VMCS_ENTRY_INTR_INFO, info);
|
||||
} else {
|
||||
vmx_set_nmi_window_exiting(cpu_state);
|
||||
}
|
||||
@@ -418,7 +419,7 @@ bool hvf_inject_interrupts(CPUState *cpu_state)
|
||||
int line = cpu_get_pic_interrupt(&x86cpu->env);
|
||||
cpu_state->interrupt_request &= ~CPU_INTERRUPT_HARD;
|
||||
if (line >= 0) {
|
||||
wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_INTR_INFO, line |
|
||||
wvmcs(cpu_state->hvf->fd, VMCS_ENTRY_INTR_INFO, line |
|
||||
VMCS_INTR_VALID | VMCS_INTR_T_HWINTR);
|
||||
}
|
||||
}
|
||||
@@ -434,10 +435,13 @@ int hvf_process_events(CPUState *cpu_state)
|
||||
X86CPU *cpu = X86_CPU(cpu_state);
|
||||
CPUX86State *env = &cpu->env;
|
||||
|
||||
env->eflags = rreg(cpu_state->hvf_fd, HV_X86_RFLAGS);
|
||||
if (!cpu_state->vcpu_dirty) {
|
||||
/* light weight sync for CPU_INTERRUPT_HARD and IF_MASK */
|
||||
env->eflags = rreg(cpu_state->hvf->fd, HV_X86_RFLAGS);
|
||||
}
|
||||
|
||||
if (cpu_state->interrupt_request & CPU_INTERRUPT_INIT) {
|
||||
hvf_cpu_synchronize_state(cpu_state);
|
||||
cpu_synchronize_state(cpu_state);
|
||||
do_cpu_init(cpu);
|
||||
}
|
||||
|
||||
@@ -451,12 +455,12 @@ int hvf_process_events(CPUState *cpu_state)
|
||||
cpu_state->halted = 0;
|
||||
}
|
||||
if (cpu_state->interrupt_request & CPU_INTERRUPT_SIPI) {
|
||||
hvf_cpu_synchronize_state(cpu_state);
|
||||
cpu_synchronize_state(cpu_state);
|
||||
do_cpu_sipi(cpu);
|
||||
}
|
||||
if (cpu_state->interrupt_request & CPU_INTERRUPT_TPR) {
|
||||
cpu_state->interrupt_request &= ~CPU_INTERRUPT_TPR;
|
||||
hvf_cpu_synchronize_state(cpu_state);
|
||||
cpu_synchronize_state(cpu_state);
|
||||
apic_handle_tpr_access_report(cpu->apic_state, env->eip,
|
||||
env->tpr_access_type);
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
#include "x86_descr.h"
|
||||
|
||||
int hvf_process_events(CPUState *);
|
||||
int hvf_put_registers(CPUState *);
|
||||
int hvf_get_registers(CPUState *);
|
||||
bool hvf_inject_interrupts(CPUState *);
|
||||
void hvf_set_segment(struct CPUState *cpu, struct vmx_segment *vmx_seg,
|
||||
SegmentCache *qseg, bool is_tr);
|
||||
|
||||
@@ -83,7 +83,8 @@ static void mb_cpu_set_pc(CPUState *cs, vaddr value)
|
||||
cpu->env.iflags = 0;
|
||||
}
|
||||
|
||||
static void mb_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
|
||||
static void mb_cpu_synchronize_from_tb(CPUState *cs,
|
||||
const TranslationBlock *tb)
|
||||
{
|
||||
MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
|
||||
|
||||
|
||||
+2
-1
@@ -47,7 +47,8 @@ static void mips_cpu_set_pc(CPUState *cs, vaddr value)
|
||||
}
|
||||
}
|
||||
|
||||
static void mips_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
|
||||
static void mips_cpu_synchronize_from_tb(CPUState *cs,
|
||||
const TranslationBlock *tb)
|
||||
{
|
||||
MIPSCPU *cpu = MIPS_CPU(cs);
|
||||
CPUMIPSState *env = &cpu->env;
|
||||
|
||||
+2
-1
@@ -285,7 +285,8 @@ static void riscv_cpu_set_pc(CPUState *cs, vaddr value)
|
||||
env->pc = value;
|
||||
}
|
||||
|
||||
static void riscv_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
|
||||
static void riscv_cpu_synchronize_from_tb(CPUState *cs,
|
||||
const TranslationBlock *tb)
|
||||
{
|
||||
RISCVCPU *cpu = RISCV_CPU(cs);
|
||||
CPURISCVState *env = &cpu->env;
|
||||
|
||||
+2
-1
@@ -33,7 +33,8 @@ static void rx_cpu_set_pc(CPUState *cs, vaddr value)
|
||||
cpu->env.pc = value;
|
||||
}
|
||||
|
||||
static void rx_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
|
||||
static void rx_cpu_synchronize_from_tb(CPUState *cs,
|
||||
const TranslationBlock *tb)
|
||||
{
|
||||
RXCPU *cpu = RX_CPU(cs);
|
||||
|
||||
|
||||
+2
-1
@@ -34,7 +34,8 @@ static void superh_cpu_set_pc(CPUState *cs, vaddr value)
|
||||
cpu->env.pc = value;
|
||||
}
|
||||
|
||||
static void superh_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
|
||||
static void superh_cpu_synchronize_from_tb(CPUState *cs,
|
||||
const TranslationBlock *tb)
|
||||
{
|
||||
SuperHCPU *cpu = SUPERH_CPU(cs);
|
||||
|
||||
|
||||
+2
-1
@@ -691,7 +691,8 @@ static void sparc_cpu_set_pc(CPUState *cs, vaddr value)
|
||||
cpu->env.npc = value + 4;
|
||||
}
|
||||
|
||||
static void sparc_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
|
||||
static void sparc_cpu_synchronize_from_tb(CPUState *cs,
|
||||
const TranslationBlock *tb)
|
||||
{
|
||||
SPARCCPU *cpu = SPARC_CPU(cs);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ static void tricore_cpu_set_pc(CPUState *cs, vaddr value)
|
||||
}
|
||||
|
||||
static void tricore_cpu_synchronize_from_tb(CPUState *cs,
|
||||
TranslationBlock *tb)
|
||||
const TranslationBlock *tb)
|
||||
{
|
||||
TriCoreCPU *cpu = TRICORE_CPU(cs);
|
||||
CPUTriCoreState *env = &cpu->env;
|
||||
|
||||
@@ -78,38 +78,42 @@ static const int tcg_target_call_oarg_regs[1] = {
|
||||
#define TCG_REG_GUEST_BASE TCG_REG_X28
|
||||
#endif
|
||||
|
||||
static inline bool reloc_pc26(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
static bool reloc_pc26(tcg_insn_unit *src_rw, const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = target - code_ptr;
|
||||
const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw);
|
||||
ptrdiff_t offset = target - src_rx;
|
||||
|
||||
if (offset == sextract64(offset, 0, 26)) {
|
||||
/* read instruction, mask away previous PC_REL26 parameter contents,
|
||||
set the proper offset, then write back the instruction. */
|
||||
*code_ptr = deposit32(*code_ptr, 0, 26, offset);
|
||||
*src_rw = deposit32(*src_rw, 0, 26, offset);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool reloc_pc19(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
static bool reloc_pc19(tcg_insn_unit *src_rw, const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = target - code_ptr;
|
||||
const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw);
|
||||
ptrdiff_t offset = target - src_rx;
|
||||
|
||||
if (offset == sextract64(offset, 0, 19)) {
|
||||
*code_ptr = deposit32(*code_ptr, 5, 19, offset);
|
||||
*src_rw = deposit32(*src_rw, 5, 19, offset);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
tcg_debug_assert(addend == 0);
|
||||
switch (type) {
|
||||
case R_AARCH64_JUMP26:
|
||||
case R_AARCH64_CALL26:
|
||||
return reloc_pc26(code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_pc26(code_ptr, (const tcg_insn_unit *)value);
|
||||
case R_AARCH64_CONDBR19:
|
||||
return reloc_pc19(code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_pc19(code_ptr, (const tcg_insn_unit *)value);
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
@@ -1050,12 +1054,13 @@ static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd,
|
||||
/* Look for host pointer values within 4G of the PC. This happens
|
||||
often when loading pointers to QEMU's own data structures. */
|
||||
if (type == TCG_TYPE_I64) {
|
||||
tcg_target_long disp = value - (intptr_t)s->code_ptr;
|
||||
intptr_t src_rx = (intptr_t)tcg_splitwx_to_rx(s->code_ptr);
|
||||
tcg_target_long disp = value - src_rx;
|
||||
if (disp == sextract64(disp, 0, 21)) {
|
||||
tcg_out_insn(s, 3406, ADR, rd, disp);
|
||||
return;
|
||||
}
|
||||
disp = (value >> 12) - ((intptr_t)s->code_ptr >> 12);
|
||||
disp = (value >> 12) - (src_rx >> 12);
|
||||
if (disp == sextract64(disp, 0, 21)) {
|
||||
tcg_out_insn(s, 3406, ADRP, rd, disp);
|
||||
if (value & 0xfff) {
|
||||
@@ -1306,18 +1311,18 @@ static void tcg_out_cmp(TCGContext *s, TCGType ext, TCGReg a,
|
||||
}
|
||||
}
|
||||
|
||||
static inline void tcg_out_goto(TCGContext *s, tcg_insn_unit *target)
|
||||
static void tcg_out_goto(TCGContext *s, const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = target - s->code_ptr;
|
||||
ptrdiff_t offset = tcg_pcrel_diff(s, target) >> 2;
|
||||
tcg_debug_assert(offset == sextract64(offset, 0, 26));
|
||||
tcg_out_insn(s, 3206, B, offset);
|
||||
}
|
||||
|
||||
static inline void tcg_out_goto_long(TCGContext *s, tcg_insn_unit *target)
|
||||
static void tcg_out_goto_long(TCGContext *s, const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = target - s->code_ptr;
|
||||
ptrdiff_t offset = tcg_pcrel_diff(s, target) >> 2;
|
||||
if (offset == sextract64(offset, 0, 26)) {
|
||||
tcg_out_insn(s, 3206, BL, offset);
|
||||
tcg_out_insn(s, 3206, B, offset);
|
||||
} else {
|
||||
tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_TMP, (intptr_t)target);
|
||||
tcg_out_insn(s, 3207, BR, TCG_REG_TMP);
|
||||
@@ -1329,9 +1334,9 @@ static inline void tcg_out_callr(TCGContext *s, TCGReg reg)
|
||||
tcg_out_insn(s, 3207, BLR, reg);
|
||||
}
|
||||
|
||||
static inline void tcg_out_call(TCGContext *s, tcg_insn_unit *target)
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = target - s->code_ptr;
|
||||
ptrdiff_t offset = tcg_pcrel_diff(s, target) >> 2;
|
||||
if (offset == sextract64(offset, 0, 26)) {
|
||||
tcg_out_insn(s, 3206, BL, offset);
|
||||
} else {
|
||||
@@ -1340,21 +1345,21 @@ static inline void tcg_out_call(TCGContext *s, tcg_insn_unit *target)
|
||||
}
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
uintptr_t addr)
|
||||
void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,
|
||||
uintptr_t jmp_rw, uintptr_t addr)
|
||||
{
|
||||
tcg_insn_unit i1, i2;
|
||||
TCGType rt = TCG_TYPE_I64;
|
||||
TCGReg rd = TCG_REG_TMP;
|
||||
uint64_t pair;
|
||||
|
||||
ptrdiff_t offset = addr - jmp_addr;
|
||||
ptrdiff_t offset = addr - jmp_rx;
|
||||
|
||||
if (offset == sextract64(offset, 0, 26)) {
|
||||
i1 = I3206_B | ((offset >> 2) & 0x3ffffff);
|
||||
i2 = NOP;
|
||||
} else {
|
||||
offset = (addr >> 12) - (jmp_addr >> 12);
|
||||
offset = (addr >> 12) - (jmp_rx >> 12);
|
||||
|
||||
/* patch ADRP */
|
||||
i1 = I3406_ADRP | (offset & 3) << 29 | (offset & 0x1ffffc) << (5 - 2) | rd;
|
||||
@@ -1362,8 +1367,8 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
i2 = I3401_ADDI | rt << 31 | (addr & 0xfff) << 10 | rd << 5 | rd;
|
||||
}
|
||||
pair = (uint64_t)i2 << 32 | i1;
|
||||
qatomic_set((uint64_t *)jmp_addr, pair);
|
||||
flush_icache_range(jmp_addr, jmp_addr + 8);
|
||||
qatomic_set((uint64_t *)jmp_rw, pair);
|
||||
flush_idcache_range(jmp_rx, jmp_rw, 8);
|
||||
}
|
||||
|
||||
static inline void tcg_out_goto_label(TCGContext *s, TCGLabel *l)
|
||||
@@ -1393,7 +1398,7 @@ static void tcg_out_brcond(TCGContext *s, TCGType ext, TCGCond c, TCGArg a,
|
||||
tcg_out_reloc(s, s->code_ptr, R_AARCH64_CONDBR19, l, 0);
|
||||
offset = tcg_in32(s) >> 5;
|
||||
} else {
|
||||
offset = l->u.value_ptr - s->code_ptr;
|
||||
offset = tcg_pcrel_diff(s, l->u.value_ptr) >> 2;
|
||||
tcg_debug_assert(offset == sextract64(offset, 0, 19));
|
||||
}
|
||||
|
||||
@@ -1568,7 +1573,7 @@ static void * const qemu_st_helpers[16] = {
|
||||
[MO_BEQ] = helper_be_stq_mmu,
|
||||
};
|
||||
|
||||
static inline void tcg_out_adr(TCGContext *s, TCGReg rd, void *target)
|
||||
static inline void tcg_out_adr(TCGContext *s, TCGReg rd, const void *target)
|
||||
{
|
||||
ptrdiff_t offset = tcg_pcrel_diff(s, target);
|
||||
tcg_debug_assert(offset == sextract64(offset, 0, 21));
|
||||
@@ -1581,7 +1586,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
MemOp opc = get_memop(oi);
|
||||
MemOp size = opc & MO_SIZE;
|
||||
|
||||
if (!reloc_pc19(lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc19(lb->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1606,7 +1611,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
MemOp opc = get_memop(oi);
|
||||
MemOp size = opc & MO_SIZE;
|
||||
|
||||
if (!reloc_pc19(lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc19(lb->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1631,7 +1636,7 @@ static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi,
|
||||
label->type = ext;
|
||||
label->datalo_reg = data_reg;
|
||||
label->addrlo_reg = addr_reg;
|
||||
label->raddr = raddr;
|
||||
label->raddr = tcg_splitwx_to_rx(raddr);
|
||||
label->label_ptr[0] = label_ptr;
|
||||
}
|
||||
|
||||
@@ -1849,7 +1854,7 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,
|
||||
#endif /* CONFIG_SOFTMMU */
|
||||
}
|
||||
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
|
||||
static void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
const TCGArg args[TCG_MAX_OP_ARGS],
|
||||
@@ -1873,7 +1878,7 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
case INDEX_op_exit_tb:
|
||||
/* Reuse the zeroing that exists for goto_ptr. */
|
||||
if (a0 == 0) {
|
||||
tcg_out_goto_long(s, s->code_gen_epilogue);
|
||||
tcg_out_goto_long(s, tcg_code_gen_epilogue);
|
||||
} else {
|
||||
tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_X0, a0);
|
||||
tcg_out_goto_long(s, tb_ret_addr);
|
||||
@@ -2894,11 +2899,11 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
* Return path for goto_ptr. Set return value to 0, a-la exit_tb,
|
||||
* and fall through to the rest of the epilogue.
|
||||
*/
|
||||
s->code_gen_epilogue = s->code_ptr;
|
||||
tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr);
|
||||
tcg_out_movi(s, TCG_TYPE_REG, TCG_REG_X0, 0);
|
||||
|
||||
/* TB epilogue */
|
||||
tb_ret_addr = s->code_ptr;
|
||||
tb_ret_addr = tcg_splitwx_to_rx(s->code_ptr);
|
||||
|
||||
/* Remove TCG locals stack space. */
|
||||
tcg_out_insn(s, 3401, ADDI, TCG_TYPE_I64, TCG_REG_SP, TCG_REG_SP,
|
||||
@@ -2964,7 +2969,7 @@ static const DebugFrame debug_frame = {
|
||||
}
|
||||
};
|
||||
|
||||
void tcg_register_jit(void *buf, size_t buf_size)
|
||||
void tcg_register_jit(const void *buf, size_t buf_size)
|
||||
{
|
||||
tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame));
|
||||
}
|
||||
@@ -148,12 +148,7 @@ typedef enum {
|
||||
#define TCG_TARGET_DEFAULT_MO (0)
|
||||
#define TCG_TARGET_HAS_MEMORY_BSWAP 1
|
||||
|
||||
static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
__builtin___clear_cache((char *)start, (char *)stop);
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
||||
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
#define TCG_TARGET_NEED_LDST_LABELS
|
||||
|
||||
+22
-19
@@ -187,29 +187,32 @@ static const uint8_t tcg_cond_to_arm_cond[] = {
|
||||
[TCG_COND_GTU] = COND_HI,
|
||||
};
|
||||
|
||||
static inline bool reloc_pc24(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
static bool reloc_pc24(tcg_insn_unit *src_rw, const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = (tcg_ptr_byte_diff(target, code_ptr) - 8) >> 2;
|
||||
const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw);
|
||||
ptrdiff_t offset = (tcg_ptr_byte_diff(target, src_rx) - 8) >> 2;
|
||||
|
||||
if (offset == sextract32(offset, 0, 24)) {
|
||||
*code_ptr = (*code_ptr & ~0xffffff) | (offset & 0xffffff);
|
||||
*src_rw = deposit32(*src_rw, 0, 24, offset);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool reloc_pc13(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
static bool reloc_pc13(tcg_insn_unit *src_rw, const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = tcg_ptr_byte_diff(target, code_ptr) - 8;
|
||||
const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw);
|
||||
ptrdiff_t offset = tcg_ptr_byte_diff(target, src_rx) - 8;
|
||||
|
||||
if (offset >= -0xfff && offset <= 0xfff) {
|
||||
tcg_insn_unit insn = *code_ptr;
|
||||
tcg_insn_unit insn = *src_rw;
|
||||
bool u = (offset >= 0);
|
||||
if (!u) {
|
||||
offset = -offset;
|
||||
}
|
||||
insn = deposit32(insn, 23, 1, u);
|
||||
insn = deposit32(insn, 0, 12, offset);
|
||||
*code_ptr = insn;
|
||||
*src_rw = insn;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -221,9 +224,9 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
tcg_debug_assert(addend == 0);
|
||||
|
||||
if (type == R_ARM_PC24) {
|
||||
return reloc_pc24(code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_pc24(code_ptr, (const tcg_insn_unit *)value);
|
||||
} else if (type == R_ARM_PC13) {
|
||||
return reloc_pc13(code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_pc13(code_ptr, (const tcg_insn_unit *)value);
|
||||
} else {
|
||||
g_assert_not_reached();
|
||||
}
|
||||
@@ -617,7 +620,7 @@ static void tcg_out_movi32(TCGContext *s, int cond, int rd, uint32_t arg)
|
||||
|
||||
/* Check for a pc-relative address. This will usually be the TB,
|
||||
or within the TB, which is immediately before the code block. */
|
||||
diff = arg - ((intptr_t)s->code_ptr + 8);
|
||||
diff = tcg_pcrel_diff(s, (void *)arg) - 8;
|
||||
if (diff >= 0) {
|
||||
rot = encode_imm(diff);
|
||||
if (rot >= 0) {
|
||||
@@ -1019,7 +1022,7 @@ static inline void tcg_out_st8(TCGContext *s, int cond,
|
||||
* with the code buffer limited to 16MB we wouldn't need the long case.
|
||||
* But we also use it for the tail-call to the qemu_ld/st helpers, which does.
|
||||
*/
|
||||
static void tcg_out_goto(TCGContext *s, int cond, tcg_insn_unit *addr)
|
||||
static void tcg_out_goto(TCGContext *s, int cond, const tcg_insn_unit *addr)
|
||||
{
|
||||
intptr_t addri = (intptr_t)addr;
|
||||
ptrdiff_t disp = tcg_pcrel_diff(s, addr);
|
||||
@@ -1033,7 +1036,7 @@ static void tcg_out_goto(TCGContext *s, int cond, tcg_insn_unit *addr)
|
||||
|
||||
/* The call case is mostly used for helpers - so it's not unreasonable
|
||||
* for them to be beyond branch range */
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *addr)
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *addr)
|
||||
{
|
||||
intptr_t addri = (intptr_t)addr;
|
||||
ptrdiff_t disp = tcg_pcrel_diff(s, addr);
|
||||
@@ -1337,7 +1340,7 @@ static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi,
|
||||
label->datahi_reg = datahi;
|
||||
label->addrlo_reg = addrlo;
|
||||
label->addrhi_reg = addrhi;
|
||||
label->raddr = raddr;
|
||||
label->raddr = tcg_splitwx_to_rx(raddr);
|
||||
label->label_ptr[0] = label_ptr;
|
||||
}
|
||||
|
||||
@@ -1348,7 +1351,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
MemOp opc = get_memop(oi);
|
||||
void *func;
|
||||
|
||||
if (!reloc_pc24(lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc24(lb->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1411,7 +1414,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
TCGMemOpIdx oi = lb->oi;
|
||||
MemOp opc = get_memop(oi);
|
||||
|
||||
if (!reloc_pc24(lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc24(lb->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1762,8 +1765,8 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
TCGReg base = TCG_REG_PC;
|
||||
|
||||
tcg_debug_assert(s->tb_jmp_insn_offset == 0);
|
||||
ptr = (intptr_t)(s->tb_jmp_target_addr + args[0]);
|
||||
dif = ptr - ((intptr_t)s->code_ptr + 8);
|
||||
ptr = (intptr_t)tcg_splitwx_to_rx(s->tb_jmp_target_addr + args[0]);
|
||||
dif = tcg_pcrel_diff(s, (void *)ptr) - 8;
|
||||
dil = sextract32(dif, 0, 12);
|
||||
if (dif != dil) {
|
||||
/* The TB is close, but outside the 12 bits addressable by
|
||||
@@ -2297,7 +2300,7 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
* Return path for goto_ptr. Set return value to 0, a-la exit_tb,
|
||||
* and fall through to the rest of the epilogue.
|
||||
*/
|
||||
s->code_gen_epilogue = s->code_ptr;
|
||||
tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr);
|
||||
tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R0, 0);
|
||||
tcg_out_epilogue(s);
|
||||
}
|
||||
@@ -2353,7 +2356,7 @@ static const DebugFrame debug_frame = {
|
||||
}
|
||||
};
|
||||
|
||||
void tcg_register_jit(void *buf, size_t buf_size)
|
||||
void tcg_register_jit(const void *buf, size_t buf_size)
|
||||
{
|
||||
tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame));
|
||||
}
|
||||
@@ -134,13 +134,8 @@ enum {
|
||||
#define TCG_TARGET_DEFAULT_MO (0)
|
||||
#define TCG_TARGET_HAS_MEMORY_BSWAP 1
|
||||
|
||||
static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
__builtin___clear_cache((char *) start, (char *) stop);
|
||||
}
|
||||
|
||||
/* not defined -- call should be eliminated at compile time */
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
||||
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
#define TCG_TARGET_NEED_LDST_LABELS
|
||||
|
||||
+18
-18
@@ -165,7 +165,7 @@ static bool have_lzcnt;
|
||||
# define have_lzcnt 0
|
||||
#endif
|
||||
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
@@ -173,7 +173,7 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
value += addend;
|
||||
switch(type) {
|
||||
case R_386_PC32:
|
||||
value -= (uintptr_t)code_ptr;
|
||||
value -= (uintptr_t)tcg_splitwx_to_rx(code_ptr);
|
||||
if (value != (int32_t)value) {
|
||||
return false;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
tcg_patch32(code_ptr, value);
|
||||
break;
|
||||
case R_386_PC8:
|
||||
value -= (uintptr_t)code_ptr;
|
||||
value -= (uintptr_t)tcg_splitwx_to_rx(code_ptr);
|
||||
if (value != (int8_t)value) {
|
||||
return false;
|
||||
}
|
||||
@@ -1006,7 +1006,7 @@ static void tcg_out_movi(TCGContext *s, TCGType type,
|
||||
}
|
||||
|
||||
/* Try a 7 byte pc-relative lea before the 10 byte movq. */
|
||||
diff = arg - ((uintptr_t)s->code_ptr + 7);
|
||||
diff = tcg_pcrel_diff(s, (const void *)arg) - 7;
|
||||
if (diff == (int32_t)diff) {
|
||||
tcg_out_opc(s, OPC_LEA | P_REXW, ret, 0, 0);
|
||||
tcg_out8(s, (LOWREGMASK(ret) << 3) | 5);
|
||||
@@ -1452,7 +1452,7 @@ static void tcg_out_brcond2(TCGContext *s, const TCGArg *args,
|
||||
default:
|
||||
tcg_abort();
|
||||
}
|
||||
tcg_out_label(s, label_next, s->code_ptr);
|
||||
tcg_out_label(s, label_next);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1494,10 +1494,10 @@ static void tcg_out_setcond2(TCGContext *s, const TCGArg *args,
|
||||
|
||||
tcg_out_movi(s, TCG_TYPE_I32, args[0], 0);
|
||||
tcg_out_jxx(s, JCC_JMP, label_over, 1);
|
||||
tcg_out_label(s, label_true, s->code_ptr);
|
||||
tcg_out_label(s, label_true);
|
||||
|
||||
tcg_out_movi(s, TCG_TYPE_I32, args[0], 1);
|
||||
tcg_out_label(s, label_over, s->code_ptr);
|
||||
tcg_out_label(s, label_over);
|
||||
} else {
|
||||
/* When the destination does not overlap one of the arguments,
|
||||
clear the destination first, jump if cond false, and emit an
|
||||
@@ -1511,7 +1511,7 @@ static void tcg_out_setcond2(TCGContext *s, const TCGArg *args,
|
||||
tcg_out_brcond2(s, new_args, const_args+1, 1);
|
||||
|
||||
tgen_arithi(s, ARITH_ADD, args[0], 1, 0);
|
||||
tcg_out_label(s, label_over, s->code_ptr);
|
||||
tcg_out_label(s, label_over);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1525,7 +1525,7 @@ static void tcg_out_cmov(TCGContext *s, TCGCond cond, int rexw,
|
||||
TCGLabel *over = gen_new_label();
|
||||
tcg_out_jxx(s, tcg_cond_to_jcc[tcg_invert_cond(cond)], over, 1);
|
||||
tcg_out_mov(s, TCG_TYPE_I32, dest, v1);
|
||||
tcg_out_label(s, over, s->code_ptr);
|
||||
tcg_out_label(s, over);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1591,7 +1591,7 @@ static void tcg_out_clz(TCGContext *s, int rexw, TCGReg dest, TCGReg arg1,
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_branch(TCGContext *s, int call, tcg_insn_unit *dest)
|
||||
static void tcg_out_branch(TCGContext *s, int call, const tcg_insn_unit *dest)
|
||||
{
|
||||
intptr_t disp = tcg_pcrel_diff(s, dest) - 5;
|
||||
|
||||
@@ -1610,12 +1610,12 @@ static void tcg_out_branch(TCGContext *s, int call, tcg_insn_unit *dest)
|
||||
}
|
||||
}
|
||||
|
||||
static inline void tcg_out_call(TCGContext *s, tcg_insn_unit *dest)
|
||||
static inline void tcg_out_call(TCGContext *s, const tcg_insn_unit *dest)
|
||||
{
|
||||
tcg_out_branch(s, 1, dest);
|
||||
}
|
||||
|
||||
static void tcg_out_jmp(TCGContext *s, tcg_insn_unit *dest)
|
||||
static void tcg_out_jmp(TCGContext *s, const tcg_insn_unit *dest)
|
||||
{
|
||||
tcg_out_branch(s, 0, dest);
|
||||
}
|
||||
@@ -1786,7 +1786,7 @@ static void add_qemu_ldst_label(TCGContext *s, bool is_ld, bool is_64,
|
||||
label->datahi_reg = datahi;
|
||||
label->addrlo_reg = addrlo;
|
||||
label->addrhi_reg = addrhi;
|
||||
label->raddr = raddr;
|
||||
label->raddr = tcg_splitwx_to_rx(raddr);
|
||||
label->label_ptr[0] = label_ptr[0];
|
||||
if (TARGET_LONG_BITS > TCG_TARGET_REG_BITS) {
|
||||
label->label_ptr[1] = label_ptr[1];
|
||||
@@ -2267,7 +2267,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
case INDEX_op_exit_tb:
|
||||
/* Reuse the zeroing that exists for goto_ptr. */
|
||||
if (a0 == 0) {
|
||||
tcg_out_jmp(s, s->code_gen_epilogue);
|
||||
tcg_out_jmp(s, tcg_code_gen_epilogue);
|
||||
} else {
|
||||
tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_EAX, a0);
|
||||
tcg_out_jmp(s, tb_ret_addr);
|
||||
@@ -2280,7 +2280,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
/* jump displacement must be aligned for atomic patching;
|
||||
* see if we need to add extra nops before jump
|
||||
*/
|
||||
gap = tcg_pcrel_diff(s, QEMU_ALIGN_PTR_UP(s->code_ptr + 1, 4));
|
||||
gap = QEMU_ALIGN_PTR_UP(s->code_ptr + 1, 4) - s->code_ptr;
|
||||
if (gap != 1) {
|
||||
tcg_out_nopn(s, gap - 1);
|
||||
}
|
||||
@@ -3825,11 +3825,11 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
* Return path for goto_ptr. Set return value to 0, a-la exit_tb,
|
||||
* and fall through to the rest of the epilogue.
|
||||
*/
|
||||
s->code_gen_epilogue = s->code_ptr;
|
||||
tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr);
|
||||
tcg_out_movi(s, TCG_TYPE_REG, TCG_REG_EAX, 0);
|
||||
|
||||
/* TB epilogue */
|
||||
tb_ret_addr = s->code_ptr;
|
||||
tb_ret_addr = tcg_splitwx_to_rx(s->code_ptr);
|
||||
|
||||
tcg_out_addi(s, TCG_REG_CALL_STACK, stack_addend);
|
||||
|
||||
@@ -3998,7 +3998,7 @@ static const DebugFrame debug_frame = {
|
||||
#endif
|
||||
|
||||
#if defined(ELF_HOST_MACHINE)
|
||||
void tcg_register_jit(void *buf, size_t buf_size)
|
||||
void tcg_register_jit(const void *buf, size_t buf_size)
|
||||
{
|
||||
tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame));
|
||||
}
|
||||
|
||||
@@ -206,15 +206,11 @@ extern bool have_avx2;
|
||||
#define TCG_TARGET_extract_i64_valid(ofs, len) \
|
||||
(((ofs) == 8 && (len) == 8) || ((ofs) + (len)) == 32)
|
||||
|
||||
static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
}
|
||||
|
||||
static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,
|
||||
uintptr_t jmp_addr, uintptr_t addr)
|
||||
static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,
|
||||
uintptr_t jmp_rw, uintptr_t addr)
|
||||
{
|
||||
/* patch the branch destination */
|
||||
qatomic_set((int32_t *)jmp_addr, addr - (jmp_addr + 4));
|
||||
qatomic_set((int32_t *)jmp_rw, addr - (jmp_rx + 4));
|
||||
/* no need to flush icache explicitly */
|
||||
}
|
||||
|
||||
|
||||
+43
-54
@@ -139,33 +139,21 @@ static const TCGReg tcg_target_call_oarg_regs[2] = {
|
||||
TCG_REG_V1
|
||||
};
|
||||
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
static tcg_insn_unit *bswap32_addr;
|
||||
static tcg_insn_unit *bswap32u_addr;
|
||||
static tcg_insn_unit *bswap64_addr;
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
static const tcg_insn_unit *bswap32_addr;
|
||||
static const tcg_insn_unit *bswap32u_addr;
|
||||
static const tcg_insn_unit *bswap64_addr;
|
||||
|
||||
static inline uint32_t reloc_pc16_val(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
static bool reloc_pc16(tcg_insn_unit *src_rw, const tcg_insn_unit *target)
|
||||
{
|
||||
/* Let the compiler perform the right-shift as part of the arithmetic. */
|
||||
ptrdiff_t disp = target - (pc + 1);
|
||||
tcg_debug_assert(disp == (int16_t)disp);
|
||||
return disp & 0xffff;
|
||||
}
|
||||
|
||||
static inline void reloc_pc16(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
{
|
||||
*pc = deposit32(*pc, 0, 16, reloc_pc16_val(pc, target));
|
||||
}
|
||||
|
||||
static inline uint32_t reloc_26_val(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
{
|
||||
tcg_debug_assert((((uintptr_t)pc ^ (uintptr_t)target) & 0xf0000000) == 0);
|
||||
return ((uintptr_t)target >> 2) & 0x3ffffff;
|
||||
}
|
||||
|
||||
static inline void reloc_26(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
{
|
||||
*pc = deposit32(*pc, 0, 26, reloc_26_val(pc, target));
|
||||
const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw);
|
||||
ptrdiff_t disp = target - (src_rx + 1);
|
||||
if (disp == (int16_t)disp) {
|
||||
*src_rw = deposit32(*src_rw, 0, 16, disp);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
@@ -173,8 +161,7 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
{
|
||||
tcg_debug_assert(type == R_MIPS_PC16);
|
||||
tcg_debug_assert(addend == 0);
|
||||
reloc_pc16(code_ptr, (tcg_insn_unit *)value);
|
||||
return true;
|
||||
return reloc_pc16(code_ptr, (const tcg_insn_unit *)value);
|
||||
}
|
||||
|
||||
#define TCG_CT_CONST_ZERO 0x100
|
||||
@@ -516,10 +503,10 @@ static void tcg_out_opc_sa64(TCGContext *s, MIPSInsn opc1, MIPSInsn opc2,
|
||||
* Type jump.
|
||||
* Returns true if the branch was in range and the insn was emitted.
|
||||
*/
|
||||
static bool tcg_out_opc_jmp(TCGContext *s, MIPSInsn opc, void *target)
|
||||
static bool tcg_out_opc_jmp(TCGContext *s, MIPSInsn opc, const void *target)
|
||||
{
|
||||
uintptr_t dest = (uintptr_t)target;
|
||||
uintptr_t from = (uintptr_t)s->code_ptr + 4;
|
||||
uintptr_t from = (uintptr_t)tcg_splitwx_to_rx(s->code_ptr) + 4;
|
||||
int32_t inst;
|
||||
|
||||
/* The pc-region branch happens within the 256MB region of
|
||||
@@ -631,7 +618,7 @@ static inline void tcg_out_bswap16s(TCGContext *s, TCGReg ret, TCGReg arg)
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_bswap_subr(TCGContext *s, tcg_insn_unit *sub)
|
||||
static void tcg_out_bswap_subr(TCGContext *s, const tcg_insn_unit *sub)
|
||||
{
|
||||
bool ok = tcg_out_opc_jmp(s, OPC_JAL, sub);
|
||||
tcg_debug_assert(ok);
|
||||
@@ -924,11 +911,7 @@ static void tcg_out_brcond(TCGContext *s, TCGCond cond, TCGReg arg1,
|
||||
}
|
||||
|
||||
tcg_out_opc_br(s, b_opc, arg1, arg2);
|
||||
if (l->has_value) {
|
||||
reloc_pc16(s->code_ptr - 1, l->u.value_ptr);
|
||||
} else {
|
||||
tcg_out_reloc(s, s->code_ptr - 1, R_MIPS_PC16, l, 0);
|
||||
}
|
||||
tcg_out_reloc(s, s->code_ptr - 1, R_MIPS_PC16, l, 0);
|
||||
tcg_out_nop(s);
|
||||
}
|
||||
|
||||
@@ -1079,7 +1062,7 @@ static void tcg_out_movcond(TCGContext *s, TCGCond cond, TCGReg ret,
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_call_int(TCGContext *s, tcg_insn_unit *arg, bool tail)
|
||||
static void tcg_out_call_int(TCGContext *s, const tcg_insn_unit *arg, bool tail)
|
||||
{
|
||||
/* Note that the ABI requires the called function's address to be
|
||||
loaded into T9, even if a direct branch is in range. */
|
||||
@@ -1097,7 +1080,7 @@ static void tcg_out_call_int(TCGContext *s, tcg_insn_unit *arg, bool tail)
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *arg)
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *arg)
|
||||
{
|
||||
tcg_out_call_int(s, arg, false);
|
||||
tcg_out_nop(s);
|
||||
@@ -1300,7 +1283,7 @@ static void add_qemu_ldst_label(TCGContext *s, int is_ld, TCGMemOpIdx oi,
|
||||
label->datahi_reg = datahi;
|
||||
label->addrlo_reg = addrlo;
|
||||
label->addrhi_reg = addrhi;
|
||||
label->raddr = raddr;
|
||||
label->raddr = tcg_splitwx_to_rx(raddr);
|
||||
label->label_ptr[0] = label_ptr[0];
|
||||
if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) {
|
||||
label->label_ptr[1] = label_ptr[1];
|
||||
@@ -1309,15 +1292,17 @@ static void add_qemu_ldst_label(TCGContext *s, int is_ld, TCGMemOpIdx oi,
|
||||
|
||||
static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
{
|
||||
const tcg_insn_unit *tgt_rx = tcg_splitwx_to_rx(s->code_ptr);
|
||||
TCGMemOpIdx oi = l->oi;
|
||||
MemOp opc = get_memop(oi);
|
||||
TCGReg v0;
|
||||
int i;
|
||||
|
||||
/* resolve label address */
|
||||
reloc_pc16(l->label_ptr[0], s->code_ptr);
|
||||
if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) {
|
||||
reloc_pc16(l->label_ptr[1], s->code_ptr);
|
||||
if (!reloc_pc16(l->label_ptr[0], tgt_rx)
|
||||
|| (TCG_TARGET_REG_BITS < TARGET_LONG_BITS
|
||||
&& !reloc_pc16(l->label_ptr[1], tgt_rx))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
i = 1;
|
||||
@@ -1345,7 +1330,9 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
}
|
||||
|
||||
tcg_out_opc_br(s, OPC_BEQ, TCG_REG_ZERO, TCG_REG_ZERO);
|
||||
reloc_pc16(s->code_ptr - 1, l->raddr);
|
||||
if (!reloc_pc16(s->code_ptr - 1, l->raddr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* delay slot */
|
||||
if (TCG_TARGET_REG_BITS == 64 && l->type == TCG_TYPE_I32) {
|
||||
@@ -1359,15 +1346,17 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
|
||||
static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
{
|
||||
const tcg_insn_unit *tgt_rx = tcg_splitwx_to_rx(s->code_ptr);
|
||||
TCGMemOpIdx oi = l->oi;
|
||||
MemOp opc = get_memop(oi);
|
||||
MemOp s_bits = opc & MO_SIZE;
|
||||
int i;
|
||||
|
||||
/* resolve label address */
|
||||
reloc_pc16(l->label_ptr[0], s->code_ptr);
|
||||
if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) {
|
||||
reloc_pc16(l->label_ptr[1], s->code_ptr);
|
||||
if (!reloc_pc16(l->label_ptr[0], tgt_rx)
|
||||
|| (TCG_TARGET_REG_BITS < TARGET_LONG_BITS
|
||||
&& !reloc_pc16(l->label_ptr[1], tgt_rx))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
i = 1;
|
||||
@@ -2483,11 +2472,11 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
* Return path for goto_ptr. Set return value to 0, a-la exit_tb,
|
||||
* and fall through to the rest of the epilogue.
|
||||
*/
|
||||
s->code_gen_epilogue = s->code_ptr;
|
||||
tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr);
|
||||
tcg_out_mov(s, TCG_TYPE_REG, TCG_REG_V0, TCG_REG_ZERO);
|
||||
|
||||
/* TB epilogue */
|
||||
tb_ret_addr = s->code_ptr;
|
||||
tb_ret_addr = tcg_splitwx_to_rx(s->code_ptr);
|
||||
for (i = 0; i < ARRAY_SIZE(tcg_target_callee_save_regs); i++) {
|
||||
tcg_out_ld(s, TCG_TYPE_REG, tcg_target_callee_save_regs[i],
|
||||
TCG_REG_SP, SAVE_OFS + i * REG_SIZE);
|
||||
@@ -2507,7 +2496,7 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
/*
|
||||
* bswap32 -- 32-bit swap (signed result for mips64). a0 = abcd.
|
||||
*/
|
||||
bswap32_addr = align_code_ptr(s);
|
||||
bswap32_addr = tcg_splitwx_to_rx(align_code_ptr(s));
|
||||
/* t3 = (ssss)d000 */
|
||||
tcg_out_opc_sa(s, OPC_SLL, TCG_TMP3, TCG_TMP0, 24);
|
||||
/* t1 = 000a */
|
||||
@@ -2535,7 +2524,7 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
/*
|
||||
* bswap32u -- unsigned 32-bit swap. a0 = ....abcd.
|
||||
*/
|
||||
bswap32u_addr = align_code_ptr(s);
|
||||
bswap32u_addr = tcg_splitwx_to_rx(align_code_ptr(s));
|
||||
/* t1 = (0000)000d */
|
||||
tcg_out_opc_imm(s, OPC_ANDI, TCG_TMP1, TCG_TMP0, 0xff);
|
||||
/* t3 = 000a */
|
||||
@@ -2561,7 +2550,7 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
/*
|
||||
* bswap64 -- 64-bit swap. a0 = abcdefgh
|
||||
*/
|
||||
bswap64_addr = align_code_ptr(s);
|
||||
bswap64_addr = tcg_splitwx_to_rx(align_code_ptr(s));
|
||||
/* t3 = h0000000 */
|
||||
tcg_out_dsll(s, TCG_TMP3, TCG_TMP0, 56);
|
||||
/* t1 = 0000000a */
|
||||
@@ -2656,11 +2645,11 @@ static void tcg_target_init(TCGContext *s)
|
||||
tcg_regset_set_reg(s->reserved_regs, TCG_REG_GP); /* global pointer */
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
uintptr_t addr)
|
||||
void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,
|
||||
uintptr_t jmp_rw, uintptr_t addr)
|
||||
{
|
||||
qatomic_set((uint32_t *)jmp_addr, deposit32(OPC_J, 0, 26, addr >> 2));
|
||||
flush_icache_range(jmp_addr, jmp_addr + 4);
|
||||
qatomic_set((uint32_t *)jmp_rw, deposit32(OPC_J, 0, 26, addr >> 2));
|
||||
flush_idcache_range(jmp_rx, jmp_rw, 4);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
@@ -2702,7 +2691,7 @@ static const DebugFrame debug_frame = {
|
||||
}
|
||||
};
|
||||
|
||||
void tcg_register_jit(void *buf, size_t buf_size)
|
||||
void tcg_register_jit(const void *buf, size_t buf_size)
|
||||
{
|
||||
tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame));
|
||||
}
|
||||
+1
-12
@@ -198,21 +198,10 @@ extern bool use_mips32r2_instructions;
|
||||
#define TCG_TARGET_HAS_ext16u_i64 0 /* andi rt, rs, 0xffff */
|
||||
#endif
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
#include <machine/sysarch.h>
|
||||
#else
|
||||
#include <sys/cachectl.h>
|
||||
#endif
|
||||
|
||||
#define TCG_TARGET_DEFAULT_MO (0)
|
||||
#define TCG_TARGET_HAS_MEMORY_BSWAP 1
|
||||
|
||||
static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
cacheflush ((void *)start, stop-start, ICACHE);
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
||||
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
#define TCG_TARGET_NEED_LDST_LABELS
|
||||
|
||||
+46
-64
@@ -62,8 +62,6 @@
|
||||
#define TCG_CT_CONST_MONE 0x2000
|
||||
#define TCG_CT_CONST_WSZ 0x4000
|
||||
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
|
||||
TCGPowerISA have_isa;
|
||||
static bool have_isel;
|
||||
bool have_altivec;
|
||||
@@ -184,35 +182,41 @@ static inline bool in_range_b(tcg_target_long target)
|
||||
return target == sextract64(target, 0, 26);
|
||||
}
|
||||
|
||||
static uint32_t reloc_pc24_val(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
static uint32_t reloc_pc24_val(const tcg_insn_unit *pc,
|
||||
const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t disp = tcg_ptr_byte_diff(target, pc);
|
||||
tcg_debug_assert(in_range_b(disp));
|
||||
return disp & 0x3fffffc;
|
||||
}
|
||||
|
||||
static bool reloc_pc24(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
static bool reloc_pc24(tcg_insn_unit *src_rw, const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t disp = tcg_ptr_byte_diff(target, pc);
|
||||
const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw);
|
||||
ptrdiff_t disp = tcg_ptr_byte_diff(target, src_rx);
|
||||
|
||||
if (in_range_b(disp)) {
|
||||
*pc = (*pc & ~0x3fffffc) | (disp & 0x3fffffc);
|
||||
*src_rw = (*src_rw & ~0x3fffffc) | (disp & 0x3fffffc);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static uint16_t reloc_pc14_val(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
static uint16_t reloc_pc14_val(const tcg_insn_unit *pc,
|
||||
const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t disp = tcg_ptr_byte_diff(target, pc);
|
||||
tcg_debug_assert(disp == (int16_t) disp);
|
||||
return disp & 0xfffc;
|
||||
}
|
||||
|
||||
static bool reloc_pc14(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
static bool reloc_pc14(tcg_insn_unit *src_rw, const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t disp = tcg_ptr_byte_diff(target, pc);
|
||||
const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw);
|
||||
ptrdiff_t disp = tcg_ptr_byte_diff(target, src_rx);
|
||||
|
||||
if (disp == (int16_t) disp) {
|
||||
*pc = (*pc & ~0xfffc) | (disp & 0xfffc);
|
||||
*src_rw = (*src_rw & ~0xfffc) | (disp & 0xfffc);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -673,12 +677,12 @@ static const uint32_t tcg_to_isel[] = {
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
tcg_insn_unit *target;
|
||||
const tcg_insn_unit *target;
|
||||
int16_t lo;
|
||||
int32_t hi;
|
||||
|
||||
value += addend;
|
||||
target = (tcg_insn_unit *)value;
|
||||
target = (const tcg_insn_unit *)value;
|
||||
|
||||
switch (type) {
|
||||
case R_PPC_REL14:
|
||||
@@ -837,7 +841,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,
|
||||
}
|
||||
|
||||
/* Load addresses within the TB with one insn. */
|
||||
tb_diff = arg - (intptr_t)s->code_gen_ptr;
|
||||
tb_diff = tcg_tbrel_diff(s, (void *)arg);
|
||||
if (!in_prologue && USE_REG_TB && tb_diff == (int16_t)tb_diff) {
|
||||
tcg_out32(s, ADDI | TAI(ret, TCG_REG_TB, tb_diff));
|
||||
return;
|
||||
@@ -890,7 +894,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,
|
||||
/* Use the constant pool, if possible. */
|
||||
if (!in_prologue && USE_REG_TB) {
|
||||
new_pool_label(s, arg, R_PPC_ADDR16, s->code_ptr,
|
||||
-(intptr_t)s->code_gen_ptr);
|
||||
tcg_tbrel_diff(s, NULL));
|
||||
tcg_out32(s, LD | TAI(ret, TCG_REG_TB, 0));
|
||||
return;
|
||||
}
|
||||
@@ -940,7 +944,7 @@ static void tcg_out_dupi_vec(TCGContext *s, TCGType type, TCGReg ret,
|
||||
*/
|
||||
if (USE_REG_TB) {
|
||||
rel = R_PPC_ADDR16;
|
||||
add = -(intptr_t)s->code_gen_ptr;
|
||||
add = tcg_tbrel_diff(s, NULL);
|
||||
} else {
|
||||
rel = R_PPC_ADDR32;
|
||||
add = 0;
|
||||
@@ -1106,7 +1110,7 @@ static void tcg_out_xori32(TCGContext *s, TCGReg dst, TCGReg src, uint32_t c)
|
||||
tcg_out_zori32(s, dst, src, c, XORI, XORIS);
|
||||
}
|
||||
|
||||
static void tcg_out_b(TCGContext *s, int mask, tcg_insn_unit *target)
|
||||
static void tcg_out_b(TCGContext *s, int mask, const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t disp = tcg_pcrel_diff(s, target);
|
||||
if (in_range_b(disp)) {
|
||||
@@ -1544,7 +1548,7 @@ static void tcg_out_setcond(TCGContext *s, TCGType type, TCGCond cond,
|
||||
static void tcg_out_bc(TCGContext *s, int bc, TCGLabel *l)
|
||||
{
|
||||
if (l->has_value) {
|
||||
bc |= reloc_pc14_val(s->code_ptr, l->u.value_ptr);
|
||||
bc |= reloc_pc14_val(tcg_splitwx_to_rx(s->code_ptr), l->u.value_ptr);
|
||||
} else {
|
||||
tcg_out_reloc(s, s->code_ptr, R_PPC_REL14, l, 0);
|
||||
}
|
||||
@@ -1722,13 +1726,13 @@ static void tcg_out_mb(TCGContext *s, TCGArg a0)
|
||||
tcg_out32(s, insn);
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
uintptr_t addr)
|
||||
void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,
|
||||
uintptr_t jmp_rw, uintptr_t addr)
|
||||
{
|
||||
if (TCG_TARGET_REG_BITS == 64) {
|
||||
tcg_insn_unit i1, i2;
|
||||
intptr_t tb_diff = addr - tc_ptr;
|
||||
intptr_t br_diff = addr - (jmp_addr + 4);
|
||||
intptr_t br_diff = addr - (jmp_rx + 4);
|
||||
uint64_t pair;
|
||||
|
||||
/* This does not exercise the range of the branch, but we do
|
||||
@@ -1752,23 +1756,23 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
|
||||
/* As per the enclosing if, this is ppc64. Avoid the _Static_assert
|
||||
within qatomic_set that would fail to build a ppc32 host. */
|
||||
qatomic_set__nocheck((uint64_t *)jmp_addr, pair);
|
||||
flush_icache_range(jmp_addr, jmp_addr + 8);
|
||||
qatomic_set__nocheck((uint64_t *)jmp_rw, pair);
|
||||
flush_idcache_range(jmp_rx, jmp_rw, 8);
|
||||
} else {
|
||||
intptr_t diff = addr - jmp_addr;
|
||||
intptr_t diff = addr - jmp_rx;
|
||||
tcg_debug_assert(in_range_b(diff));
|
||||
qatomic_set((uint32_t *)jmp_addr, B | (diff & 0x3fffffc));
|
||||
flush_icache_range(jmp_addr, jmp_addr + 4);
|
||||
qatomic_set((uint32_t *)jmp_rw, B | (diff & 0x3fffffc));
|
||||
flush_idcache_range(jmp_rx, jmp_rw, 4);
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *target)
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target)
|
||||
{
|
||||
#ifdef _CALL_AIX
|
||||
/* Look through the descriptor. If the branch is in range, and we
|
||||
don't have to spend too much effort on building the toc. */
|
||||
void *tgt = ((void **)target)[0];
|
||||
uintptr_t toc = ((uintptr_t *)target)[1];
|
||||
const void *tgt = ((const void * const *)target)[0];
|
||||
uintptr_t toc = ((const uintptr_t *)target)[1];
|
||||
intptr_t diff = tcg_pcrel_diff(s, tgt);
|
||||
|
||||
if (in_range_b(diff) && toc == (uint32_t)toc) {
|
||||
@@ -1997,7 +2001,7 @@ static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi,
|
||||
label->datahi_reg = datahi_reg;
|
||||
label->addrlo_reg = addrlo_reg;
|
||||
label->addrhi_reg = addrhi_reg;
|
||||
label->raddr = raddr;
|
||||
label->raddr = tcg_splitwx_to_rx(raddr);
|
||||
label->label_ptr[0] = lptr;
|
||||
}
|
||||
|
||||
@@ -2007,7 +2011,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
MemOp opc = get_memop(oi);
|
||||
TCGReg hi, lo, arg = TCG_REG_R3;
|
||||
|
||||
if (!reloc_pc14(lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc14(lb->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2055,7 +2059,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
MemOp s_bits = opc & MO_SIZE;
|
||||
TCGReg hi, lo, arg = TCG_REG_R3;
|
||||
|
||||
if (!reloc_pc14(lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc14(lb->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2306,10 +2310,10 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
int i;
|
||||
|
||||
#ifdef _CALL_AIX
|
||||
void **desc = (void **)s->code_ptr;
|
||||
desc[0] = desc + 2; /* entry point */
|
||||
desc[1] = 0; /* environment pointer */
|
||||
s->code_ptr = (void *)(desc + 2); /* skip over descriptor */
|
||||
const void **desc = (const void **)s->code_ptr;
|
||||
desc[0] = tcg_splitwx_to_rx(desc + 2); /* entry point */
|
||||
desc[1] = 0; /* environment pointer */
|
||||
s->code_ptr = (void *)(desc + 2); /* skip over descriptor */
|
||||
#endif
|
||||
|
||||
tcg_set_frame(s, TCG_REG_CALL_STACK, REG_SAVE_BOT - CPU_TEMP_BUF_SIZE,
|
||||
@@ -2341,7 +2345,7 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
tcg_out32(s, BCCTR | BO_ALWAYS);
|
||||
|
||||
/* Epilogue */
|
||||
s->code_gen_epilogue = tb_ret_addr = s->code_ptr;
|
||||
tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr);
|
||||
|
||||
tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_R0, TCG_REG_R1, FRAME_SIZE+LR_OFFSET);
|
||||
for (i = 0; i < ARRAY_SIZE(tcg_target_callee_save_regs); ++i) {
|
||||
@@ -2362,7 +2366,7 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args,
|
||||
switch (opc) {
|
||||
case INDEX_op_exit_tb:
|
||||
tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R3, args[0]);
|
||||
tcg_out_b(s, 0, tb_ret_addr);
|
||||
tcg_out_b(s, 0, tcg_code_gen_epilogue);
|
||||
break;
|
||||
case INDEX_op_goto_tb:
|
||||
if (s->tb_jmp_insn_offset) {
|
||||
@@ -2392,9 +2396,8 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args,
|
||||
set_jmp_reset_offset(s, args[0]);
|
||||
if (USE_REG_TB) {
|
||||
/* For the unlinked case, need to reset TCG_REG_TB. */
|
||||
c = -tcg_current_code_size(s);
|
||||
assert(c == (int16_t)c);
|
||||
tcg_out32(s, ADDI | TAI(TCG_REG_TB, TCG_REG_TB, c));
|
||||
tcg_out_mem_long(s, ADDI, ADD, TCG_REG_TB, TCG_REG_TB,
|
||||
-tcg_current_code_size(s));
|
||||
}
|
||||
break;
|
||||
case INDEX_op_goto_ptr:
|
||||
@@ -2411,7 +2414,8 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args,
|
||||
uint32_t insn = B;
|
||||
|
||||
if (l->has_value) {
|
||||
insn |= reloc_pc24_val(s->code_ptr, l->u.value_ptr);
|
||||
insn |= reloc_pc24_val(tcg_splitwx_to_rx(s->code_ptr),
|
||||
l->u.value_ptr);
|
||||
} else {
|
||||
tcg_out_reloc(s, s->code_ptr, R_PPC_REL24, l, 0);
|
||||
}
|
||||
@@ -3847,7 +3851,7 @@ static DebugFrame debug_frame = {
|
||||
}
|
||||
};
|
||||
|
||||
void tcg_register_jit(void *buf, size_t buf_size)
|
||||
void tcg_register_jit(const void *buf, size_t buf_size)
|
||||
{
|
||||
uint8_t *p = &debug_frame.fde_reg_ofs[3];
|
||||
int i;
|
||||
@@ -3863,25 +3867,3 @@ void tcg_register_jit(void *buf, size_t buf_size)
|
||||
tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame));
|
||||
}
|
||||
#endif /* __ELF__ */
|
||||
|
||||
void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
uintptr_t p, start1, stop1;
|
||||
size_t dsize = qemu_dcache_linesize;
|
||||
size_t isize = qemu_icache_linesize;
|
||||
|
||||
start1 = start & ~(dsize - 1);
|
||||
stop1 = (stop + dsize - 1) & ~(dsize - 1);
|
||||
for (p = start1; p < stop1; p += dsize) {
|
||||
asm volatile ("dcbst 0,%0" : : "r"(p) : "memory");
|
||||
}
|
||||
asm volatile ("sync" : : : "memory");
|
||||
|
||||
start &= start & ~(isize - 1);
|
||||
stop1 = (stop + isize - 1) & ~(isize - 1);
|
||||
for (p = start1; p < stop1; p += isize) {
|
||||
asm volatile ("icbi 0,%0" : : "r"(p) : "memory");
|
||||
}
|
||||
asm volatile ("sync" : : : "memory");
|
||||
asm volatile ("isync" : : : "memory");
|
||||
}
|
||||
@@ -175,8 +175,7 @@ extern bool have_vsx;
|
||||
#define TCG_TARGET_HAS_bitsel_vec have_vsx
|
||||
#define TCG_TARGET_HAS_cmpsel_vec 0
|
||||
|
||||
void flush_icache_range(uintptr_t start, uintptr_t stop);
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
||||
|
||||
#define TCG_TARGET_DEFAULT_MO (0)
|
||||
#define TCG_TARGET_HAS_MEMORY_BSWAP 1
|
||||
|
||||
+43
-82
@@ -425,39 +425,44 @@ static void tcg_out_nop_fill(tcg_insn_unit *p, int count)
|
||||
* Relocations
|
||||
*/
|
||||
|
||||
static bool reloc_sbimm12(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
static bool reloc_sbimm12(tcg_insn_unit *src_rw, const tcg_insn_unit *target)
|
||||
{
|
||||
intptr_t offset = (intptr_t)target - (intptr_t)code_ptr;
|
||||
const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw);
|
||||
intptr_t offset = (intptr_t)target - (intptr_t)src_rx;
|
||||
|
||||
if (offset == sextreg(offset, 1, 12) << 1) {
|
||||
code_ptr[0] |= encode_sbimm12(offset);
|
||||
tcg_debug_assert((offset & 1) == 0);
|
||||
if (offset == sextreg(offset, 0, 12)) {
|
||||
*src_rw |= encode_sbimm12(offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool reloc_jimm20(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
static bool reloc_jimm20(tcg_insn_unit *src_rw, const tcg_insn_unit *target)
|
||||
{
|
||||
intptr_t offset = (intptr_t)target - (intptr_t)code_ptr;
|
||||
const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw);
|
||||
intptr_t offset = (intptr_t)target - (intptr_t)src_rx;
|
||||
|
||||
if (offset == sextreg(offset, 1, 20) << 1) {
|
||||
code_ptr[0] |= encode_ujimm20(offset);
|
||||
tcg_debug_assert((offset & 1) == 0);
|
||||
if (offset == sextreg(offset, 0, 20)) {
|
||||
*src_rw |= encode_ujimm20(offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool reloc_call(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
static bool reloc_call(tcg_insn_unit *src_rw, const tcg_insn_unit *target)
|
||||
{
|
||||
intptr_t offset = (intptr_t)target - (intptr_t)code_ptr;
|
||||
const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw);
|
||||
intptr_t offset = (intptr_t)target - (intptr_t)src_rx;
|
||||
int32_t lo = sextreg(offset, 0, 12);
|
||||
int32_t hi = offset - lo;
|
||||
|
||||
if (offset == hi + lo) {
|
||||
code_ptr[0] |= encode_uimm20(hi);
|
||||
code_ptr[1] |= encode_imm12(lo);
|
||||
src_rw[0] |= encode_uimm20(hi);
|
||||
src_rw[1] |= encode_imm12(lo);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -467,43 +472,16 @@ static bool reloc_call(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
uint32_t insn = *code_ptr;
|
||||
intptr_t diff;
|
||||
bool short_jmp;
|
||||
|
||||
tcg_debug_assert(addend == 0);
|
||||
|
||||
switch (type) {
|
||||
case R_RISCV_BRANCH:
|
||||
diff = value - (uintptr_t)code_ptr;
|
||||
short_jmp = diff == sextreg(diff, 0, 12);
|
||||
if (short_jmp) {
|
||||
return reloc_sbimm12(code_ptr, (tcg_insn_unit *)value);
|
||||
} else {
|
||||
/* Invert the condition */
|
||||
insn = insn ^ (1 << 12);
|
||||
/* Clear the offset */
|
||||
insn &= 0x01fff07f;
|
||||
/* Set the offset to the PC + 8 */
|
||||
insn |= encode_sbimm12(8);
|
||||
|
||||
/* Move forward */
|
||||
code_ptr[0] = insn;
|
||||
|
||||
/* Overwrite the NOP with jal x0,value */
|
||||
diff = value - (uintptr_t)(code_ptr + 1);
|
||||
insn = encode_uj(OPC_JAL, TCG_REG_ZERO, diff);
|
||||
code_ptr[1] = insn;
|
||||
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
return reloc_sbimm12(code_ptr, (tcg_insn_unit *)value);
|
||||
case R_RISCV_JAL:
|
||||
return reloc_jimm20(code_ptr, (tcg_insn_unit *)value);
|
||||
case R_RISCV_CALL:
|
||||
return reloc_call(code_ptr, (tcg_insn_unit *)value);
|
||||
default:
|
||||
tcg_abort();
|
||||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -557,7 +535,7 @@ static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd,
|
||||
if (tmp == (int32_t)tmp) {
|
||||
tcg_out_opc_upper(s, OPC_AUIPC, rd, 0);
|
||||
tcg_out_opc_imm(s, OPC_ADDI, rd, rd, 0);
|
||||
ret = reloc_call(s->code_ptr - 2, (tcg_insn_unit *)val);
|
||||
ret = reloc_call(s->code_ptr - 2, (const tcg_insn_unit *)val);
|
||||
tcg_debug_assert(ret == true);
|
||||
return;
|
||||
}
|
||||
@@ -777,21 +755,8 @@ static void tcg_out_brcond(TCGContext *s, TCGCond cond, TCGReg arg1,
|
||||
arg2 = t;
|
||||
}
|
||||
|
||||
if (l->has_value) {
|
||||
intptr_t diff = tcg_pcrel_diff(s, l->u.value_ptr);
|
||||
if (diff == sextreg(diff, 0, 12)) {
|
||||
tcg_out_opc_branch(s, op, arg1, arg2, diff);
|
||||
} else {
|
||||
/* Invert the conditional branch. */
|
||||
tcg_out_opc_branch(s, op ^ (1 << 12), arg1, arg2, 8);
|
||||
tcg_out_opc_jump(s, OPC_JAL, TCG_REG_ZERO, diff - 4);
|
||||
}
|
||||
} else {
|
||||
tcg_out_reloc(s, s->code_ptr, R_RISCV_BRANCH, l, 0);
|
||||
tcg_out_opc_branch(s, op, arg1, arg2, 0);
|
||||
/* NOP to allow patching later */
|
||||
tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_ZERO, TCG_REG_ZERO, 0);
|
||||
}
|
||||
tcg_out_reloc(s, s->code_ptr, R_RISCV_BRANCH, l, 0);
|
||||
tcg_out_opc_branch(s, op, arg1, arg2, 0);
|
||||
}
|
||||
|
||||
static void tcg_out_setcond(TCGContext *s, TCGCond cond, TCGReg ret,
|
||||
@@ -854,28 +819,21 @@ static void tcg_out_setcond2(TCGContext *s, TCGCond cond, TCGReg ret,
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
static inline void tcg_out_goto(TCGContext *s, tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = tcg_pcrel_diff(s, target);
|
||||
tcg_debug_assert(offset == sextreg(offset, 1, 20) << 1);
|
||||
tcg_out_opc_jump(s, OPC_JAL, TCG_REG_ZERO, offset);
|
||||
}
|
||||
|
||||
static void tcg_out_call_int(TCGContext *s, tcg_insn_unit *arg, bool tail)
|
||||
static void tcg_out_call_int(TCGContext *s, const tcg_insn_unit *arg, bool tail)
|
||||
{
|
||||
TCGReg link = tail ? TCG_REG_ZERO : TCG_REG_RA;
|
||||
ptrdiff_t offset = tcg_pcrel_diff(s, arg);
|
||||
int ret;
|
||||
|
||||
if (offset == sextreg(offset, 1, 20) << 1) {
|
||||
tcg_debug_assert((offset & 1) == 0);
|
||||
if (offset == sextreg(offset, 0, 20)) {
|
||||
/* short jump: -2097150 to 2097152 */
|
||||
tcg_out_opc_jump(s, OPC_JAL, link, offset);
|
||||
} else if (TCG_TARGET_REG_BITS == 32 ||
|
||||
offset == sextreg(offset, 1, 31) << 1) {
|
||||
} else if (TCG_TARGET_REG_BITS == 32 || offset == (int32_t)offset) {
|
||||
/* long jump: -2147483646 to 2147483648 */
|
||||
tcg_out_opc_upper(s, OPC_AUIPC, TCG_REG_TMP0, 0);
|
||||
tcg_out_opc_imm(s, OPC_JALR, link, TCG_REG_TMP0, 0);
|
||||
ret = reloc_call(s->code_ptr - 2, arg);\
|
||||
ret = reloc_call(s->code_ptr - 2, arg);
|
||||
tcg_debug_assert(ret == true);
|
||||
} else if (TCG_TARGET_REG_BITS == 64) {
|
||||
/* far jump: 64-bit */
|
||||
@@ -888,7 +846,7 @@ static void tcg_out_call_int(TCGContext *s, tcg_insn_unit *arg, bool tail)
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *arg)
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *arg)
|
||||
{
|
||||
tcg_out_call_int(s, arg, false);
|
||||
}
|
||||
@@ -962,6 +920,13 @@ QEMU_BUILD_BUG_ON(TCG_TARGET_REG_BITS < TARGET_LONG_BITS);
|
||||
QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) > 0);
|
||||
QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) < -(1 << 11));
|
||||
|
||||
static void tcg_out_goto(TCGContext *s, const tcg_insn_unit *target)
|
||||
{
|
||||
tcg_out_opc_jump(s, OPC_JAL, TCG_REG_ZERO, 0);
|
||||
bool ok = reloc_jimm20(s->code_ptr - 1, target);
|
||||
tcg_debug_assert(ok);
|
||||
}
|
||||
|
||||
static void tcg_out_tlb_load(TCGContext *s, TCGReg addrl,
|
||||
TCGReg addrh, TCGMemOpIdx oi,
|
||||
tcg_insn_unit **label_ptr, bool is_load)
|
||||
@@ -1007,8 +972,6 @@ static void tcg_out_tlb_load(TCGContext *s, TCGReg addrl,
|
||||
/* Compare masked address with the TLB entry. */
|
||||
label_ptr[0] = s->code_ptr;
|
||||
tcg_out_opc_branch(s, OPC_BNE, TCG_REG_TMP0, TCG_REG_TMP1, 0);
|
||||
/* NOP to allow patching later */
|
||||
tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_ZERO, TCG_REG_ZERO, 0);
|
||||
|
||||
/* TLB Hit - translate address using addend. */
|
||||
if (TCG_TARGET_REG_BITS > TARGET_LONG_BITS) {
|
||||
@@ -1033,7 +996,7 @@ static void add_qemu_ldst_label(TCGContext *s, int is_ld, TCGMemOpIdx oi,
|
||||
label->datahi_reg = datahi;
|
||||
label->addrlo_reg = addrlo;
|
||||
label->addrhi_reg = addrhi;
|
||||
label->raddr = raddr;
|
||||
label->raddr = tcg_splitwx_to_rx(raddr);
|
||||
label->label_ptr[0] = label_ptr[0];
|
||||
}
|
||||
|
||||
@@ -1052,8 +1015,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
}
|
||||
|
||||
/* resolve label address */
|
||||
if (!patch_reloc(l->label_ptr[0], R_RISCV_BRANCH,
|
||||
(intptr_t) s->code_ptr, 0)) {
|
||||
if (!reloc_sbimm12(l->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1087,8 +1049,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
}
|
||||
|
||||
/* resolve label address */
|
||||
if (!patch_reloc(l->label_ptr[0], R_RISCV_BRANCH,
|
||||
(intptr_t) s->code_ptr, 0)) {
|
||||
if (!reloc_sbimm12(l->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1274,7 +1235,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)
|
||||
#endif
|
||||
}
|
||||
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
|
||||
static void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
const TCGArg *args, const int *const_args)
|
||||
@@ -1288,7 +1249,7 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
case INDEX_op_exit_tb:
|
||||
/* Reuse the zeroing that exists for goto_ptr. */
|
||||
if (a0 == 0) {
|
||||
tcg_out_call_int(s, s->code_gen_epilogue, true);
|
||||
tcg_out_call_int(s, tcg_code_gen_epilogue, true);
|
||||
} else {
|
||||
tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_A0, a0);
|
||||
tcg_out_call_int(s, tb_ret_addr, true);
|
||||
@@ -1822,11 +1783,11 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
tcg_out_opc_imm(s, OPC_JALR, TCG_REG_ZERO, tcg_target_call_iarg_regs[1], 0);
|
||||
|
||||
/* Return path for goto_ptr. Set return value to 0 */
|
||||
s->code_gen_epilogue = s->code_ptr;
|
||||
tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr);
|
||||
tcg_out_mov(s, TCG_TYPE_REG, TCG_REG_A0, TCG_REG_ZERO);
|
||||
|
||||
/* TB epilogue */
|
||||
tb_ret_addr = s->code_ptr;
|
||||
tb_ret_addr = tcg_splitwx_to_rx(s->code_ptr);
|
||||
for (i = 0; i < ARRAY_SIZE(tcg_target_callee_save_regs); i++) {
|
||||
tcg_out_ld(s, TCG_TYPE_REG, tcg_target_callee_save_regs[i],
|
||||
TCG_REG_SP, SAVE_OFS + i * REG_SIZE);
|
||||
@@ -1907,7 +1868,7 @@ static const DebugFrame debug_frame = {
|
||||
}
|
||||
};
|
||||
|
||||
void tcg_register_jit(void *buf, size_t buf_size)
|
||||
void tcg_register_jit(const void *buf, size_t buf_size)
|
||||
{
|
||||
tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame));
|
||||
}
|
||||
@@ -159,13 +159,8 @@ typedef enum {
|
||||
#define TCG_TARGET_HAS_mulsh_i64 1
|
||||
#endif
|
||||
|
||||
static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
__builtin___clear_cache((char *)start, (char *)stop);
|
||||
}
|
||||
|
||||
/* not defined -- call should be eliminated at compile time */
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
||||
|
||||
#define TCG_TARGET_DEFAULT_MO (0)
|
||||
|
||||
|
||||
+40
-51
@@ -363,36 +363,37 @@ static void * const qemu_st_helpers[16] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
uint64_t s390_facilities;
|
||||
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(tcg_insn_unit *src_rw, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw);
|
||||
intptr_t pcrel2;
|
||||
uint32_t old;
|
||||
|
||||
value += addend;
|
||||
pcrel2 = (tcg_insn_unit *)value - code_ptr;
|
||||
pcrel2 = (tcg_insn_unit *)value - src_rx;
|
||||
|
||||
switch (type) {
|
||||
case R_390_PC16DBL:
|
||||
if (pcrel2 == (int16_t)pcrel2) {
|
||||
tcg_patch16(code_ptr, pcrel2);
|
||||
tcg_patch16(src_rw, pcrel2);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case R_390_PC32DBL:
|
||||
if (pcrel2 == (int32_t)pcrel2) {
|
||||
tcg_patch32(code_ptr, pcrel2);
|
||||
tcg_patch32(src_rw, pcrel2);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case R_390_20:
|
||||
if (value == sextract64(value, 0, 20)) {
|
||||
old = *(uint32_t *)code_ptr & 0xf00000ff;
|
||||
old = *(uint32_t *)src_rw & 0xf00000ff;
|
||||
old |= ((value & 0xfff) << 16) | ((value & 0xff000) >> 4);
|
||||
tcg_patch32(code_ptr, old);
|
||||
tcg_patch32(src_rw, old);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -630,7 +631,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,
|
||||
return;
|
||||
}
|
||||
} else if (USE_REG_TB && !in_prologue) {
|
||||
ptrdiff_t off = sval - (uintptr_t)s->code_gen_ptr;
|
||||
ptrdiff_t off = tcg_tbrel_diff(s, (void *)sval);
|
||||
if (off == sextract64(off, 0, 20)) {
|
||||
/* This is certain to be an address within TB, and therefore
|
||||
OFF will be negative; don't try RX_LA. */
|
||||
@@ -655,7 +656,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,
|
||||
} else if (USE_REG_TB && !in_prologue) {
|
||||
tcg_out_insn(s, RXY, LG, ret, TCG_REG_TB, TCG_REG_NONE, 0);
|
||||
new_pool_label(s, sval, R_390_20, s->code_ptr - 2,
|
||||
-(intptr_t)s->code_gen_ptr);
|
||||
tcg_tbrel_diff(s, NULL));
|
||||
} else {
|
||||
TCGReg base = ret ? ret : TCG_TMP0;
|
||||
tcg_out_insn(s, RIL, LARL, base, 0);
|
||||
@@ -730,7 +731,8 @@ static inline bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val,
|
||||
}
|
||||
|
||||
/* load data from an absolute host address */
|
||||
static void tcg_out_ld_abs(TCGContext *s, TCGType type, TCGReg dest, void *abs)
|
||||
static void tcg_out_ld_abs(TCGContext *s, TCGType type,
|
||||
TCGReg dest, const void *abs)
|
||||
{
|
||||
intptr_t addr = (intptr_t)abs;
|
||||
|
||||
@@ -746,7 +748,7 @@ static void tcg_out_ld_abs(TCGContext *s, TCGType type, TCGReg dest, void *abs)
|
||||
}
|
||||
}
|
||||
if (USE_REG_TB) {
|
||||
ptrdiff_t disp = abs - (void *)s->code_gen_ptr;
|
||||
ptrdiff_t disp = tcg_tbrel_diff(s, abs);
|
||||
if (disp == sextract64(disp, 0, 20)) {
|
||||
tcg_out_ld(s, type, dest, TCG_REG_TB, disp);
|
||||
return;
|
||||
@@ -956,7 +958,7 @@ static void tgen_andi(TCGContext *s, TCGType type, TCGReg dest, uint64_t val)
|
||||
if (!maybe_out_small_movi(s, type, TCG_TMP0, val)) {
|
||||
tcg_out_insn(s, RXY, NG, dest, TCG_REG_TB, TCG_REG_NONE, 0);
|
||||
new_pool_label(s, val & valid, R_390_20, s->code_ptr - 2,
|
||||
-(intptr_t)s->code_gen_ptr);
|
||||
tcg_tbrel_diff(s, NULL));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -1015,7 +1017,7 @@ static void tgen_ori(TCGContext *s, TCGType type, TCGReg dest, uint64_t val)
|
||||
} else if (USE_REG_TB) {
|
||||
tcg_out_insn(s, RXY, OG, dest, TCG_REG_TB, TCG_REG_NONE, 0);
|
||||
new_pool_label(s, val, R_390_20, s->code_ptr - 2,
|
||||
-(intptr_t)s->code_gen_ptr);
|
||||
tcg_tbrel_diff(s, NULL));
|
||||
} else {
|
||||
/* Perform the OR via sequential modifications to the high and
|
||||
low parts. Do this via recursion to handle 16-bit vs 32-bit
|
||||
@@ -1050,7 +1052,7 @@ static void tgen_xori(TCGContext *s, TCGType type, TCGReg dest, uint64_t val)
|
||||
} else if (USE_REG_TB) {
|
||||
tcg_out_insn(s, RXY, XG, dest, TCG_REG_TB, TCG_REG_NONE, 0);
|
||||
new_pool_label(s, val, R_390_20, s->code_ptr - 2,
|
||||
-(intptr_t)s->code_gen_ptr);
|
||||
tcg_tbrel_diff(s, NULL));
|
||||
} else {
|
||||
/* Perform the xor by parts. */
|
||||
tcg_debug_assert(s390_facilities & FACILITY_EXT_IMM);
|
||||
@@ -1108,12 +1110,12 @@ static int tgen_cmp(TCGContext *s, TCGType type, TCGCond c, TCGReg r1,
|
||||
op = (is_unsigned ? RXY_CLY : RXY_CY);
|
||||
tcg_out_insn_RXY(s, op, r1, TCG_REG_TB, TCG_REG_NONE, 0);
|
||||
new_pool_label(s, (uint32_t)c2, R_390_20, s->code_ptr - 2,
|
||||
4 - (intptr_t)s->code_gen_ptr);
|
||||
4 - tcg_tbrel_diff(s, NULL));
|
||||
} else {
|
||||
op = (is_unsigned ? RXY_CLG : RXY_CG);
|
||||
tcg_out_insn_RXY(s, op, r1, TCG_REG_TB, TCG_REG_NONE, 0);
|
||||
new_pool_label(s, c2, R_390_20, s->code_ptr - 2,
|
||||
-(intptr_t)s->code_gen_ptr);
|
||||
tcg_tbrel_diff(s, NULL));
|
||||
}
|
||||
goto exit;
|
||||
} else {
|
||||
@@ -1302,9 +1304,9 @@ static void tgen_extract(TCGContext *s, TCGReg dest, TCGReg src,
|
||||
tcg_out_risbg(s, dest, src, 64 - len, 63, 64 - ofs, 1);
|
||||
}
|
||||
|
||||
static void tgen_gotoi(TCGContext *s, int cc, tcg_insn_unit *dest)
|
||||
static void tgen_gotoi(TCGContext *s, int cc, const tcg_insn_unit *dest)
|
||||
{
|
||||
ptrdiff_t off = dest - s->code_ptr;
|
||||
ptrdiff_t off = tcg_pcrel_diff(s, dest) >> 1;
|
||||
if (off == (int16_t)off) {
|
||||
tcg_out_insn(s, RI, BRC, cc, off);
|
||||
} else if (off == (int32_t)off) {
|
||||
@@ -1333,34 +1335,18 @@ static void tgen_branch(TCGContext *s, int cc, TCGLabel *l)
|
||||
static void tgen_compare_branch(TCGContext *s, S390Opcode opc, int cc,
|
||||
TCGReg r1, TCGReg r2, TCGLabel *l)
|
||||
{
|
||||
intptr_t off = 0;
|
||||
|
||||
if (l->has_value) {
|
||||
off = l->u.value_ptr - s->code_ptr;
|
||||
tcg_debug_assert(off == (int16_t)off);
|
||||
} else {
|
||||
tcg_out_reloc(s, s->code_ptr + 1, R_390_PC16DBL, l, 2);
|
||||
}
|
||||
|
||||
tcg_out_reloc(s, s->code_ptr + 1, R_390_PC16DBL, l, 2);
|
||||
tcg_out16(s, (opc & 0xff00) | (r1 << 4) | r2);
|
||||
tcg_out16(s, off);
|
||||
tcg_out16(s, 0);
|
||||
tcg_out16(s, cc << 12 | (opc & 0xff));
|
||||
}
|
||||
|
||||
static void tgen_compare_imm_branch(TCGContext *s, S390Opcode opc, int cc,
|
||||
TCGReg r1, int i2, TCGLabel *l)
|
||||
{
|
||||
tcg_target_long off = 0;
|
||||
|
||||
if (l->has_value) {
|
||||
off = l->u.value_ptr - s->code_ptr;
|
||||
tcg_debug_assert(off == (int16_t)off);
|
||||
} else {
|
||||
tcg_out_reloc(s, s->code_ptr + 1, R_390_PC16DBL, l, 2);
|
||||
}
|
||||
|
||||
tcg_out_reloc(s, s->code_ptr + 1, R_390_PC16DBL, l, 2);
|
||||
tcg_out16(s, (opc & 0xff00) | (r1 << 4) | cc);
|
||||
tcg_out16(s, off);
|
||||
tcg_out16(s, 0);
|
||||
tcg_out16(s, (i2 << 8) | (opc & 0xff));
|
||||
}
|
||||
|
||||
@@ -1415,9 +1401,9 @@ static void tgen_brcond(TCGContext *s, TCGType type, TCGCond c,
|
||||
tgen_branch(s, cc, l);
|
||||
}
|
||||
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *dest)
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *dest)
|
||||
{
|
||||
ptrdiff_t off = dest - s->code_ptr;
|
||||
ptrdiff_t off = tcg_pcrel_diff(s, dest) >> 1;
|
||||
if (off == (int32_t)off) {
|
||||
tcg_out_insn(s, RIL, BRASL, TCG_REG_R14, off);
|
||||
} else {
|
||||
@@ -1601,7 +1587,7 @@ static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi,
|
||||
label->oi = oi;
|
||||
label->datalo_reg = data;
|
||||
label->addrlo_reg = addr;
|
||||
label->raddr = raddr;
|
||||
label->raddr = tcg_splitwx_to_rx(raddr);
|
||||
label->label_ptr[0] = label_ptr;
|
||||
}
|
||||
|
||||
@@ -1613,7 +1599,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
MemOp opc = get_memop(oi);
|
||||
|
||||
if (!patch_reloc(lb->label_ptr[0], R_390_PC16DBL,
|
||||
(intptr_t)s->code_ptr, 2)) {
|
||||
(intptr_t)tcg_splitwx_to_rx(s->code_ptr), 2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1638,7 +1624,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
MemOp opc = get_memop(oi);
|
||||
|
||||
if (!patch_reloc(lb->label_ptr[0], R_390_PC16DBL,
|
||||
(intptr_t)s->code_ptr, 2)) {
|
||||
(intptr_t)tcg_splitwx_to_rx(s->code_ptr), 2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1756,7 +1742,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
/* Reuse the zeroing that exists for goto_ptr. */
|
||||
a0 = args[0];
|
||||
if (a0 == 0) {
|
||||
tgen_gotoi(s, S390_CC_ALWAYS, s->code_gen_epilogue);
|
||||
tgen_gotoi(s, S390_CC_ALWAYS, tcg_code_gen_epilogue);
|
||||
} else {
|
||||
tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R2, a0);
|
||||
tgen_gotoi(s, S390_CC_ALWAYS, tb_ret_addr);
|
||||
@@ -1766,7 +1752,8 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
case INDEX_op_goto_tb:
|
||||
a0 = args[0];
|
||||
if (s->tb_jmp_insn_offset) {
|
||||
/* branch displacement must be aligned for atomic patching;
|
||||
/*
|
||||
* branch displacement must be aligned for atomic patching;
|
||||
* see if we need to add extra nop before branch
|
||||
*/
|
||||
if (!QEMU_PTR_IS_ALIGNED(s->code_ptr + 1, 4)) {
|
||||
@@ -1779,7 +1766,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
} else {
|
||||
/* load address stored at s->tb_jmp_target_addr + a0 */
|
||||
tcg_out_ld_abs(s, TCG_TYPE_PTR, TCG_REG_TB,
|
||||
s->tb_jmp_target_addr + a0);
|
||||
tcg_splitwx_to_rx(s->tb_jmp_target_addr + a0));
|
||||
/* and go there */
|
||||
tcg_out_insn(s, RR, BCR, S390_CC_ALWAYS, TCG_REG_TB);
|
||||
}
|
||||
@@ -1789,8 +1776,10 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
TCG_REG_TB to the beginning of this TB. */
|
||||
if (USE_REG_TB) {
|
||||
int ofs = -tcg_current_code_size(s);
|
||||
assert(ofs == (int16_t)ofs);
|
||||
tcg_out_insn(s, RI, AGHI, TCG_REG_TB, ofs);
|
||||
/* All TB are restricted to 64KiB by unwind info. */
|
||||
tcg_debug_assert(ofs == sextract64(ofs, 0, 20));
|
||||
tcg_out_insn(s, RXY, LAY, TCG_REG_TB,
|
||||
TCG_REG_TB, TCG_REG_NONE, ofs);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -2561,11 +2550,11 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
* Return path for goto_ptr. Set return value to 0, a-la exit_tb,
|
||||
* and fall through to the rest of the epilogue.
|
||||
*/
|
||||
s->code_gen_epilogue = s->code_ptr;
|
||||
tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr);
|
||||
tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R2, 0);
|
||||
|
||||
/* TB epilogue */
|
||||
tb_ret_addr = s->code_ptr;
|
||||
tb_ret_addr = tcg_splitwx_to_rx(s->code_ptr);
|
||||
|
||||
/* lmg %r6,%r15,fs+48(%r15) (restore registers) */
|
||||
tcg_out_insn(s, RXY, LMG, TCG_REG_R6, TCG_REG_R15, TCG_REG_R15,
|
||||
@@ -2620,7 +2609,7 @@ static const DebugFrame debug_frame = {
|
||||
}
|
||||
};
|
||||
|
||||
void tcg_register_jit(void *buf, size_t buf_size)
|
||||
void tcg_register_jit(const void *buf, size_t buf_size)
|
||||
{
|
||||
tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame));
|
||||
}
|
||||
@@ -145,16 +145,12 @@ enum {
|
||||
TCG_AREG0 = TCG_REG_R10,
|
||||
};
|
||||
|
||||
static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
}
|
||||
|
||||
static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,
|
||||
uintptr_t jmp_addr, uintptr_t addr)
|
||||
static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,
|
||||
uintptr_t jmp_rw, uintptr_t addr)
|
||||
{
|
||||
/* patch the branch destination */
|
||||
intptr_t disp = addr - (jmp_addr - 2);
|
||||
qatomic_set((int32_t *)jmp_addr, disp / 2);
|
||||
intptr_t disp = addr - (jmp_rx - 2);
|
||||
qatomic_set((int32_t *)jmp_rw, disp / 2);
|
||||
/* no need to flush icache explicitly */
|
||||
}
|
||||
|
||||
|
||||
+29
-29
@@ -291,14 +291,15 @@ static inline int check_fit_i32(int32_t val, unsigned int bits)
|
||||
# define check_fit_ptr check_fit_i32
|
||||
#endif
|
||||
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(tcg_insn_unit *src_rw, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
uint32_t insn = *code_ptr;
|
||||
const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw);
|
||||
uint32_t insn = *src_rw;
|
||||
intptr_t pcrel;
|
||||
|
||||
value += addend;
|
||||
pcrel = tcg_ptr_byte_diff((tcg_insn_unit *)value, code_ptr);
|
||||
pcrel = tcg_ptr_byte_diff((tcg_insn_unit *)value, src_rx);
|
||||
|
||||
switch (type) {
|
||||
case R_SPARC_WDISP16:
|
||||
@@ -315,7 +316,7 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
*code_ptr = insn;
|
||||
*src_rw = insn;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -440,7 +441,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,
|
||||
|
||||
/* A 13-bit constant relative to the TB. */
|
||||
if (!in_prologue && USE_REG_TB) {
|
||||
test = arg - (uintptr_t)s->code_gen_ptr;
|
||||
test = tcg_tbrel_diff(s, (void *)arg);
|
||||
if (check_fit_ptr(test, 13)) {
|
||||
tcg_out_arithi(s, ret, TCG_REG_TB, test, ARITH_ADD);
|
||||
return;
|
||||
@@ -537,15 +538,15 @@ static inline bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val,
|
||||
return false;
|
||||
}
|
||||
|
||||
static void tcg_out_ld_ptr(TCGContext *s, TCGReg ret, uintptr_t arg)
|
||||
static void tcg_out_ld_ptr(TCGContext *s, TCGReg ret, const void *arg)
|
||||
{
|
||||
intptr_t diff = arg - (uintptr_t)s->code_gen_ptr;
|
||||
intptr_t diff = tcg_tbrel_diff(s, arg);
|
||||
if (USE_REG_TB && check_fit_ptr(diff, 13)) {
|
||||
tcg_out_ld(s, TCG_TYPE_PTR, ret, TCG_REG_TB, diff);
|
||||
return;
|
||||
}
|
||||
tcg_out_movi(s, TCG_TYPE_PTR, ret, arg & ~0x3ff);
|
||||
tcg_out_ld(s, TCG_TYPE_PTR, ret, ret, arg & 0x3ff);
|
||||
tcg_out_movi(s, TCG_TYPE_PTR, ret, (uintptr_t)arg & ~0x3ff);
|
||||
tcg_out_ld(s, TCG_TYPE_PTR, ret, ret, (uintptr_t)arg & 0x3ff);
|
||||
}
|
||||
|
||||
static inline void tcg_out_sety(TCGContext *s, TCGReg rs)
|
||||
@@ -840,7 +841,7 @@ static void tcg_out_addsub2_i64(TCGContext *s, TCGReg rl, TCGReg rh,
|
||||
tcg_out_mov(s, TCG_TYPE_I64, rl, tmp);
|
||||
}
|
||||
|
||||
static void tcg_out_call_nodelay(TCGContext *s, tcg_insn_unit *dest,
|
||||
static void tcg_out_call_nodelay(TCGContext *s, const tcg_insn_unit *dest,
|
||||
bool in_prologue)
|
||||
{
|
||||
ptrdiff_t disp = tcg_pcrel_diff(s, dest);
|
||||
@@ -855,7 +856,7 @@ static void tcg_out_call_nodelay(TCGContext *s, tcg_insn_unit *dest,
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *dest)
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *dest)
|
||||
{
|
||||
tcg_out_call_nodelay(s, dest, false);
|
||||
tcg_out_nop(s);
|
||||
@@ -868,8 +869,8 @@ static void tcg_out_mb(TCGContext *s, TCGArg a0)
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
static tcg_insn_unit *qemu_ld_trampoline[16];
|
||||
static tcg_insn_unit *qemu_st_trampoline[16];
|
||||
static const tcg_insn_unit *qemu_ld_trampoline[16];
|
||||
static const tcg_insn_unit *qemu_st_trampoline[16];
|
||||
|
||||
static void emit_extend(TCGContext *s, TCGReg r, int op)
|
||||
{
|
||||
@@ -930,7 +931,7 @@ static void build_trampolines(TCGContext *s)
|
||||
while ((uintptr_t)s->code_ptr & 15) {
|
||||
tcg_out_nop(s);
|
||||
}
|
||||
qemu_ld_trampoline[i] = s->code_ptr;
|
||||
qemu_ld_trampoline[i] = tcg_splitwx_to_rx(s->code_ptr);
|
||||
|
||||
if (SPARC64 || TARGET_LONG_BITS == 32) {
|
||||
ra = TCG_REG_O3;
|
||||
@@ -958,7 +959,7 @@ static void build_trampolines(TCGContext *s)
|
||||
while ((uintptr_t)s->code_ptr & 15) {
|
||||
tcg_out_nop(s);
|
||||
}
|
||||
qemu_st_trampoline[i] = s->code_ptr;
|
||||
qemu_st_trampoline[i] = tcg_splitwx_to_rx(s->code_ptr);
|
||||
|
||||
if (SPARC64) {
|
||||
emit_extend(s, TCG_REG_O2, i);
|
||||
@@ -1038,7 +1039,7 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
tcg_out_nop(s);
|
||||
|
||||
/* Epilogue for goto_ptr. */
|
||||
s->code_gen_epilogue = s->code_ptr;
|
||||
tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr);
|
||||
tcg_out_arithi(s, TCG_REG_G0, TCG_REG_I7, 8, RETURN);
|
||||
/* delay slot */
|
||||
tcg_out_movi_imm13(s, TCG_REG_O0, 0);
|
||||
@@ -1163,7 +1164,7 @@ static void tcg_out_qemu_ld(TCGContext *s, TCGReg data, TCGReg addr,
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
unsigned memi = get_mmuidx(oi);
|
||||
TCGReg addrz, param;
|
||||
tcg_insn_unit *func;
|
||||
const tcg_insn_unit *func;
|
||||
tcg_insn_unit *label_ptr;
|
||||
|
||||
addrz = tcg_out_tlb_load(s, addr, memi, memop,
|
||||
@@ -1245,7 +1246,7 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data, TCGReg addr,
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
unsigned memi = get_mmuidx(oi);
|
||||
TCGReg addrz, param;
|
||||
tcg_insn_unit *func;
|
||||
const tcg_insn_unit *func;
|
||||
tcg_insn_unit *label_ptr;
|
||||
|
||||
addrz = tcg_out_tlb_load(s, addr, memi, memop,
|
||||
@@ -1313,7 +1314,7 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
tcg_out_movi_imm13(s, TCG_REG_O0, a0);
|
||||
break;
|
||||
} else if (USE_REG_TB) {
|
||||
intptr_t tb_diff = a0 - (uintptr_t)s->code_gen_ptr;
|
||||
intptr_t tb_diff = tcg_tbrel_diff(s, (void *)a0);
|
||||
if (check_fit_ptr(tb_diff, 13)) {
|
||||
tcg_out_arithi(s, TCG_REG_G0, TCG_REG_I7, 8, RETURN);
|
||||
/* Note that TCG_REG_TB has been unwound to O1. */
|
||||
@@ -1345,8 +1346,7 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
}
|
||||
} else {
|
||||
/* indirect jump method */
|
||||
tcg_out_ld_ptr(s, TCG_REG_TB,
|
||||
(uintptr_t)(s->tb_jmp_target_addr + a0));
|
||||
tcg_out_ld_ptr(s, TCG_REG_TB, s->tb_jmp_target_addr + a0);
|
||||
tcg_out_arithi(s, TCG_REG_G0, TCG_REG_TB, 0, JMPL);
|
||||
tcg_out_nop(s);
|
||||
}
|
||||
@@ -1816,16 +1816,16 @@ static const DebugFrame debug_frame = {
|
||||
.fde_ret_save = { 9, 15, 31 }, /* DW_CFA_register o7, i7 */
|
||||
};
|
||||
|
||||
void tcg_register_jit(void *buf, size_t buf_size)
|
||||
void tcg_register_jit(const void *buf, size_t buf_size)
|
||||
{
|
||||
tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame));
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
uintptr_t addr)
|
||||
void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,
|
||||
uintptr_t jmp_rw, uintptr_t addr)
|
||||
{
|
||||
intptr_t tb_disp = addr - tc_ptr;
|
||||
intptr_t br_disp = addr - jmp_addr;
|
||||
intptr_t br_disp = addr - jmp_rx;
|
||||
tcg_insn_unit i1, i2;
|
||||
|
||||
/* We can reach the entire address space for ILP32.
|
||||
@@ -1834,9 +1834,9 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
tcg_debug_assert(br_disp == (int32_t)br_disp);
|
||||
|
||||
if (!USE_REG_TB) {
|
||||
qatomic_set((uint32_t *)jmp_addr,
|
||||
qatomic_set((uint32_t *)jmp_rw,
|
||||
deposit32(CALL, 0, 30, br_disp >> 2));
|
||||
flush_icache_range(jmp_addr, jmp_addr + 4);
|
||||
flush_idcache_range(jmp_rx, jmp_rw, 4);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1859,6 +1859,6 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
| INSN_IMM13((tb_disp & 0x3ff) | -0x400));
|
||||
}
|
||||
|
||||
qatomic_set((uint64_t *)jmp_addr, deposit64(i2, 32, 32, i1));
|
||||
flush_icache_range(jmp_addr, jmp_addr + 8);
|
||||
qatomic_set((uint64_t *)jmp_rw, deposit64(i2, 32, 32, i1));
|
||||
flush_idcache_range(jmp_rx, jmp_rw, 8);
|
||||
}
|
||||
@@ -168,15 +168,7 @@ extern bool use_vis3_instructions;
|
||||
#define TCG_TARGET_DEFAULT_MO (0)
|
||||
#define TCG_TARGET_HAS_MEMORY_BSWAP 1
|
||||
|
||||
static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
uintptr_t p;
|
||||
for (p = start & -8; p < ((stop + 7) & -8); p += 8) {
|
||||
__asm__ __volatile__("flush\t%0" : : "r" (p));
|
||||
}
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
||||
|
||||
#define TCG_TARGET_NEED_POOL_LABELS
|
||||
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ typedef struct TCGLabelQemuLdst {
|
||||
TCGReg addrhi_reg; /* reg index for high word of guest virtual addr */
|
||||
TCGReg datalo_reg; /* reg index for low word to be loaded or stored */
|
||||
TCGReg datahi_reg; /* reg index for high word to be loaded or stored */
|
||||
tcg_insn_unit *raddr; /* gen code addr of the next IR of qemu_ld/st IR */
|
||||
const tcg_insn_unit *raddr; /* addr of the next IR of qemu_ld/st IR */
|
||||
tcg_insn_unit *label_ptr[2]; /* label pointers to be updated */
|
||||
QSIMPLEQ_ENTRY(TCGLabelQemuLdst) next;
|
||||
} TCGLabelQemuLdst;
|
||||
|
||||
+13
-2
@@ -2664,9 +2664,20 @@ void tcg_gen_extr32_i64(TCGv_i64 lo, TCGv_i64 hi, TCGv_i64 arg)
|
||||
|
||||
/* QEMU specific operations. */
|
||||
|
||||
void tcg_gen_exit_tb(TranslationBlock *tb, unsigned idx)
|
||||
void tcg_gen_exit_tb(const TranslationBlock *tb, unsigned idx)
|
||||
{
|
||||
uintptr_t val = (uintptr_t)tb + idx;
|
||||
/*
|
||||
* Let the jit code return the read-only version of the
|
||||
* TranslationBlock, so that we minimize the pc-relative
|
||||
* distance of the address of the exit_tb code to TB.
|
||||
* This will improve utilization of pc-relative address loads.
|
||||
*
|
||||
* TODO: Move this to translator_loop, so that all const
|
||||
* TranslationBlock pointers refer to read-only memory.
|
||||
* This requires coordination with targets that do not use
|
||||
* the translator_loop.
|
||||
*/
|
||||
uintptr_t val = (uintptr_t)tcg_splitwx_to_rx((void *)tb) + idx;
|
||||
|
||||
if (tb == NULL) {
|
||||
tcg_debug_assert(idx == 0);
|
||||
|
||||
+5
-1
@@ -140,6 +140,8 @@ static int tcg_out_pool_finalize(TCGContext *s)
|
||||
|
||||
for (; p != NULL; p = p->next) {
|
||||
size_t size = sizeof(tcg_target_ulong) * p->nlong;
|
||||
uintptr_t value;
|
||||
|
||||
if (!l || l->nlong != p->nlong || memcmp(l->data, p->data, size)) {
|
||||
if (unlikely(a > s->code_gen_highwater)) {
|
||||
return -1;
|
||||
@@ -148,7 +150,9 @@ static int tcg_out_pool_finalize(TCGContext *s)
|
||||
a += size;
|
||||
l = p;
|
||||
}
|
||||
if (!patch_reloc(p->label, p->rtype, (intptr_t)a - size, p->addend)) {
|
||||
|
||||
value = (uintptr_t)tcg_splitwx_to_rx(a) - size;
|
||||
if (!patch_reloc(p->label, p->rtype, value, p->addend)) {
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "qemu/host-utils.h"
|
||||
#include "qemu/qemu-print.h"
|
||||
#include "qemu/timer.h"
|
||||
#include "qemu/cacheflush.h"
|
||||
|
||||
/* Note: the long term plan is to reduce the dependencies on the QEMU
|
||||
CPU definitions. Currently they are used for qemu_ld/st
|
||||
@@ -96,7 +97,7 @@ typedef struct QEMU_PACKED {
|
||||
DebugFrameFDEHeader fde;
|
||||
} DebugFrameHeader;
|
||||
|
||||
static void tcg_register_jit_int(void *buf, size_t size,
|
||||
static void tcg_register_jit_int(const void *buf, size_t size,
|
||||
const void *debug_frame,
|
||||
size_t debug_frame_size)
|
||||
__attribute__((unused));
|
||||
@@ -148,7 +149,7 @@ static void tcg_out_st(TCGContext *s, TCGType type, TCGReg arg, TCGReg arg1,
|
||||
intptr_t arg2);
|
||||
static bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val,
|
||||
TCGReg base, intptr_t ofs);
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *target);
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target);
|
||||
static int tcg_target_const_match(tcg_target_long val, TCGType type,
|
||||
const TCGArgConstraint *arg_ct);
|
||||
#ifdef TCG_TARGET_NEED_LDST_LABELS
|
||||
@@ -160,6 +161,12 @@ static int tcg_out_ldst_finalize(TCGContext *s);
|
||||
static TCGContext **tcg_ctxs;
|
||||
static unsigned int n_tcg_ctxs;
|
||||
TCGv_env cpu_env = 0;
|
||||
const void *tcg_code_gen_epilogue;
|
||||
uintptr_t tcg_splitwx_diff;
|
||||
|
||||
#ifndef CONFIG_TCG_INTERPRETER
|
||||
tcg_prologue_fn *tcg_qemu_tb_exec;
|
||||
#endif
|
||||
|
||||
struct tcg_region_tree {
|
||||
QemuMutex lock;
|
||||
@@ -295,11 +302,11 @@ static void tcg_out_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
QSIMPLEQ_INSERT_TAIL(&l->relocs, r, next);
|
||||
}
|
||||
|
||||
static void tcg_out_label(TCGContext *s, TCGLabel *l, tcg_insn_unit *ptr)
|
||||
static void tcg_out_label(TCGContext *s, TCGLabel *l)
|
||||
{
|
||||
tcg_debug_assert(!l->has_value);
|
||||
l->has_value = 1;
|
||||
l->u.value_ptr = ptr;
|
||||
l->u.value_ptr = tcg_splitwx_to_rx(s->code_ptr);
|
||||
}
|
||||
|
||||
TCGLabel *gen_new_label(void)
|
||||
@@ -400,8 +407,9 @@ static void tcg_region_trees_init(void)
|
||||
}
|
||||
}
|
||||
|
||||
static struct tcg_region_tree *tc_ptr_to_region_tree(void *p)
|
||||
static struct tcg_region_tree *tc_ptr_to_region_tree(const void *cp)
|
||||
{
|
||||
void *p = tcg_splitwx_to_rw(cp);
|
||||
size_t region_idx;
|
||||
|
||||
if (p < region.start_aligned) {
|
||||
@@ -695,6 +703,7 @@ void tcg_region_init(void)
|
||||
size_t region_size;
|
||||
size_t n_regions;
|
||||
size_t i;
|
||||
uintptr_t splitwx_diff;
|
||||
|
||||
n_regions = tcg_n_regions();
|
||||
|
||||
@@ -725,6 +734,7 @@ void tcg_region_init(void)
|
||||
region.end -= page_size;
|
||||
|
||||
/* set guard pages */
|
||||
splitwx_diff = tcg_splitwx_diff;
|
||||
for (i = 0; i < region.n; i++) {
|
||||
void *start, *end;
|
||||
int rc;
|
||||
@@ -732,6 +742,10 @@ void tcg_region_init(void)
|
||||
tcg_region_bounds(i, &start, &end);
|
||||
rc = qemu_mprotect_none(end, page_size);
|
||||
g_assert(!rc);
|
||||
if (splitwx_diff) {
|
||||
rc = qemu_mprotect_none(end + splitwx_diff, page_size);
|
||||
g_assert(!rc);
|
||||
}
|
||||
}
|
||||
|
||||
tcg_region_trees_init();
|
||||
@@ -746,6 +760,29 @@ void tcg_region_init(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DEBUG_TCG
|
||||
const void *tcg_splitwx_to_rx(void *rw)
|
||||
{
|
||||
/* Pass NULL pointers unchanged. */
|
||||
if (rw) {
|
||||
g_assert(in_code_gen_buffer(rw));
|
||||
rw += tcg_splitwx_diff;
|
||||
}
|
||||
return rw;
|
||||
}
|
||||
|
||||
void *tcg_splitwx_to_rw(const void *rx)
|
||||
{
|
||||
/* Pass NULL pointers unchanged. */
|
||||
if (rx) {
|
||||
rx -= tcg_splitwx_diff;
|
||||
/* Assert that we end with a pointer in the rw region. */
|
||||
g_assert(in_code_gen_buffer(rx));
|
||||
}
|
||||
return (void *)rx;
|
||||
}
|
||||
#endif /* CONFIG_DEBUG_TCG */
|
||||
|
||||
static void alloc_tcg_plugin_context(TCGContext *s)
|
||||
{
|
||||
#ifdef CONFIG_PLUGIN
|
||||
@@ -1054,7 +1091,17 @@ void tcg_prologue_init(TCGContext *s)
|
||||
s->code_ptr = buf0;
|
||||
s->code_buf = buf0;
|
||||
s->data_gen_ptr = NULL;
|
||||
s->code_gen_prologue = buf0;
|
||||
|
||||
/*
|
||||
* The region trees are not yet configured, but tcg_splitwx_to_rx
|
||||
* needs the bounds for an assert.
|
||||
*/
|
||||
region.start = buf0;
|
||||
region.end = buf0 + total_size;
|
||||
|
||||
#ifndef CONFIG_TCG_INTERPRETER
|
||||
tcg_qemu_tb_exec = (tcg_prologue_fn *)tcg_splitwx_to_rx(buf0);
|
||||
#endif
|
||||
|
||||
/* Compute a high-water mark, at which we voluntarily flush the buffer
|
||||
and start over. The size here is arbitrary, significantly larger
|
||||
@@ -1065,6 +1112,7 @@ void tcg_prologue_init(TCGContext *s)
|
||||
s->pool_labels = NULL;
|
||||
#endif
|
||||
|
||||
qemu_thread_jit_write();
|
||||
/* Generate the prologue. */
|
||||
tcg_target_qemu_prologue(s);
|
||||
|
||||
@@ -1077,7 +1125,10 @@ void tcg_prologue_init(TCGContext *s)
|
||||
#endif
|
||||
|
||||
buf1 = s->code_ptr;
|
||||
flush_icache_range((uintptr_t)buf0, (uintptr_t)buf1);
|
||||
#ifndef CONFIG_TCG_INTERPRETER
|
||||
flush_idcache_range((uintptr_t)tcg_splitwx_to_rx(buf0), (uintptr_t)buf0,
|
||||
tcg_ptr_byte_diff(buf1, buf0));
|
||||
#endif
|
||||
|
||||
/* Deduct the prologue from the buffer. */
|
||||
prologue_size = tcg_current_code_size(s);
|
||||
@@ -1087,7 +1138,7 @@ void tcg_prologue_init(TCGContext *s)
|
||||
total_size -= prologue_size;
|
||||
s->code_gen_buffer_size = total_size;
|
||||
|
||||
tcg_register_jit(s->code_gen_buffer, total_size);
|
||||
tcg_register_jit(tcg_splitwx_to_rx(s->code_gen_buffer), total_size);
|
||||
|
||||
#ifdef DEBUG_DISAS
|
||||
if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM)) {
|
||||
@@ -1122,7 +1173,7 @@ void tcg_prologue_init(TCGContext *s)
|
||||
|
||||
/* Assert that goto_ptr is implemented completely. */
|
||||
if (TCG_TARGET_HAS_goto_ptr) {
|
||||
tcg_debug_assert(s->code_gen_epilogue != NULL);
|
||||
tcg_debug_assert(tcg_code_gen_epilogue != NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4215,8 +4266,13 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
|
||||
|
||||
tcg_reg_alloc_start(s);
|
||||
|
||||
s->code_buf = tb->tc.ptr;
|
||||
s->code_ptr = tb->tc.ptr;
|
||||
/*
|
||||
* Reset the buffer pointers when restarting after overflow.
|
||||
* TODO: Move this into translate-all.c with the rest of the
|
||||
* buffer management. Having only this done here is confusing.
|
||||
*/
|
||||
s->code_buf = tcg_splitwx_to_rw(tb->tc.ptr);
|
||||
s->code_ptr = s->code_buf;
|
||||
|
||||
#ifdef TCG_TARGET_NEED_LDST_LABELS
|
||||
QSIMPLEQ_INIT(&s->ldst_labels);
|
||||
@@ -4270,7 +4326,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
|
||||
break;
|
||||
case INDEX_op_set_label:
|
||||
tcg_reg_alloc_bb_end(s, s->reserved_regs);
|
||||
tcg_out_label(s, arg_label(op->args[0]), s->code_ptr);
|
||||
tcg_out_label(s, arg_label(op->args[0]));
|
||||
break;
|
||||
case INDEX_op_call:
|
||||
tcg_reg_alloc_call(s, op);
|
||||
@@ -4319,8 +4375,12 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
|
||||
return -2;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_TCG_INTERPRETER
|
||||
/* flush instruction cache */
|
||||
flush_icache_range((uintptr_t)s->code_buf, (uintptr_t)s->code_ptr);
|
||||
flush_idcache_range((uintptr_t)tcg_splitwx_to_rx(s->code_buf),
|
||||
(uintptr_t)s->code_buf,
|
||||
tcg_ptr_byte_diff(s->code_ptr, s->code_buf));
|
||||
#endif
|
||||
|
||||
return tcg_current_code_size(s);
|
||||
}
|
||||
@@ -4448,7 +4508,7 @@ static int find_string(const char *strtab, const char *str)
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_register_jit_int(void *buf_ptr, size_t buf_size,
|
||||
static void tcg_register_jit_int(const void *buf_ptr, size_t buf_size,
|
||||
const void *debug_frame,
|
||||
size_t debug_frame_size)
|
||||
{
|
||||
@@ -4650,13 +4710,13 @@ static void tcg_register_jit_int(void *buf_ptr, size_t buf_size,
|
||||
/* No support for the feature. Provide the entry point expected by exec.c,
|
||||
and implement the internal function we declared earlier. */
|
||||
|
||||
static void tcg_register_jit_int(void *buf, size_t size,
|
||||
static void tcg_register_jit_int(const void *buf, size_t size,
|
||||
const void *debug_frame,
|
||||
size_t debug_frame_size)
|
||||
{
|
||||
}
|
||||
|
||||
void tcg_register_jit(void *buf, size_t buf_size)
|
||||
void tcg_register_jit(const void *buf, size_t buf_size)
|
||||
{
|
||||
}
|
||||
#endif /* ELF_HOST_MACHINE */
|
||||
|
||||
@@ -163,34 +163,34 @@ static uint64_t tci_uint64(uint32_t high, uint32_t low)
|
||||
#endif
|
||||
|
||||
/* Read constant (native size) from bytecode. */
|
||||
static tcg_target_ulong tci_read_i(uint8_t **tb_ptr)
|
||||
static tcg_target_ulong tci_read_i(const uint8_t **tb_ptr)
|
||||
{
|
||||
tcg_target_ulong value = *(tcg_target_ulong *)(*tb_ptr);
|
||||
tcg_target_ulong value = *(const tcg_target_ulong *)(*tb_ptr);
|
||||
*tb_ptr += sizeof(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
/* Read unsigned constant (32 bit) from bytecode. */
|
||||
static uint32_t tci_read_i32(uint8_t **tb_ptr)
|
||||
static uint32_t tci_read_i32(const uint8_t **tb_ptr)
|
||||
{
|
||||
uint32_t value = *(uint32_t *)(*tb_ptr);
|
||||
uint32_t value = *(const uint32_t *)(*tb_ptr);
|
||||
*tb_ptr += sizeof(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
/* Read signed constant (32 bit) from bytecode. */
|
||||
static int32_t tci_read_s32(uint8_t **tb_ptr)
|
||||
static int32_t tci_read_s32(const uint8_t **tb_ptr)
|
||||
{
|
||||
int32_t value = *(int32_t *)(*tb_ptr);
|
||||
int32_t value = *(const int32_t *)(*tb_ptr);
|
||||
*tb_ptr += sizeof(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
#if TCG_TARGET_REG_BITS == 64
|
||||
/* Read constant (64 bit) from bytecode. */
|
||||
static uint64_t tci_read_i64(uint8_t **tb_ptr)
|
||||
static uint64_t tci_read_i64(const uint8_t **tb_ptr)
|
||||
{
|
||||
uint64_t value = *(uint64_t *)(*tb_ptr);
|
||||
uint64_t value = *(const uint64_t *)(*tb_ptr);
|
||||
*tb_ptr += sizeof(value);
|
||||
return value;
|
||||
}
|
||||
@@ -198,7 +198,7 @@ static uint64_t tci_read_i64(uint8_t **tb_ptr)
|
||||
|
||||
/* Read indexed register (native size) from bytecode. */
|
||||
static tcg_target_ulong
|
||||
tci_read_r(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
tci_read_r(const tcg_target_ulong *regs, const uint8_t **tb_ptr)
|
||||
{
|
||||
tcg_target_ulong value = tci_read_reg(regs, **tb_ptr);
|
||||
*tb_ptr += 1;
|
||||
@@ -206,7 +206,7 @@ tci_read_r(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
}
|
||||
|
||||
/* Read indexed register (8 bit) from bytecode. */
|
||||
static uint8_t tci_read_r8(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
static uint8_t tci_read_r8(const tcg_target_ulong *regs, const uint8_t **tb_ptr)
|
||||
{
|
||||
uint8_t value = tci_read_reg8(regs, **tb_ptr);
|
||||
*tb_ptr += 1;
|
||||
@@ -215,7 +215,7 @@ static uint8_t tci_read_r8(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
|
||||
#if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64
|
||||
/* Read indexed register (8 bit signed) from bytecode. */
|
||||
static int8_t tci_read_r8s(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
static int8_t tci_read_r8s(const tcg_target_ulong *regs, const uint8_t **tb_ptr)
|
||||
{
|
||||
int8_t value = tci_read_reg8s(regs, **tb_ptr);
|
||||
*tb_ptr += 1;
|
||||
@@ -224,7 +224,8 @@ static int8_t tci_read_r8s(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
#endif
|
||||
|
||||
/* Read indexed register (16 bit) from bytecode. */
|
||||
static uint16_t tci_read_r16(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
static uint16_t tci_read_r16(const tcg_target_ulong *regs,
|
||||
const uint8_t **tb_ptr)
|
||||
{
|
||||
uint16_t value = tci_read_reg16(regs, **tb_ptr);
|
||||
*tb_ptr += 1;
|
||||
@@ -233,7 +234,8 @@ static uint16_t tci_read_r16(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
|
||||
#if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64
|
||||
/* Read indexed register (16 bit signed) from bytecode. */
|
||||
static int16_t tci_read_r16s(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
static int16_t tci_read_r16s(const tcg_target_ulong *regs,
|
||||
const uint8_t **tb_ptr)
|
||||
{
|
||||
int16_t value = tci_read_reg16s(regs, **tb_ptr);
|
||||
*tb_ptr += 1;
|
||||
@@ -242,7 +244,8 @@ static int16_t tci_read_r16s(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
#endif
|
||||
|
||||
/* Read indexed register (32 bit) from bytecode. */
|
||||
static uint32_t tci_read_r32(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
static uint32_t tci_read_r32(const tcg_target_ulong *regs,
|
||||
const uint8_t **tb_ptr)
|
||||
{
|
||||
uint32_t value = tci_read_reg32(regs, **tb_ptr);
|
||||
*tb_ptr += 1;
|
||||
@@ -251,14 +254,16 @@ static uint32_t tci_read_r32(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
|
||||
#if TCG_TARGET_REG_BITS == 32
|
||||
/* Read two indexed registers (2 * 32 bit) from bytecode. */
|
||||
static uint64_t tci_read_r64(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
static uint64_t tci_read_r64(const tcg_target_ulong *regs,
|
||||
const uint8_t **tb_ptr)
|
||||
{
|
||||
uint32_t low = tci_read_r32(regs, tb_ptr);
|
||||
return tci_uint64(tci_read_r32(regs, tb_ptr), low);
|
||||
}
|
||||
#elif TCG_TARGET_REG_BITS == 64
|
||||
/* Read indexed register (32 bit signed) from bytecode. */
|
||||
static int32_t tci_read_r32s(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
static int32_t tci_read_r32s(const tcg_target_ulong *regs,
|
||||
const uint8_t **tb_ptr)
|
||||
{
|
||||
int32_t value = tci_read_reg32s(regs, **tb_ptr);
|
||||
*tb_ptr += 1;
|
||||
@@ -266,7 +271,8 @@ static int32_t tci_read_r32s(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
}
|
||||
|
||||
/* Read indexed register (64 bit) from bytecode. */
|
||||
static uint64_t tci_read_r64(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
static uint64_t tci_read_r64(const tcg_target_ulong *regs,
|
||||
const uint8_t **tb_ptr)
|
||||
{
|
||||
uint64_t value = tci_read_reg64(regs, **tb_ptr);
|
||||
*tb_ptr += 1;
|
||||
@@ -276,7 +282,7 @@ static uint64_t tci_read_r64(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
|
||||
/* Read indexed register(s) with target address from bytecode. */
|
||||
static target_ulong
|
||||
tci_read_ulong(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
tci_read_ulong(const tcg_target_ulong *regs, const uint8_t **tb_ptr)
|
||||
{
|
||||
target_ulong taddr = tci_read_r(regs, tb_ptr);
|
||||
#if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
|
||||
@@ -287,7 +293,7 @@ tci_read_ulong(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
|
||||
/* Read indexed register or constant (native size) from bytecode. */
|
||||
static tcg_target_ulong
|
||||
tci_read_ri(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
tci_read_ri(const tcg_target_ulong *regs, const uint8_t **tb_ptr)
|
||||
{
|
||||
tcg_target_ulong value;
|
||||
TCGReg r = **tb_ptr;
|
||||
@@ -301,7 +307,8 @@ tci_read_ri(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
}
|
||||
|
||||
/* Read indexed register or constant (32 bit) from bytecode. */
|
||||
static uint32_t tci_read_ri32(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
static uint32_t tci_read_ri32(const tcg_target_ulong *regs,
|
||||
const uint8_t **tb_ptr)
|
||||
{
|
||||
uint32_t value;
|
||||
TCGReg r = **tb_ptr;
|
||||
@@ -316,14 +323,16 @@ static uint32_t tci_read_ri32(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
|
||||
#if TCG_TARGET_REG_BITS == 32
|
||||
/* Read two indexed registers or constants (2 * 32 bit) from bytecode. */
|
||||
static uint64_t tci_read_ri64(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
static uint64_t tci_read_ri64(const tcg_target_ulong *regs,
|
||||
const uint8_t **tb_ptr)
|
||||
{
|
||||
uint32_t low = tci_read_ri32(regs, tb_ptr);
|
||||
return tci_uint64(tci_read_ri32(regs, tb_ptr), low);
|
||||
}
|
||||
#elif TCG_TARGET_REG_BITS == 64
|
||||
/* Read indexed register or constant (64 bit) from bytecode. */
|
||||
static uint64_t tci_read_ri64(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
static uint64_t tci_read_ri64(const tcg_target_ulong *regs,
|
||||
const uint8_t **tb_ptr)
|
||||
{
|
||||
uint64_t value;
|
||||
TCGReg r = **tb_ptr;
|
||||
@@ -337,7 +346,7 @@ static uint64_t tci_read_ri64(const tcg_target_ulong *regs, uint8_t **tb_ptr)
|
||||
}
|
||||
#endif
|
||||
|
||||
static tcg_target_ulong tci_read_label(uint8_t **tb_ptr)
|
||||
static tcg_target_ulong tci_read_label(const uint8_t **tb_ptr)
|
||||
{
|
||||
tcg_target_ulong label = tci_read_i(tb_ptr);
|
||||
tci_assert(label != 0);
|
||||
@@ -475,8 +484,9 @@ static bool tci_compare64(uint64_t u0, uint64_t u1, TCGCond condition)
|
||||
#endif
|
||||
|
||||
/* Interpret pseudo code in tb. */
|
||||
uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t *tb_ptr)
|
||||
uintptr_t tcg_qemu_tb_exec(CPUArchState *env, const void *v_tb_ptr)
|
||||
{
|
||||
const uint8_t *tb_ptr = v_tb_ptr;
|
||||
tcg_target_ulong regs[TCG_TARGET_NB_REGS];
|
||||
long tcg_temps[CPU_TEMP_BUF_NLONGS];
|
||||
uintptr_t sp_value = (uintptr_t)(tcg_temps + CPU_TEMP_BUF_NLONGS);
|
||||
@@ -490,7 +500,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t *tb_ptr)
|
||||
TCGOpcode opc = tb_ptr[0];
|
||||
#if defined(CONFIG_DEBUG_TCG) && !defined(NDEBUG)
|
||||
uint8_t op_size = tb_ptr[1];
|
||||
uint8_t *old_code_ptr = tb_ptr;
|
||||
const uint8_t *old_code_ptr = tb_ptr;
|
||||
#endif
|
||||
tcg_target_ulong t0;
|
||||
tcg_target_ulong t1;
|
||||
|
||||
@@ -545,7 +545,7 @@ static void tcg_out_movi(TCGContext *s, TCGType type,
|
||||
old_code_ptr[1] = s->code_ptr - old_code_ptr;
|
||||
}
|
||||
|
||||
static inline void tcg_out_call(TCGContext *s, tcg_insn_unit *arg)
|
||||
static inline void tcg_out_call(TCGContext *s, const tcg_insn_unit *arg)
|
||||
{
|
||||
uint8_t *old_code_ptr = s->code_ptr;
|
||||
tcg_out_op_t(s, INDEX_op_call);
|
||||
|
||||
Loaded 100 of 107 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user