mirror of
https://github.com/utmapp/qemu.git
synced 2026-12-01 22:23:23 -10:00
Compare commits
34
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5897229105 | ||
|
|
d35954d3c9 | ||
|
|
64dcc3969b | ||
|
|
06962e1aaa | ||
|
|
ec151f4659 | ||
|
|
9d9ca24b72 | ||
|
|
fe1b754eab | ||
|
|
6d6e43ebce | ||
|
|
f479e7eacd | ||
|
|
dbbbd13bf6 | ||
|
|
dc32fd2d89 | ||
|
|
3354c800ac | ||
|
|
365294d55a | ||
|
|
a6bff5ccc8 | ||
|
|
c803fc9d7d | ||
|
|
653cc15628 | ||
|
|
2e77c788d8 | ||
|
|
1534c4fe04 | ||
|
|
3a513c9db4 | ||
|
|
e27df17c9c | ||
|
|
aa7ebf9a77 | ||
|
|
be54898fd5 | ||
|
|
7a64de81ce | ||
|
|
71f21b796f | ||
|
|
4e70afa94d | ||
|
|
36195a781c | ||
|
|
2541dde936 | ||
|
|
ecc067a3ba | ||
|
|
819b2c2984 | ||
|
|
8ed0f7cb4d | ||
|
|
d1bf1e28b6 | ||
|
|
47cd50d3d2 | ||
|
|
324cef19f8 | ||
|
|
e252078b6e |
No files matched your search
+6
-3
@@ -49,9 +49,9 @@
|
||||
[submodule "roms/edk2"]
|
||||
path = roms/edk2
|
||||
url = https://gitlab.com/qemu-project/edk2.git
|
||||
[submodule "slirp"]
|
||||
path = slirp
|
||||
url = https://gitlab.com/qemu-project/libslirp.git
|
||||
[submodule "subprojects/libslirp"]
|
||||
path = subprojects/libslirp
|
||||
url = https://git.qemu.org/git/libslirp.git
|
||||
[submodule "roms/opensbi"]
|
||||
path = roms/opensbi
|
||||
url = https://gitlab.com/qemu-project/opensbi.git
|
||||
@@ -64,3 +64,6 @@
|
||||
[submodule "roms/vbootrom"]
|
||||
path = roms/vbootrom
|
||||
url = https://gitlab.com/qemu-project/vbootrom.git
|
||||
[submodule "libucontext"]
|
||||
path = subprojects/libucontext
|
||||
url = https://github.com/utmapp/libucontext.git
|
||||
+13
@@ -456,13 +456,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: 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]>
|
||||
|
||||
@@ -0,0 +1,484 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
HVFState *hvf_state;
|
||||
|
||||
#ifdef __aarch64__
|
||||
#define HV_VM_DEFAULT NULL
|
||||
#endif
|
||||
|
||||
/* 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(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 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_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 dummy_signal(int sig)
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
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);
|
||||
g_free(cpu->hvf);
|
||||
cpu->hvf = NULL;
|
||||
}
|
||||
|
||||
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 void hvf_accel_ops_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
|
||||
|
||||
ops->create_vcpu_thread = hvf_start_vcpu_thread;
|
||||
ops->kick_vcpu_thread = hvf_kick_vcpu_thread;
|
||||
|
||||
ops->synchronize_post_reset = hvf_cpu_synchronize_post_reset;
|
||||
ops->synchronize_post_init = hvf_cpu_synchronize_post_init;
|
||||
ops->synchronize_state = hvf_cpu_synchronize_state;
|
||||
ops->synchronize_pre_loadvm = hvf_cpu_synchronize_pre_loadvm;
|
||||
};
|
||||
static const TypeInfo hvf_accel_ops_type = {
|
||||
.name = ACCEL_OPS_NAME("hvf"),
|
||||
|
||||
.parent = TYPE_ACCEL_OPS,
|
||||
.class_init = hvf_accel_ops_class_init,
|
||||
.abstract = true,
|
||||
};
|
||||
static void hvf_accel_ops_register_types(void)
|
||||
{
|
||||
type_register_static(&hvf_accel_ops_type);
|
||||
}
|
||||
type_init(hvf_accel_ops_register_types);
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
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,7 @@
|
||||
hvf_ss = ss.source_set()
|
||||
hvf_ss.add(files(
|
||||
'hvf-all.c',
|
||||
'hvf-accel-ops.c',
|
||||
))
|
||||
|
||||
specific_ss.add_all(when: 'CONFIG_HVF', if_true: hvf_ss)
|
||||
@@ -2,6 +2,7 @@ specific_ss.add(files('accel-common.c'))
|
||||
softmmu_ss.add(files('accel-softmmu.c'))
|
||||
user_ss.add(files('accel-user.c'))
|
||||
|
||||
subdir('hvf')
|
||||
subdir('qtest')
|
||||
subdir('kvm')
|
||||
subdir('tcg')
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "disas/disas.h"
|
||||
#include "exec/exec-all.h"
|
||||
#include "tcg/tcg.h"
|
||||
#include "tcg/tcg-apple-jit.h"
|
||||
#include "qemu/atomic.h"
|
||||
#include "qemu/compiler.h"
|
||||
#include "qemu/timer.h"
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "disas/disas.h"
|
||||
#include "exec/exec-all.h"
|
||||
#include "tcg/tcg.h"
|
||||
#include "tcg/tcg-apple-jit.h"
|
||||
#if defined(CONFIG_USER_ONLY)
|
||||
#include "qemu.h"
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
@@ -1128,7 +1129,7 @@ static bool alloc_code_gen_buffer_anon(size_t size, int prot,
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_TCG_INTERPRETER
|
||||
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
|
||||
#ifdef CONFIG_POSIX
|
||||
#include "qemu/memfd.h"
|
||||
|
||||
@@ -1255,7 +1256,7 @@ static bool alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **errp)
|
||||
|
||||
static bool alloc_code_gen_buffer_splitwx(size_t size, Error **errp)
|
||||
{
|
||||
#ifndef CONFIG_TCG_INTERPRETER
|
||||
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
|
||||
# ifdef CONFIG_DARWIN
|
||||
return alloc_code_gen_buffer_splitwx_vmremap(size, errp);
|
||||
# endif
|
||||
@@ -1288,7 +1289,7 @@ static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp)
|
||||
|
||||
prot = PROT_READ | PROT_WRITE | PROT_EXEC;
|
||||
flags = MAP_PRIVATE | MAP_ANONYMOUS;
|
||||
#ifdef CONFIG_TCG_INTERPRETER
|
||||
#if defined(CONFIG_TCG_INTERPRETER) || defined(CONFIG_TCG_THREADED_INTERPRETER)
|
||||
/* The tcg interpreter does not need execute permission. */
|
||||
prot = PROT_READ | PROT_WRITE;
|
||||
#elif defined(CONFIG_DARWIN)
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
#ifdef CONFIG_BSD
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/queue.h>
|
||||
#ifndef __DragonFly__
|
||||
#if defined(HAVE_SYS_DISK_H)
|
||||
#include <sys/disk.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
+29
-22
@@ -42,6 +42,8 @@
|
||||
#include "scsi/constants.h"
|
||||
|
||||
#if defined(__APPLE__) && (__MACH__)
|
||||
#include <sys/ioctl.h>
|
||||
#if defined(HAVE_HOST_BLOCK_DEVICE)
|
||||
#include <paths.h>
|
||||
#include <sys/param.h>
|
||||
#include <IOKit/IOKitLib.h>
|
||||
@@ -52,6 +54,7 @@
|
||||
//#include <IOKit/storage/IOCDTypes.h>
|
||||
#include <IOKit/storage/IODVDMedia.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif /* defined(HAVE_HOST_BLOCK_DEVICE) */
|
||||
#endif
|
||||
|
||||
#ifdef __sun__
|
||||
@@ -181,7 +184,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 {
|
||||
@@ -2308,8 +2321,10 @@ static int64_t raw_getlength(BlockDriverState *bs)
|
||||
again:
|
||||
#endif
|
||||
if (!fstat(fd, &sb) && (S_IFCHR & sb.st_mode)) {
|
||||
size = 0;
|
||||
#ifdef DIOCGMEDIASIZE
|
||||
if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size))
|
||||
size = 0;
|
||||
#elif defined(DIOCGPART)
|
||||
{
|
||||
struct partinfo pi;
|
||||
@@ -2318,9 +2333,7 @@ again:
|
||||
else
|
||||
size = 0;
|
||||
}
|
||||
if (size == 0)
|
||||
#endif
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#elif defined(DKIOCGETBLOCKCOUNT) && defined(DKIOCGETBLOCKSIZE)
|
||||
{
|
||||
uint64_t sectors = 0;
|
||||
uint32_t sector_size = 0;
|
||||
@@ -2328,19 +2341,15 @@ again:
|
||||
if (ioctl(fd, DKIOCGETBLOCKCOUNT, §ors) == 0
|
||||
&& ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) == 0) {
|
||||
size = sectors * sector_size;
|
||||
} else {
|
||||
size = lseek(fd, 0LL, SEEK_END);
|
||||
if (size < 0) {
|
||||
return -errno;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
size = lseek(fd, 0LL, SEEK_END);
|
||||
#endif
|
||||
if (size == 0) {
|
||||
size = lseek(fd, 0LL, SEEK_END);
|
||||
}
|
||||
if (size < 0) {
|
||||
return -errno;
|
||||
}
|
||||
#endif
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
switch(s->type) {
|
||||
case FTYPE_CD:
|
||||
@@ -3027,6 +3036,7 @@ static BlockStatsSpecific *raw_get_specific_stats(BlockDriverState *bs)
|
||||
return stats;
|
||||
}
|
||||
|
||||
#if defined(HAVE_HOST_BLOCK_DEVICE)
|
||||
static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs)
|
||||
{
|
||||
BlockStatsSpecific *stats = g_new(BlockStatsSpecific, 1);
|
||||
@@ -3036,6 +3046,7 @@ static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs)
|
||||
|
||||
return stats;
|
||||
}
|
||||
#endif /* HAVE_HOST_BLOCK_DEVICE */
|
||||
|
||||
static QemuOptsList raw_create_opts = {
|
||||
.name = "raw-create-opts",
|
||||
@@ -3260,6 +3271,8 @@ BlockDriver bdrv_file = {
|
||||
/***********************************************/
|
||||
/* host device */
|
||||
|
||||
#if defined(HAVE_HOST_BLOCK_DEVICE)
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
static kern_return_t GetBSDPath(io_iterator_t mediaIterator, char *bsdPath,
|
||||
CFIndex maxPathSize, int flags);
|
||||
@@ -3552,16 +3565,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)
|
||||
{
|
||||
@@ -3885,6 +3888,8 @@ static BlockDriver bdrv_host_cdrom = {
|
||||
};
|
||||
#endif /* __FreeBSD__ */
|
||||
|
||||
#endif /* HAVE_HOST_BLOCK_DEVICE */
|
||||
|
||||
static void bdrv_file_init(void)
|
||||
{
|
||||
/*
|
||||
@@ -3892,6 +3897,7 @@ static void bdrv_file_init(void)
|
||||
* registered last will get probed first.
|
||||
*/
|
||||
bdrv_register(&bdrv_file);
|
||||
#if defined(HAVE_HOST_BLOCK_DEVICE)
|
||||
bdrv_register(&bdrv_host_device);
|
||||
#ifdef __linux__
|
||||
bdrv_register(&bdrv_host_cdrom);
|
||||
@@ -3899,6 +3905,7 @@ static void bdrv_file_init(void)
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
bdrv_register(&bdrv_host_cdrom);
|
||||
#endif
|
||||
#endif /* HAVE_HOST_BLOCK_DEVICE */
|
||||
}
|
||||
|
||||
block_init(bdrv_file_init);
|
||||
@@ -362,6 +362,7 @@ tsan="no"
|
||||
fortify_source="$default_feature"
|
||||
strip_opt="yes"
|
||||
tcg_interpreter="false"
|
||||
tcg_threaded_interpreter="false"
|
||||
bigendian="no"
|
||||
mingw32="no"
|
||||
gcov="no"
|
||||
@@ -463,9 +464,11 @@ gettext="auto"
|
||||
fuse="auto"
|
||||
fuse_lseek="auto"
|
||||
multiprocess="auto"
|
||||
shared_lib="false"
|
||||
|
||||
malloc_trim="auto"
|
||||
gio="$default_feature"
|
||||
slirp_smbd="auto"
|
||||
|
||||
# parse CC options second
|
||||
for opt do
|
||||
@@ -835,8 +838,6 @@ do
|
||||
fi
|
||||
done
|
||||
|
||||
: ${smbd=${SMBD-/usr/sbin/smbd}}
|
||||
|
||||
# Default objcc to clang if available, otherwise use CC
|
||||
if has clang; then
|
||||
objcc=clang
|
||||
@@ -1115,6 +1116,10 @@ for opt do
|
||||
;;
|
||||
--enable-tcg-interpreter) tcg_interpreter="true"
|
||||
;;
|
||||
--disable-tcg-tcti) tcg_threaded_interpreter="false"
|
||||
;;
|
||||
--enable-tcg-tcti) tcg_threaded_interpreter="true"
|
||||
;;
|
||||
--disable-cap-ng) cap_ng="disabled"
|
||||
;;
|
||||
--enable-cap-ng) cap_ng="enabled"
|
||||
@@ -1565,6 +1570,14 @@ for opt do
|
||||
;;
|
||||
--disable-gio) gio=no
|
||||
;;
|
||||
--enable-slirp-smbd) slirp_smbd=yes
|
||||
;;
|
||||
--disable-slirp-smbd) slirp_smbd=no
|
||||
;;
|
||||
--enable-shared-lib) shared_lib=true
|
||||
;;
|
||||
--disable-shared-lib) shared_lib=false
|
||||
;;
|
||||
*)
|
||||
echo "ERROR: unknown option $opt"
|
||||
echo "Try '$0 --help' for more information"
|
||||
@@ -1778,7 +1791,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
|
||||
@@ -1792,6 +1805,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
|
||||
@@ -1919,6 +1933,7 @@ disabled with --disable-FEATURE, default is enabled if available
|
||||
fuse-lseek SEEK_HOLE/SEEK_DATA support for FUSE exports
|
||||
multiprocess Out of process device emulation support
|
||||
gio libgio support
|
||||
slirp-smbd use smbd (at path --smbd=*) in slirp networking
|
||||
|
||||
NOTE: The object files are built at the place where configure is launched
|
||||
EOF
|
||||
@@ -4535,12 +4550,26 @@ 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"
|
||||
coroutine_impl=ucontext
|
||||
libucontext="enabled"
|
||||
;;
|
||||
*)
|
||||
coroutine_impl=$coroutine
|
||||
libucontext="disabled"
|
||||
;;
|
||||
esac
|
||||
|
||||
if test "$coroutine_pool" = ""; then
|
||||
coroutine_pool=yes
|
||||
fi
|
||||
@@ -5250,11 +5279,24 @@ case "$slirp" in
|
||||
auto | enabled | internal)
|
||||
# Simpler to always update submodule, even if not needed.
|
||||
if test "$git_submodules_action" != "ignore"; then
|
||||
git_submodules="${git_submodules} slirp"
|
||||
git_submodules="${git_submodules} subprojects/libslirp"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
# Check for slirp smbd dupport
|
||||
: ${smbd=${SMBD-/usr/sbin/smbd}}
|
||||
if test "$slirp_smbd" != "no" ; then
|
||||
if test "$mingw32" = "yes" ; then
|
||||
if test "$slirp_smbd" = "yes" ; then
|
||||
error_exit "Host smbd not supported on this platform."
|
||||
fi
|
||||
slirp_smbd=no
|
||||
else
|
||||
slirp_smbd=yes
|
||||
fi
|
||||
fi
|
||||
|
||||
##########################################
|
||||
# check for usable __NR_keyctl syscall
|
||||
|
||||
@@ -5530,7 +5572,10 @@ fi
|
||||
if test "$guest_agent" = "yes" ; then
|
||||
echo "CONFIG_GUEST_AGENT=y" >> $config_host_mak
|
||||
fi
|
||||
echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
|
||||
if test "$slirp_smbd" = "yes" ; then
|
||||
echo "CONFIG_SLIRP_SMBD=y" >> $config_host_mak
|
||||
echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
|
||||
fi
|
||||
if test "$vde" = "yes" ; then
|
||||
echo "CONFIG_VDE=y" >> $config_host_mak
|
||||
echo "VDE_LIBS=$vde_libs" >> $config_host_mak
|
||||
@@ -5861,7 +5906,7 @@ if test "$qom_cast_debug" = "yes" ; then
|
||||
echo "CONFIG_QOM_CAST_DEBUG=y" >> $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
|
||||
@@ -6343,7 +6388,11 @@ 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 "$cross_compile" = "yes"; then
|
||||
cross_arg="--cross-file config-meson.cross"
|
||||
@@ -6420,14 +6469,13 @@ NINJA=$ninja $meson setup \
|
||||
-Dlibnfs=$libnfs -Diconv=$iconv -Dcurses=$curses -Dlibudev=$libudev\
|
||||
-Drbd=$rbd -Dlzo=$lzo -Dsnappy=$snappy -Dlzfse=$lzfse \
|
||||
-Dzstd=$zstd -Dseccomp=$seccomp -Dvirtfs=$virtfs -Dcap_ng=$cap_ng \
|
||||
-Dattr=$attr -Ddefault_devices=$default_devices \
|
||||
-Dattr=$attr -Ddefault_devices=$default_devices -Ducontext=$libucontext \
|
||||
-Ddocs=$docs -Dsphinx_build=$sphinx_build -Dinstall_blobs=$blobs \
|
||||
-Dvhost_user_blk_server=$vhost_user_blk_server -Dmultiprocess=$multiprocess \
|
||||
-Dfuse=$fuse -Dfuse_lseek=$fuse_lseek -Dguest_agent_msi=$guest_agent_msi \
|
||||
$(if test "$default_features" = no; then echo "-Dauto_features=disabled"; fi) \
|
||||
-Dtcg_interpreter=$tcg_interpreter \
|
||||
$cross_arg \
|
||||
"$PWD" "$source_path"
|
||||
-Dtcg_interpreter=$tcg_interpreter -Dtcg_threaded_interpreter=$tcg_threaded_interpreter\
|
||||
-Dshared_lib=$shared_lib $cross_arg "$PWD" "$source_path"
|
||||
|
||||
if test "$?" -ne 0 ; then
|
||||
error_exit "meson setup failed"
|
||||
|
||||
@@ -152,6 +152,8 @@ static void initialize_debug_host(CPUDebug *s)
|
||||
#endif
|
||||
#if defined(CONFIG_TCG_INTERPRETER)
|
||||
s->info.print_insn = print_insn_tci;
|
||||
#elif defined(CONFIG_TCG_THREADED_INTERPRETER)
|
||||
s->info.print_insn = print_insn_tcti;
|
||||
#elif defined(__i386__)
|
||||
s->info.mach = bfd_mach_i386_i386;
|
||||
s->info.print_insn = print_insn_i386;
|
||||
|
||||
@@ -50,3 +50,6 @@ config CS4231
|
||||
|
||||
config MARVELL_88W8618
|
||||
bool
|
||||
|
||||
config SCREAMER
|
||||
bool
|
||||
@@ -13,3 +13,4 @@ softmmu_ss.add(when: 'CONFIG_PL041', if_true: files('pl041.c', 'lm4549.c'))
|
||||
softmmu_ss.add(when: 'CONFIG_SB16', if_true: files('sb16.c'))
|
||||
softmmu_ss.add(when: 'CONFIG_VT82C686', if_true: files('via-ac97.c'))
|
||||
softmmu_ss.add(when: 'CONFIG_WM8750', if_true: files('wm8750.c'))
|
||||
softmmu_ss.add(when: 'CONFIG_SCREAMER', if_true: files('screamer.c'))
|
||||
@@ -0,0 +1,985 @@
|
||||
/*
|
||||
* File: Screamer.c
|
||||
* Description: Implement the Screamer sound chip used in Apple Macintoshes.
|
||||
* It works by filling a buffer, then playing the buffer.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "audio/audio.h"
|
||||
#include "hw/hw.h"
|
||||
#include "hw/irq.h"
|
||||
#include <inttypes.h>
|
||||
#include "hw/ppc/mac.h"
|
||||
#include "hw/qdev-properties.h"
|
||||
#include "migration/vmstate.h"
|
||||
#include "include/hw/audio/screamer.h"
|
||||
|
||||
#define DEBUG_SCREAMER 0
|
||||
#define DPRINTF(fmt, ...) \
|
||||
do { if (DEBUG_SCREAMER) { printf(fmt , ## __VA_ARGS__); } } while (0)
|
||||
|
||||
#define SOUND_CONTROL_REG 0
|
||||
#define CODEC_CONTROL_REG 1
|
||||
#define CODEC_STATUS_REG 2
|
||||
#define CLIP_COUNT_REG 3
|
||||
#define BYTE_SWAP_REG 4
|
||||
#define FRAME_COUNT_REG 5
|
||||
|
||||
#define AWACS_BUSY 0x01000000
|
||||
|
||||
/* Used with AWACS register 1 */
|
||||
#define RECALIBRATE 0x004
|
||||
#define LOOPTHRU 0x040
|
||||
#define SPEAKER_MUTE 0x080
|
||||
#define HEADPHONE_MUTE 0x200
|
||||
#define OUTPUT_ZERO 0x400
|
||||
#define OUTPUT_ONE 0x800
|
||||
#define PARALLEL_OUTPUT 0xc00
|
||||
|
||||
/* Function prototypes */
|
||||
static uint32_t set_busy_bit(uint32_t value, int bit);
|
||||
static uint32_t set_part_ready_bit(uint32_t value, int bit_value);
|
||||
static uint32_t set_revision(uint32_t input_value);
|
||||
static uint32_t set_manufacturer(uint32_t input_value);
|
||||
static int get_sampling_rate(ScreamerState *s);
|
||||
static uint32_t get_frame_count_reg(ScreamerState *s);
|
||||
static void add_to_speaker_buffer(DBDMA_io *io);
|
||||
static void dma_request(DBDMA_io *io);
|
||||
|
||||
|
||||
/**************************** Getters *************************/
|
||||
|
||||
/* Returns the codec control register's encoded AWACS address */
|
||||
static uint8_t get_codec_control_address(uint32_t value)
|
||||
{
|
||||
uint8_t return_value;
|
||||
return_value = (value >> 12) & 0x00000fff;
|
||||
return return_value;
|
||||
}
|
||||
|
||||
|
||||
static uint32_t get_sound_control_reg(ScreamerState *s)
|
||||
{
|
||||
DPRINTF("%s() called - returned 0x%x\n", __func__, s->sound_control);
|
||||
return s->sound_control;
|
||||
}
|
||||
|
||||
/* The AWACS registers are accessed thru this register */
|
||||
static uint32_t get_codec_control_reg(ScreamerState *s)
|
||||
{
|
||||
int awacs_register = get_codec_control_address(s->codec_control);
|
||||
uint32_t return_value = s->awacs[awacs_register];
|
||||
return_value = set_busy_bit(return_value, 0); /* Tell CPU we are ready */
|
||||
DPRINTF("%s() called - returned 0x%x\tAWACS register: %d\n", __func__,
|
||||
return_value, awacs_register);
|
||||
return return_value;
|
||||
}
|
||||
|
||||
/*
|
||||
* Determines if the readback bit is set.
|
||||
* It is used by the Codec Control register.
|
||||
*/
|
||||
static bool readback_enabled(ScreamerState *s)
|
||||
{
|
||||
/* Note: bit zero is the readback enabled bit */
|
||||
if (s->awacs[7] & 1) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t get_codec_status_reg(ScreamerState *s)
|
||||
{
|
||||
uint32_t return_value;
|
||||
|
||||
/* if in readback mode - return AWACS register value */
|
||||
if (readback_enabled(s)) {
|
||||
int awacs_register = (s->awacs[7] & 0xe) >> 1;
|
||||
s->awacs[7] = s->awacs[7] & 0xfffffffe; /* turn off readback mode */
|
||||
return_value = s->awacs[awacs_register] << 4;
|
||||
DPRINTF("readback enable bit is set, returning AWACS register %d\t"
|
||||
"value:0x%x\n", awacs_register, return_value);
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
/* Tell CPU we are ready */
|
||||
return_value = set_part_ready_bit(s->codec_status, 1);
|
||||
|
||||
/* Set Revision to Screamer */
|
||||
return_value = set_revision(return_value);
|
||||
|
||||
/* Set the Manufacturer to Crystal */
|
||||
return_value = set_manufacturer(return_value);
|
||||
DPRINTF("%s() called - returned 0x%x\n", __func__, return_value);
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
static uint32_t get_clip_count_reg(ScreamerState *s)
|
||||
{
|
||||
DPRINTF("%s() called - returned 0x%x\n", __func__, s->clip_count);
|
||||
uint32_t return_value;
|
||||
return_value = s->clip_count;
|
||||
/* This is reset everytime it is read */
|
||||
s->clip_count = 0;
|
||||
return return_value;
|
||||
}
|
||||
|
||||
static uint32_t get_byte_swap_reg(ScreamerState *s)
|
||||
{
|
||||
DPRINTF("%s() called - returned 0x%x\n", __func__, s->byte_swap);
|
||||
/*
|
||||
* If all you hear is noise, it could be this register reporting the
|
||||
* wrong value.
|
||||
*/
|
||||
return s->byte_swap ? 0 : 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the frame (sample) count
|
||||
*/
|
||||
static uint32_t get_frame_count_reg(ScreamerState *s)
|
||||
{
|
||||
DPRINTF("%s() called - returned 0x%x\n", __func__, s->frame_count);
|
||||
return s->frame_count;
|
||||
}
|
||||
|
||||
static uint8_t get_left_vol(uint32_t value)
|
||||
{
|
||||
return value & 0xf;
|
||||
}
|
||||
|
||||
static uint8_t get_right_vol(uint32_t value)
|
||||
{
|
||||
return value & 0x3c0 >> 6;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the sampling rate.
|
||||
* If the audio is playing back too fast or too slow, this function may be the
|
||||
* cause.
|
||||
*/
|
||||
static int get_sampling_rate(ScreamerState *s)
|
||||
{
|
||||
uint32_t screamer_rate = s->sound_control & 0x700;
|
||||
int return_value;
|
||||
|
||||
/* All return values are in Hertz */
|
||||
switch (screamer_rate) {
|
||||
case 0x0:
|
||||
return_value = 44100;
|
||||
break;
|
||||
case 0x100:
|
||||
return_value = 29400;
|
||||
break;
|
||||
case 0x200:
|
||||
return_value = 22050;
|
||||
break;
|
||||
case 0x300:
|
||||
return_value = 17640;
|
||||
break;
|
||||
case 0x400:
|
||||
return_value = 14700;
|
||||
break;
|
||||
case 0x500:
|
||||
return_value = 11025;
|
||||
break;
|
||||
case 0x600:
|
||||
return_value = 8820;
|
||||
break;
|
||||
case 0x700:
|
||||
return_value = 7350;
|
||||
break;
|
||||
default:
|
||||
DPRINTF("get_sampling_rate() unknown value: 0x%x\nDefaulting to"
|
||||
" 44100 Hz.\n", screamer_rate);
|
||||
return 44100;
|
||||
}
|
||||
DPRINTF("%s() called - returning %dHz\n", __func__, return_value);
|
||||
return return_value;
|
||||
}
|
||||
|
||||
/**************************** End of getters *************************/
|
||||
|
||||
/***************************** Speaker call back *************************/
|
||||
|
||||
/* resets the play and buffer position markers */
|
||||
static void reset_markers(ScreamerState *s)
|
||||
{
|
||||
s->spk_play_position = 0;
|
||||
s->spk_buffer_position = 0;
|
||||
}
|
||||
|
||||
|
||||
/* Sends the samples to the host for playing */
|
||||
static void send_samples_to_host(ScreamerState *s, int max_samples)
|
||||
{
|
||||
int write_length, requested_length;
|
||||
requested_length = MIN(max_samples, (s->spk_buffer_position -
|
||||
s->spk_play_position));
|
||||
write_length = AUD_write(s->speaker_voice,
|
||||
&s->spk_buffer[s->spk_play_position],
|
||||
requested_length);
|
||||
DPRINTF("requested length: %d\twrite length: %d\t",
|
||||
requested_length, write_length);
|
||||
s->spk_play_position += write_length;
|
||||
DPRINTF("AUD_write %d/%d\n", s->spk_play_position, s->spk_buffer_position);
|
||||
s->frame_count += write_length;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Called by QEMU's audio system to tell the output backend to send samples
|
||||
* from the buffer to the host sound system.
|
||||
* opaque: a pointer to the ScreamerState instance.
|
||||
* max_samples: the number of samples that can be sent to the hardware buffer.
|
||||
*/
|
||||
static void speaker_callback(void *opaque, int max_samples)
|
||||
{
|
||||
ScreamerState *s = (ScreamerState *) opaque;
|
||||
|
||||
/* if we have more samples to play */
|
||||
if (s->spk_buffer_position > 0) {
|
||||
if (s->spk_buffer_position > s->spk_play_position) {
|
||||
DPRINTF("%s() called - max_samples: %d\n", __func__, max_samples);
|
||||
send_samples_to_host(s, max_samples);
|
||||
}
|
||||
if (s->spk_play_position >= s->spk_buffer_position) {
|
||||
DPRINTF("done playing buffer\n");
|
||||
DPRINTF("pp: %d\tbp: %d\n", s->spk_play_position,
|
||||
s->spk_buffer_position);
|
||||
if (s->spk_play_position > s->spk_buffer_position) {
|
||||
DPRINTF("Error detected! - pp > bp\n\a");
|
||||
}
|
||||
reset_markers(s);
|
||||
/* play postponed samples */
|
||||
if (s->dma_io.len > 0) {
|
||||
DPRINTF("playing postponed samples\n");
|
||||
add_to_speaker_buffer(&s->dma_io);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/************************* End of speaker call back *************************/
|
||||
|
||||
|
||||
/* Opens the speaker's voice */
|
||||
static void open_speaker_voice(ScreamerState *s)
|
||||
{
|
||||
DPRINTF("%s() called\n", __func__);
|
||||
|
||||
/* if voice is already open return from function */
|
||||
if (s->speaker_voice != NULL) {
|
||||
DPRINTF("closing speaker voice\n");
|
||||
AUD_close_out(&s->card, s->speaker_voice);
|
||||
s->speaker_voice = NULL;
|
||||
}
|
||||
struct audsettings audio_settings;
|
||||
audio_settings.freq = get_sampling_rate(s); /* in hertz */
|
||||
audio_settings.nchannels = 2; /* stereo output */
|
||||
audio_settings.fmt = AUDIO_FORMAT_S16; /* signed 16 bit */
|
||||
audio_settings.endianness = get_byte_swap_reg(s); /* endianness */
|
||||
s->speaker_voice = AUD_open_out(&s->card, s->speaker_voice, SOUND_CHIP_NAME
|
||||
" speaker", s, speaker_callback,
|
||||
&audio_settings);
|
||||
if (!s->speaker_voice) {
|
||||
AUD_log(SOUND_CHIP_NAME, "Out voice could not be opened\n");
|
||||
} else {
|
||||
AUD_set_active_out(s->speaker_voice, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/******************************* Setters *************************************/
|
||||
|
||||
|
||||
/* Updates QEMU's audio backend settings */
|
||||
static void set_QEMU_audio_settings(ScreamerState *s)
|
||||
{
|
||||
DPRINTF("%s() called\n", __func__);
|
||||
open_speaker_voice(s);
|
||||
}
|
||||
|
||||
|
||||
/* Return value: 1 = muted 0 = not muted */
|
||||
static int is_muted(ScreamerState *s)
|
||||
{
|
||||
int mute_state = s->awacs[1] & SPEAKER_MUTE ? 1 : 0;
|
||||
if (s->awacs[1] & SPEAKER_MUTE) {
|
||||
DPRINTF("speaker is muted\n");
|
||||
} else {
|
||||
DPRINTF("speaker is unmuted\n");
|
||||
}
|
||||
|
||||
if (s->awacs[1] & HEADPHONE_MUTE) {
|
||||
DPRINTF("headphone is muted\n");
|
||||
} else {
|
||||
DPRINTF("headphone is unmuted\n");
|
||||
}
|
||||
return mute_state;
|
||||
}
|
||||
|
||||
|
||||
/* Converts Screamer's volume system to QEMU's system */
|
||||
static int screamer_to_qemu_volume(int x)
|
||||
{
|
||||
return -16 * x + 240;
|
||||
}
|
||||
|
||||
|
||||
/* Sets QEMU's volume. */
|
||||
static void set_volume(ScreamerState *s)
|
||||
{
|
||||
int should_mute = is_muted(s);
|
||||
|
||||
/* Get Screamer volume values */
|
||||
uint8_t left_vol = get_left_vol(s->awacs[4]);
|
||||
uint8_t right_vol = get_right_vol(s->awacs[4]);
|
||||
DPRINTF("set_volume() called - M:%d\tL:%d\tR:%d\n", should_mute, left_vol,
|
||||
right_vol);
|
||||
|
||||
/* Convert Screamer to QEMU volume values */
|
||||
left_vol = screamer_to_qemu_volume(left_vol);
|
||||
right_vol = screamer_to_qemu_volume(right_vol);
|
||||
DPRINTF("QEMU volume: L:%d\tR:%d\n", left_vol, right_vol);
|
||||
AUD_set_volume_out(s->speaker_voice, should_mute, left_vol, right_vol);
|
||||
}
|
||||
|
||||
|
||||
/* Sets the sound control register */
|
||||
static void set_sound_control_reg(ScreamerState *s, uint32_t value)
|
||||
{
|
||||
DPRINTF("set_sound_control_reg() called - value: 0x%x\n", value);
|
||||
s->sound_control = value;
|
||||
set_QEMU_audio_settings(s);
|
||||
}
|
||||
|
||||
|
||||
/* Used for input gain only - can be ignored for now. */
|
||||
static void set_awacs_0_reg(ScreamerState *s, uint32_t new_value)
|
||||
{
|
||||
DPRINTF("Settings AWACS register 0 to 0x%x\n", s->awacs[0]);
|
||||
s->awacs[0] = new_value;
|
||||
}
|
||||
|
||||
|
||||
static void set_awacs_1_reg(ScreamerState *s, uint32_t new_value)
|
||||
{
|
||||
DPRINTF("Settings AWACS register 1 to 0x%x\n", new_value);
|
||||
|
||||
s->awacs[1] = new_value;
|
||||
|
||||
/* If recalibration requested */
|
||||
if (new_value & RECALIBRATE) {
|
||||
DPRINTF("Recalibration requested - unimplemented\n");
|
||||
new_value = new_value ^ RECALIBRATE; /* Turn off recalibrate bit */
|
||||
}
|
||||
|
||||
/* If loop thru set - what does this mean? */
|
||||
if (new_value & LOOPTHRU) {
|
||||
DPRINTF("Loopthru enabled - doing nothing\n");
|
||||
}
|
||||
|
||||
/* Set headphone jack mute state */
|
||||
if (new_value & HEADPHONE_MUTE) {
|
||||
DPRINTF("Headphone muted\n");
|
||||
}
|
||||
|
||||
else {
|
||||
DPRINTF("Headphone unmuted\n");
|
||||
}
|
||||
|
||||
if (new_value & SPEAKER_MUTE) {
|
||||
DPRINTF("Speaker muted\n");
|
||||
}
|
||||
|
||||
else {
|
||||
DPRINTF("Speaker unmuted\n");
|
||||
}
|
||||
|
||||
if (new_value & OUTPUT_ZERO) {
|
||||
DPRINTF("output zero set - not sure what this means\n");
|
||||
}
|
||||
|
||||
if (new_value & OUTPUT_ONE) {
|
||||
DPRINTF("output one set - not sure what this means\n");
|
||||
}
|
||||
|
||||
if (new_value & PARALLEL_OUTPUT) {
|
||||
DPRINTF("parallel port enabled - but no parallel port here\n");
|
||||
}
|
||||
|
||||
set_volume(s);
|
||||
}
|
||||
|
||||
|
||||
/* This is used for headphone volume - not needed */
|
||||
static void set_awacs_2_reg(ScreamerState *s, uint32_t new_value)
|
||||
{
|
||||
DPRINTF("Settings AWACS register 2 to 0x%x\n"
|
||||
"Ignoring change in headphone volume.\n", s->awacs[2]);
|
||||
s->awacs[2] = new_value;
|
||||
}
|
||||
|
||||
|
||||
/* Unknown register purpose */
|
||||
static void set_awacs_3_reg(ScreamerState *s, uint32_t new_value)
|
||||
{
|
||||
DPRINTF("Settings AWACS register 3 to 0x%x\n"
|
||||
"This register has an unknown purpose and does not do anything\n",
|
||||
s->awacs[3]);
|
||||
s->awacs[3] = new_value;
|
||||
}
|
||||
|
||||
|
||||
/* Mostly deals with speaker volume */
|
||||
static void set_awacs_4_reg(ScreamerState *s, uint32_t new_value)
|
||||
{
|
||||
DPRINTF("AWACS register 4 write: 0x%x\n", new_value);
|
||||
s->awacs[4] = new_value;
|
||||
set_volume(s);
|
||||
}
|
||||
|
||||
|
||||
/* This register is about loop thru stuff I don't understand */
|
||||
static void set_awacs_5_reg(ScreamerState *s, uint32_t new_value)
|
||||
{
|
||||
DPRINTF("Settings AWACS register 5 to 0x%x\n"
|
||||
"Loop thru update ignored.\n", s->awacs[5]);
|
||||
s->awacs[5] = new_value;
|
||||
}
|
||||
|
||||
|
||||
/* Prints the states of the AWACS power register */
|
||||
static void print_power_reg_values(uint32_t value)
|
||||
{
|
||||
if ((value & 0x3) == 0) {
|
||||
printf("Screamer run state set\n");
|
||||
}
|
||||
if ((value & 0x3) == 1) {
|
||||
printf("Screamer doze state set\n");
|
||||
}
|
||||
if ((value & 0x3) == 2) {
|
||||
printf("Screamer idle state set\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Power Magement register */
|
||||
static void set_awacs_6_reg(ScreamerState *s, uint32_t new_value)
|
||||
{
|
||||
DPRINTF("Settings AWACS register 6 to 0x%x\n"
|
||||
"Power management update ignored.\n", s->awacs[6]);
|
||||
if (DEBUG_SCREAMER) {
|
||||
print_power_reg_values(new_value);
|
||||
}
|
||||
s->awacs[6] = new_value;
|
||||
}
|
||||
|
||||
|
||||
/* Read Back - repeating something that was sent to this chip? */
|
||||
static void set_awacs_7_reg(ScreamerState *s, uint32_t new_value)
|
||||
{
|
||||
DPRINTF("Settings AWACS register 7 to 0x%x\n", new_value);
|
||||
s->awacs[7] = new_value;
|
||||
}
|
||||
|
||||
|
||||
/* Sets the AWACs registers - a.k.a. shadow registers */
|
||||
static void set_awacs_register(ScreamerState *s, uint32_t value)
|
||||
{
|
||||
int the_register = get_codec_control_address(value);
|
||||
|
||||
switch (the_register) {
|
||||
case 0:
|
||||
set_awacs_0_reg(s, value);
|
||||
break;
|
||||
case 1:
|
||||
set_awacs_1_reg(s, value);
|
||||
break;
|
||||
case 2:
|
||||
set_awacs_2_reg(s, value);
|
||||
break;
|
||||
case 3:
|
||||
set_awacs_3_reg(s, value);
|
||||
break;
|
||||
case 4:
|
||||
set_awacs_4_reg(s, value);
|
||||
break;
|
||||
case 5:
|
||||
set_awacs_5_reg(s, value);
|
||||
break;
|
||||
case 6:
|
||||
set_awacs_6_reg(s, value);
|
||||
break;
|
||||
case 7:
|
||||
set_awacs_7_reg(s, value);
|
||||
break;
|
||||
default:
|
||||
DPRINTF("Unhandled awacs registers %d\n", the_register);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Used to set the AWACS registers */
|
||||
static void set_codec_control_reg(ScreamerState *s, uint32_t value)
|
||||
{
|
||||
DPRINTF("set_codec_control_reg() called - value: 0x%x\n", value);
|
||||
s->codec_control = value;
|
||||
set_awacs_register(s, value);
|
||||
}
|
||||
|
||||
static void set_codec_status_reg(ScreamerState *s, uint32_t value)
|
||||
{
|
||||
DPRINTF("set_codec_status_reg() called - value: 0x%x\n", value);
|
||||
s->codec_status = value;
|
||||
}
|
||||
|
||||
static void set_clip_count_reg(ScreamerState *s, uint32_t new_value)
|
||||
{
|
||||
DPRINTF("set_clip_count_reg() called - value: 0x%x\n", new_value);
|
||||
s->clip_count = new_value;
|
||||
}
|
||||
|
||||
static void set_byte_swap_reg(ScreamerState *s, uint32_t value)
|
||||
{
|
||||
DPRINTF("set_byte_swap_reg() called - value: 0x%x\n", value);
|
||||
s->byte_swap = value;
|
||||
}
|
||||
|
||||
static void set_frame_count_reg(ScreamerState *s, uint32_t new_value)
|
||||
{
|
||||
DPRINTF("%s() called - value: 0x%x\n", __func__, new_value);
|
||||
s->frame_count = new_value;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the busy bit of codec control register.
|
||||
* It is used to tell the CPU to wait.
|
||||
* value: the codec control register's value
|
||||
* bit_value: used to set or disable the busy bit
|
||||
*/
|
||||
static uint32_t set_busy_bit(uint32_t value, int bit_value)
|
||||
{
|
||||
const int busy_bit = 0x01000000;
|
||||
uint32_t return_value;
|
||||
if (bit_value == 1) /* Set this bit */
|
||||
return_value = (value | busy_bit);
|
||||
else /* bit_value == 0 Disable this bit */
|
||||
return_value = (value & ~busy_bit);
|
||||
return return_value;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Sets the part ready bit of the codec status register
|
||||
* value: the codec status register's value
|
||||
* bit_value: used to set or disable the part ready bit
|
||||
*/
|
||||
static uint32_t set_part_ready_bit(uint32_t value, int bit_value)
|
||||
{
|
||||
const int part_ready_bit = 0x00400000;
|
||||
uint32_t return_value;
|
||||
if (bit_value == 1) /* Set this bit */
|
||||
return_value = (value | part_ready_bit);
|
||||
else /* bit_value == 0 Disable this bit */
|
||||
return_value = (value & ~part_ready_bit);
|
||||
return return_value;
|
||||
}
|
||||
|
||||
/* Sets bits 12 and 13 to 1 to indicate the Screamer revision */
|
||||
static uint32_t set_revision(uint32_t input_value)
|
||||
{
|
||||
uint32_t return_value;
|
||||
return_value = input_value | 0x3000;
|
||||
return return_value;
|
||||
}
|
||||
|
||||
/* Sets bit 8 to indicate Crystal as the manufacturer */
|
||||
static uint32_t set_manufacturer(uint32_t input_value)
|
||||
{
|
||||
uint32_t return_value;
|
||||
return_value = input_value | 0x100;
|
||||
return return_value;
|
||||
}
|
||||
|
||||
|
||||
/************************** End of Setters *********************************/
|
||||
|
||||
|
||||
/*************************** DMA functions *********************************/
|
||||
|
||||
/*
|
||||
* Sends audio samples from a microphone or line-in to memory.
|
||||
* Used for sound input.
|
||||
* Currently only prevents a deadlock condition with Mac OS 9.
|
||||
*/
|
||||
static void screamer_to_dma(DBDMA_io *io)
|
||||
{
|
||||
DPRINTF("%s() called\n", __func__);
|
||||
ScreamerState *s = (ScreamerState *)io->opaque;
|
||||
DBDMAState *dbs = s->dbdma;
|
||||
DBDMA_channel *ch = &dbs->channels[0x12];
|
||||
ch->regs[DBDMA_STATUS] |= DEAD;
|
||||
ch->regs[DBDMA_STATUS] &= ~ACTIVE;
|
||||
io->dma_end(io);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static void print_dma_info(DBDMA_io *io)
|
||||
{
|
||||
#define RUN 0x8000
|
||||
#define PAUSE 0x4000
|
||||
#define FLUSH 0x2000
|
||||
#define WAKE 0x1000
|
||||
#define DEAD 0x0800
|
||||
#define ACTIVE 0x0400
|
||||
#define BT 0x0100
|
||||
#define DEVSTAT 0x00ff
|
||||
|
||||
/*
|
||||
* RUN and PAUSE are bits under software control only.
|
||||
* FLUSH and WAKE are set by SW and cleared by hardware.
|
||||
* DEAD, ACTIVE and BT are only under hardware control.
|
||||
*/
|
||||
|
||||
DBDMA_channel *ch = io->channel;
|
||||
printf("DMA FLAGS: ");
|
||||
|
||||
if (ch->regs[DBDMA_STATUS] & RUN) {
|
||||
printf("RUN ");
|
||||
}
|
||||
|
||||
if (ch->regs[DBDMA_STATUS] & ACTIVE) {
|
||||
printf("ACTIVE ");
|
||||
}
|
||||
|
||||
if (ch->regs[DBDMA_STATUS] & PAUSE) {
|
||||
printf("PAUSE ");
|
||||
}
|
||||
|
||||
if (ch->regs[DBDMA_STATUS] & DEAD) {
|
||||
printf("DEAD ");
|
||||
}
|
||||
|
||||
if (ch->regs[DBDMA_STATUS] & WAKE) {
|
||||
printf("WAKE ");
|
||||
}
|
||||
|
||||
if (ch->regs[DBDMA_STATUS] & BT) {
|
||||
printf("BT ");
|
||||
}
|
||||
|
||||
if (ch->regs[DBDMA_STATUS] & DEVSTAT) {
|
||||
printf("DEVSTAT ");
|
||||
}
|
||||
|
||||
if (ch->regs[DBDMA_STATUS] & FLUSH) {
|
||||
printf("FLUSH ");
|
||||
}
|
||||
|
||||
if (ch->io.processing == true) {
|
||||
printf("processing ");
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/* Tell the DMA controller we request more samples */
|
||||
static void dma_request(DBDMA_io *io)
|
||||
{
|
||||
DPRINTF("%s() called\n", __func__);
|
||||
if (DEBUG_SCREAMER) {
|
||||
print_dma_info(io);
|
||||
}
|
||||
io->len = 0;
|
||||
io->dma_end(io);
|
||||
}
|
||||
|
||||
|
||||
/* Adds sample data to the buffer */
|
||||
static void add_to_speaker_buffer(DBDMA_io *io)
|
||||
{
|
||||
ScreamerState *s = (ScreamerState *) io->opaque;
|
||||
|
||||
if (s->spk_buffer_position + io->len > MAX_BUFFER_SIZE) {
|
||||
/* postpone calling these samples until the buffer has been emptied */
|
||||
memcpy(&s->dma_io, io, sizeof(DBDMA_io));
|
||||
return;
|
||||
}
|
||||
dma_memory_read(&address_space_memory, io->addr,
|
||||
&s->spk_buffer[s->spk_buffer_position], io->len);
|
||||
s->spk_buffer_position += io->len;
|
||||
DPRINTF("%s() called - len: %d pos: %d/%d\n", __func__, io->len,
|
||||
s->spk_buffer_position, MAX_BUFFER_SIZE);
|
||||
|
||||
dma_request(io);
|
||||
}
|
||||
|
||||
/*
|
||||
* Called by the DMA chip to transfer samples from memory to the
|
||||
* Screamer chip.
|
||||
* Used for sound output.
|
||||
*/
|
||||
static void dma_to_screamer(DBDMA_io *io)
|
||||
{
|
||||
add_to_speaker_buffer(io);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This will flush the audio buffer of previous audio - eliminating previous
|
||||
* audio playback.
|
||||
*/
|
||||
static void send_silence_to_speaker(ScreamerState *s)
|
||||
{
|
||||
DPRINTF("Silencing audio buffer...\n");
|
||||
int length = MAX_BUFFER_SIZE;
|
||||
s->spk_buffer_position = length;
|
||||
s->spk_play_position = 0;
|
||||
memset(s->spk_buffer, 0, length);
|
||||
s->dma_io.len = 0; /* stop any postponed samples from playing */
|
||||
}
|
||||
|
||||
|
||||
/* This is called after audio stops playing */
|
||||
static void dma_send_flush(DBDMA_io *io)
|
||||
{
|
||||
DPRINTF("dma_send_flush() called\n");
|
||||
if (DEBUG_SCREAMER) {
|
||||
print_dma_info(io);
|
||||
}
|
||||
ScreamerState *s = (ScreamerState *)io->opaque;
|
||||
reset_markers(s);
|
||||
send_silence_to_speaker(s);
|
||||
if (io->len > 0) {
|
||||
dma_request(io);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void dma_receive_flush(DBDMA_io *io)
|
||||
{
|
||||
DPRINTF("dma_receive_flush() called\n");
|
||||
}
|
||||
|
||||
|
||||
/* Set the functions the DMA system will call */
|
||||
void screamer_register_dma_functions(ScreamerState *s, void *dbdma,
|
||||
int send_channel, int receive_channel)
|
||||
{
|
||||
DPRINTF("%s() called\n", __func__);
|
||||
DPRINTF("send channel: %d\treceive channel: %d\n", send_channel,
|
||||
receive_channel);
|
||||
s->dbdma = dbdma;
|
||||
|
||||
/* Setup the DMA send system */
|
||||
DBDMA_register_channel(s->dbdma, send_channel, s->dma_send_irq,
|
||||
dma_to_screamer, dma_send_flush, s);
|
||||
|
||||
/* Setup the DMA receive system */
|
||||
DBDMA_register_channel(s->dbdma, receive_channel, s->dma_receive_irq,
|
||||
screamer_to_dma, dma_receive_flush, s);
|
||||
}
|
||||
|
||||
/************************* End of DMA functions **************************/
|
||||
|
||||
/* Resets this sound chip */
|
||||
static void screamer_reset(DeviceState *d)
|
||||
{
|
||||
DPRINTF("screamer_reset() called\n");
|
||||
ScreamerState *s = SCREAMER(d);
|
||||
set_sound_control_reg(s, 0);
|
||||
set_codec_control_reg(s, 0);
|
||||
set_codec_status_reg(s, 0);
|
||||
set_clip_count_reg(s, 0);
|
||||
set_byte_swap_reg(s, 0);
|
||||
set_frame_count_reg(s, 0);
|
||||
int i, num_awacs_regs = 8;
|
||||
for (i = 0; i < num_awacs_regs; i++) {
|
||||
s->awacs[i] = 0;
|
||||
}
|
||||
set_QEMU_audio_settings(s);
|
||||
reset_markers(s);
|
||||
s->dma_io.len = 0;
|
||||
}
|
||||
|
||||
/* Called when the CPU reads the memory addresses assigned to Screamer */
|
||||
static uint64_t screamer_mmio_read(void *opaque, hwaddr addr, unsigned size)
|
||||
{
|
||||
ScreamerState *state = opaque;
|
||||
uint32_t return_value;
|
||||
|
||||
addr = addr >> 4;
|
||||
switch (addr) {
|
||||
case SOUND_CONTROL_REG:
|
||||
return_value = get_sound_control_reg(state);
|
||||
break;
|
||||
case CODEC_CONTROL_REG:
|
||||
return_value = get_codec_control_reg(state);
|
||||
break;
|
||||
case CODEC_STATUS_REG:
|
||||
return_value = get_codec_status_reg(state);
|
||||
break;
|
||||
case CLIP_COUNT_REG:
|
||||
return_value = get_clip_count_reg(state);
|
||||
break;
|
||||
case BYTE_SWAP_REG:
|
||||
return_value = get_byte_swap_reg(state);
|
||||
break;
|
||||
case FRAME_COUNT_REG:
|
||||
return_value = get_frame_count_reg(state);
|
||||
break;
|
||||
default:
|
||||
DPRINTF("Unknown register read - addr:%" HWADDR_PRIx "\tsize:%d\n",
|
||||
addr, size);
|
||||
return_value = 12021981; /* Value used for debugging purposes */
|
||||
}
|
||||
DPRINTF("screamer_mmio_read() called addr: %" HWADDR_PRIx " size: %d",
|
||||
addr >> 4, size);
|
||||
DPRINTF(" returning 0x%x\n", return_value);
|
||||
return return_value;
|
||||
}
|
||||
|
||||
|
||||
/* Called when the CPU writes to the memory addresses assigned to Screamer */
|
||||
static void screamer_mmio_write(void *opaque, hwaddr addr, uint64_t raw_value,
|
||||
unsigned size)
|
||||
{
|
||||
DPRINTF("screamer_mmio_write() called - size: %d\n", size);
|
||||
ScreamerState *state = opaque;
|
||||
uint32_t value = raw_value & 0xffffffff;
|
||||
addr = addr >> 4;
|
||||
|
||||
switch (addr) {
|
||||
case SOUND_CONTROL_REG:
|
||||
set_sound_control_reg(state, value);
|
||||
break;
|
||||
case CODEC_CONTROL_REG:
|
||||
set_codec_control_reg(state, value);
|
||||
break;
|
||||
case CODEC_STATUS_REG:
|
||||
set_codec_status_reg(state, value);
|
||||
break;
|
||||
case CLIP_COUNT_REG:
|
||||
set_clip_count_reg(state, value);
|
||||
break;
|
||||
case BYTE_SWAP_REG:
|
||||
set_byte_swap_reg(state, value);
|
||||
break;
|
||||
case FRAME_COUNT_REG:
|
||||
set_frame_count_reg(state, value);
|
||||
break;
|
||||
default:
|
||||
DPRINTF("Unknown register write - addr:%" HWADDR_PRIx "\tvalue:%d\n",
|
||||
addr, value);
|
||||
}
|
||||
}
|
||||
|
||||
/* Used for memory_region_init_io() for memory mapped I/O */
|
||||
static const MemoryRegionOps screamer_ops = {
|
||||
.read = screamer_mmio_read,
|
||||
.write = screamer_mmio_write,
|
||||
.endianness = DEVICE_LITTLE_ENDIAN,
|
||||
.valid = {
|
||||
.min_access_size = 4,
|
||||
.max_access_size = 4
|
||||
}
|
||||
};
|
||||
|
||||
/* Called when the device has become active */
|
||||
static void screamer_realize(DeviceState *dev, Error **errp)
|
||||
{
|
||||
DPRINTF("screamer_realize() called\n");
|
||||
screamer_reset(dev);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Called when an instance of the Screamer device is created.
|
||||
* Also called when this HMP command is called: device_add screamer
|
||||
*/
|
||||
static void screamer_init(Object *obj)
|
||||
{
|
||||
DPRINTF("screamer_init() called\n");
|
||||
|
||||
ScreamerState *s = (ScreamerState *)obj;
|
||||
SysBusDevice *d = SYS_BUS_DEVICE(obj);
|
||||
const int region_size = 5 * 32;
|
||||
|
||||
/* Makes the read and write ops work */
|
||||
memory_region_init_io(&s->io_memory_region, OBJECT(s),
|
||||
&screamer_ops, s, SOUND_CHIP_NAME, region_size);
|
||||
|
||||
/* Sets the SysBusDevice's memory property */
|
||||
sysbus_init_mmio(d, &s->io_memory_region);
|
||||
|
||||
/* Setup all the interrupt requests */
|
||||
sysbus_init_irq(d, &s->irq);
|
||||
sysbus_init_irq(d, &s->dma_send_irq);
|
||||
sysbus_init_irq(d, &s->dma_receive_irq);
|
||||
|
||||
/* Registers Screamer with QEMU's audio system */
|
||||
AUD_register_card(SOUND_CHIP_NAME, &s->card);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* When saving and restoring the state of the VM, this is used to save and
|
||||
* restore the registers.
|
||||
*/
|
||||
static const VMStateDescription vmstate_screamer = {
|
||||
.name = "Screamer",
|
||||
.version_id = 1,
|
||||
.minimum_version_id = 1,
|
||||
.fields = (VMStateField[]) {
|
||||
VMSTATE_UINT16_ARRAY(awacs, ScreamerState, 8), /* 8 AWACS registers */
|
||||
VMSTATE_UINT32(sound_control, ScreamerState),
|
||||
VMSTATE_UINT32(codec_control, ScreamerState),
|
||||
VMSTATE_UINT32(codec_status, ScreamerState),
|
||||
VMSTATE_UINT32(clip_count, ScreamerState),
|
||||
VMSTATE_UINT32(byte_swap, ScreamerState),
|
||||
VMSTATE_UINT32(frame_count, ScreamerState),
|
||||
VMSTATE_END_OF_LIST()
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Sets the class data. It is like polymorphism and inheritance in object
|
||||
* oriented languages.
|
||||
*/
|
||||
static void screamer_class_init(ObjectClass *class, void *data)
|
||||
{
|
||||
DPRINTF("screamer_class_init() called\n");
|
||||
DeviceClass *dc = DEVICE_CLASS(class);
|
||||
dc->realize = screamer_realize;
|
||||
dc->reset = screamer_reset;
|
||||
dc->desc = "Apple Screamer";
|
||||
dc->vmsd = &vmstate_screamer;
|
||||
dc->hotpluggable = false;
|
||||
}
|
||||
|
||||
/* Used for QOM function registration */
|
||||
static const TypeInfo screamer_info = {
|
||||
.name = "screamer",
|
||||
.parent = TYPE_SYS_BUS_DEVICE,
|
||||
.instance_size = sizeof(ScreamerState),
|
||||
.instance_init = screamer_init,
|
||||
.class_init = screamer_class_init,
|
||||
};
|
||||
|
||||
/* QOM registration of above functions for calling */
|
||||
static void screamer_register_types(void)
|
||||
{
|
||||
DPRINTF("screamer_register_types() called\n");
|
||||
type_register_static(&screamer_info);
|
||||
}
|
||||
|
||||
/* QEMU Object Model (QOM) stuff */
|
||||
type_init(screamer_register_types)
|
||||
@@ -60,6 +60,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)
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "hw/intc/heathrow_pic.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
#include "trace.h"
|
||||
#include "include/hw/audio/screamer.h"
|
||||
|
||||
/* Note: this code is strongly inspirated from the corresponding code
|
||||
* in PearPC */
|
||||
@@ -105,6 +106,17 @@ static void macio_common_realize(PCIDevice *d, Error **errp)
|
||||
sysbus_dev = SYS_BUS_DEVICE(&s->dbdma);
|
||||
memory_region_add_subregion(&s->bar, 0x08000,
|
||||
sysbus_mmio_get_region(sysbus_dev, 0));
|
||||
if (!qdev_realize(DEVICE(&s->screamer), BUS(&s->macio_bus), errp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Add the screamer sound chip */
|
||||
sysbus_dev = SYS_BUS_DEVICE(&s->screamer);
|
||||
const int offset = 0x14000; /* Offset from base address register (bar) */
|
||||
const int region_number = 0; /* which memory region to use */
|
||||
memory_region_add_subregion(&s->bar, offset,
|
||||
sysbus_mmio_get_region(sysbus_dev,
|
||||
region_number));
|
||||
|
||||
qdev_prop_set_uint32(DEVICE(&s->escc), "disabled", 0);
|
||||
qdev_prop_set_uint32(DEVICE(&s->escc), "frequency", ESCC_CLOCK);
|
||||
@@ -365,6 +377,19 @@ static void macio_newworld_realize(PCIDevice *d, Error **errp)
|
||||
memory_region_add_subregion(&s->bar, 0x16000,
|
||||
sysbus_mmio_get_region(sysbus_dev, 0));
|
||||
}
|
||||
|
||||
/* Screamer Sound Chip */
|
||||
const int gpio_0 = 0;
|
||||
const int gpio_1 = 1;
|
||||
const int transmit_channel = 0x10;
|
||||
const int receive_channel = 0x12;
|
||||
sysbus_dev = SYS_BUS_DEVICE(&s->screamer);
|
||||
sysbus_connect_irq(sysbus_dev, gpio_0, qdev_get_gpio_in(pic_dev,
|
||||
NEWWORLD_SCREAMER_IRQ));
|
||||
sysbus_connect_irq(sysbus_dev, gpio_1, qdev_get_gpio_in(pic_dev,
|
||||
NEWWORLD_SCREAMER_DMA_IRQ));
|
||||
screamer_register_dma_functions(SCREAMER(sysbus_dev), &s->dbdma,
|
||||
transmit_channel, receive_channel);
|
||||
}
|
||||
|
||||
static void macio_newworld_init(Object *obj)
|
||||
@@ -394,6 +419,9 @@ static void macio_instance_init(Object *obj)
|
||||
object_initialize_child(OBJECT(s), "dbdma", &s->dbdma, TYPE_MAC_DBDMA);
|
||||
|
||||
object_initialize_child(OBJECT(s), "escc", &s->escc, TYPE_ESCC);
|
||||
|
||||
object_initialize_child(OBJECT(s), SOUND_CHIP_NAME, &s->screamer,
|
||||
TYPE_SCREAMER);
|
||||
}
|
||||
|
||||
static const VMStateDescription vmstate_macio_oldworld = {
|
||||
|
||||
@@ -106,6 +106,7 @@ config MAC_NEWWORLD
|
||||
select MAC_PMU
|
||||
select UNIN_PCI
|
||||
select FW_CFG_PPC
|
||||
select SCREAMER
|
||||
|
||||
config E500
|
||||
bool
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#include "hw/pci/pci_host.h"
|
||||
#include "hw/pci-host/uninorth.h"
|
||||
#include "qom/object.h"
|
||||
#include "hw/ppc/mac_dbdma.h"
|
||||
#include "audio/audio.h"
|
||||
|
||||
/* SMP is not enabled, for now */
|
||||
#define MAX_CPUS 1
|
||||
@@ -67,6 +69,9 @@
|
||||
#define NEWWORLD_IDE1_DMA_IRQ 0x3
|
||||
#define NEWWORLD_EXTING_GPIO1 0x2f
|
||||
#define NEWWORLD_EXTING_GPIO9 0x37
|
||||
#define NEWWORLD_SCREAMER_IRQ 0x18
|
||||
#define NEWWORLD_SCREAMER_DMA_IRQ 0x9
|
||||
#define NEWWORLD_SCREAMER_RX_IRQ 0xa
|
||||
|
||||
/* Core99 machine */
|
||||
#define TYPE_CORE99_MACHINE MACHINE_TYPE_NAME("mac99")
|
||||
|
||||
@@ -411,6 +411,7 @@ typedef struct disassemble_info {
|
||||
typedef int (*disassembler_ftype) (bfd_vma, disassemble_info *);
|
||||
|
||||
int print_insn_tci(bfd_vma, disassemble_info*);
|
||||
int print_insn_tcti(bfd_vma, disassemble_info*);
|
||||
int print_insn_big_mips (bfd_vma, disassemble_info*);
|
||||
int print_insn_little_mips (bfd_vma, disassemble_info*);
|
||||
int print_insn_nanomips (bfd_vma, disassemble_info*);
|
||||
|
||||
@@ -543,7 +543,11 @@ void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr);
|
||||
#if defined(CONFIG_TCG_INTERPRETER)
|
||||
extern __thread uintptr_t tci_tb_ptr;
|
||||
# define GETPC() tci_tb_ptr
|
||||
#elif defined(CONFIG_TCG_THREADED_INTERPRETER)
|
||||
extern __thread uintptr_t tcti_call_return_address;
|
||||
# define GETPC() tcti_call_return_address
|
||||
#else
|
||||
/* Note that this is correct for TCTI also; whose gadget behaves like native code. */
|
||||
# define GETPC() \
|
||||
((uintptr_t)__builtin_extract_return_addr(__builtin_return_address(0)))
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* File: screamer.h
|
||||
* Description: header file to the hw/audio/screamer.c file
|
||||
*/
|
||||
|
||||
#ifndef screamer_h
|
||||
#define screamer_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "audio/audio.h"
|
||||
#include "hw/ppc/mac_dbdma.h"
|
||||
|
||||
#define TYPE_SCREAMER "screamer"
|
||||
#define SCREAMER(obj) OBJECT_CHECK(ScreamerState, (obj), TYPE_SCREAMER)
|
||||
#define SOUND_CHIP_NAME "Screamer Sound Chip"
|
||||
#define MAX_BUFFER_SIZE (128 * 64)
|
||||
|
||||
typedef struct ScreamerState {
|
||||
SysBusDevice parent_obj;
|
||||
uint16_t awacs[8]; /* Shadow/awacs registers */
|
||||
uint32_t sound_control;
|
||||
uint32_t codec_control;
|
||||
uint32_t codec_status;
|
||||
uint32_t clip_count;
|
||||
uint32_t byte_swap;
|
||||
uint32_t frame_count;
|
||||
SWVoiceOut *speaker_voice;
|
||||
DBDMAState *dbdma;
|
||||
qemu_irq dma_send_irq;
|
||||
qemu_irq dma_receive_irq;
|
||||
qemu_irq irq;
|
||||
QEMUSoundCard card;
|
||||
MemoryRegion io_memory_region;
|
||||
uint8_t spk_buffer[MAX_BUFFER_SIZE];
|
||||
uint16_t spk_buffer_position, spk_play_position;
|
||||
DBDMA_io dma_io;
|
||||
} ScreamerState;
|
||||
|
||||
void screamer_register_dma_functions(ScreamerState *s, void *dbdma,
|
||||
int send_channel, int receive_channel);
|
||||
|
||||
#endif /* screamer_h */
|
||||
@@ -245,6 +245,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)
|
||||
@@ -430,7 +431,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;
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "hw/ppc/mac.h"
|
||||
#include "hw/ppc/mac_dbdma.h"
|
||||
#include "hw/ppc/openpic.h"
|
||||
#include "hw/audio/screamer.h"
|
||||
#include "qom/object.h"
|
||||
|
||||
/* MacIO virtual bus */
|
||||
@@ -88,6 +89,7 @@ struct MacIOState {
|
||||
PMUState pmu;
|
||||
DBDMAState dbdma;
|
||||
ESCCState escc;
|
||||
ScreamerState screamer;
|
||||
uint64_t frequency;
|
||||
};
|
||||
|
||||
|
||||
@@ -702,30 +702,6 @@ char *qemu_get_host_name(Error **errp);
|
||||
*/
|
||||
size_t qemu_get_host_physmem(void);
|
||||
|
||||
/*
|
||||
* Toggle write/execute on the pages marked MAP_JIT
|
||||
* for the current thread.
|
||||
*/
|
||||
#if defined(MAC_OS_VERSION_11_0) && \
|
||||
MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0
|
||||
static inline void qemu_thread_jit_execute(void)
|
||||
{
|
||||
if (__builtin_available(macOS 11.0, *)) {
|
||||
pthread_jit_write_protect_np(true);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void qemu_thread_jit_write(void)
|
||||
{
|
||||
if (__builtin_available(macOS 11.0, *)) {
|
||||
pthread_jit_write_protect_np(false);
|
||||
}
|
||||
}
|
||||
#else
|
||||
static inline void qemu_thread_jit_write(void) {}
|
||||
static inline void qemu_thread_jit_execute(void) {}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Platforms which do not support system() return ENOSYS
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
|
||||
#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;
|
||||
bool vtimer_masked;
|
||||
sigset_t unblock_ipi_mask;
|
||||
};
|
||||
|
||||
void assert_hvf_ok(hv_return_t ret);
|
||||
int hvf_arch_init_vcpu(CPUState *cpu);
|
||||
void hvf_arch_vcpu_destroy(CPUState *cpu);
|
||||
int hvf_vcpu_exec(CPUState *);
|
||||
hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t);
|
||||
int hvf_put_registers(CPUState *);
|
||||
int hvf_get_registers(CPUState *);
|
||||
void hvf_kick_vcpu_thread(CPUState *cpu);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
static inline void qemu_thread_jit_execute(void)
|
||||
{
|
||||
if (jit_write_protect_supported()) {
|
||||
jit_write_protect(true);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void qemu_thread_jit_write(void)
|
||||
{
|
||||
if (jit_write_protect_supported()) {
|
||||
jit_write_protect(false);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* define TCG_APPLE_JIT_H */
|
||||
+1
-1
@@ -1296,7 +1296,7 @@ static inline unsigned get_mmuidx(TCGMemOpIdx oi)
|
||||
#define TB_EXIT_IDXMAX 1
|
||||
#define TB_EXIT_REQUESTED 3
|
||||
|
||||
#ifdef CONFIG_TCG_INTERPRETER
|
||||
#if defined(CONFIG_TCG_INTERPRETER) || defined(CONFIG_TCG_THREADED_INTERPRETER)
|
||||
uintptr_t tcg_qemu_tb_exec(CPUArchState *env, const void *tb_ptr);
|
||||
#else
|
||||
typedef uintptr_t tcg_prologue_fn(CPUArchState *env, const void *tb_ptr);
|
||||
|
||||
+91
-68
@@ -58,6 +58,7 @@ python = import('python').find_installation()
|
||||
supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux']
|
||||
supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv32', 'riscv64', 'x86', 'x86_64',
|
||||
'arm', 'aarch64', 'mips', 'mips64', 'sparc', 'sparc64']
|
||||
tcti_supported_cpus = ['aarch64']
|
||||
|
||||
cpu = host_machine.cpu_family()
|
||||
targetos = host_machine.system()
|
||||
@@ -77,6 +78,13 @@ else
|
||||
endif
|
||||
|
||||
accelerator_targets = { 'CONFIG_KVM': kvm_targets }
|
||||
|
||||
if cpu in ['aarch64']
|
||||
accelerator_targets += {
|
||||
'CONFIG_HVF': ['aarch64-softmmu']
|
||||
}
|
||||
endif
|
||||
|
||||
if cpu in ['x86', 'x86_64', 'arm', 'aarch64']
|
||||
# i368 emulator provides xenpv machine type for multiple architectures
|
||||
accelerator_targets += {
|
||||
@@ -169,6 +177,7 @@ socket = []
|
||||
version_res = []
|
||||
coref = []
|
||||
iokit = []
|
||||
vmnet = not_found
|
||||
emulator_link_args = []
|
||||
hvf = not_found
|
||||
if targetos == 'windows'
|
||||
@@ -181,7 +190,8 @@ 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: false)
|
||||
vmnet = dependency('appleframeworks', modules: 'vmnet', required: false)
|
||||
elif targetos == 'sunos'
|
||||
socket = [cc.find_library('socket'),
|
||||
cc.find_library('nsl'),
|
||||
@@ -246,6 +256,25 @@ if not get_option('tcg').disabled()
|
||||
endif
|
||||
if get_option('tcg_interpreter')
|
||||
tcg_arch = 'tci'
|
||||
elif get_option('tcg_threaded_interpreter')
|
||||
if cpu not in tcti_supported_cpus
|
||||
error('Unsupported CPU @0@ for TCTI, try --enable-tcg-interpreter'.format(cpu))
|
||||
else
|
||||
warning('TCTI is extremely experimental and incomplete! Things might break!')
|
||||
tcg_arch = '@0@-tcti'.format(cpu)
|
||||
endif
|
||||
|
||||
# Tell our compiler how to generate our TCTI gadgets.
|
||||
gadget_generator = 'tcg/@0@/tcti-gadget-gen.py'.format(tcg_arch)
|
||||
tcti_gadgets = custom_target('tcti-gadgets.c.inc',
|
||||
output: 'tcti-gadgets.c.inc',
|
||||
input: gadget_generator,
|
||||
command: [find_program(gadget_generator), '@OUTPUT@'],
|
||||
build_by_default: true,
|
||||
build_always_stale: false)
|
||||
|
||||
genh += tcti_gadgets
|
||||
|
||||
elif config_host['ARCH'] == 'sparc64'
|
||||
tcg_arch = 'sparc'
|
||||
elif config_host['ARCH'] == 's390x'
|
||||
@@ -1056,6 +1085,9 @@ if get_option('cfi')
|
||||
add_global_link_arguments(cfi_flags, native: false, language: ['c', 'cpp', 'objc'])
|
||||
endif
|
||||
|
||||
have_host_block_device = (targetos != 'darwin' or
|
||||
cc.has_header('IOKit/storage/IOMedia.h'))
|
||||
|
||||
#################
|
||||
# config-host.h #
|
||||
#################
|
||||
@@ -1138,6 +1170,7 @@ config_host_data.set('CONFIG_FUSE', fuse.found())
|
||||
config_host_data.set('CONFIG_FUSE_LSEEK', fuse_lseek.found())
|
||||
config_host_data.set('CONFIG_X11', x11.found())
|
||||
config_host_data.set('CONFIG_CFI', get_option('cfi'))
|
||||
config_host_data.set('CONFIG_VMNET', vmnet.found())
|
||||
config_host_data.set('QEMU_VERSION', '"@0@"'.format(meson.project_version()))
|
||||
config_host_data.set('QEMU_VERSION_MAJOR', meson.project_version().split('.')[0])
|
||||
config_host_data.set('QEMU_VERSION_MINOR', meson.project_version().split('.')[1])
|
||||
@@ -1149,6 +1182,8 @@ config_host_data.set('HAVE_PTY_H', cc.has_header('pty.h'))
|
||||
config_host_data.set('HAVE_SYS_IOCCOM_H', cc.has_header('sys/ioccom.h'))
|
||||
config_host_data.set('HAVE_SYS_KCOV_H', cc.has_header('sys/kcov.h'))
|
||||
config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', prefix: '#include <stdlib.h>'))
|
||||
config_host_data.set('HAVE_HOST_BLOCK_DEVICE', have_host_block_device)
|
||||
config_host_data.set('HAVE_SYS_DISK_H', cc.has_header('sys/disk.h'))
|
||||
|
||||
config_host_data.set('CONFIG_PREADV', cc.has_function('preadv', prefix: '#include <sys/uio.h>'))
|
||||
|
||||
@@ -1276,6 +1311,8 @@ foreach target : target_dirs
|
||||
config_all += { sym: 'y' }
|
||||
if sym == 'CONFIG_TCG' and tcg_arch == 'tci'
|
||||
config_target += { 'CONFIG_TCG_INTERPRETER': 'y' }
|
||||
elif sym == 'CONFIG_TCG' and tcg_arch.endswith('tcti')
|
||||
config_target += { 'CONFIG_TCG_THREADED_INTERPRETER': 'y' }
|
||||
elif sym == 'CONFIG_XEN' and have_xen_pci_passthrough
|
||||
config_target += { 'CONFIG_XEN_PCI_PASSTHROUGH': 'y' }
|
||||
endif
|
||||
@@ -1499,7 +1536,7 @@ slirp_opt = 'disabled'
|
||||
if have_system
|
||||
slirp_opt = get_option('slirp')
|
||||
if slirp_opt in ['enabled', 'auto', 'system']
|
||||
have_internal = fs.exists(meson.current_source_dir() / 'slirp/meson.build')
|
||||
have_internal = fs.exists(meson.current_source_dir() / 'subprojects/libslirp/meson.build')
|
||||
slirp = dependency('slirp', kwargs: static_kwargs,
|
||||
method: 'pkg-config',
|
||||
required: slirp_opt == 'system' or
|
||||
@@ -1513,64 +1550,9 @@ if have_system
|
||||
endif
|
||||
endif
|
||||
if slirp_opt == 'internal'
|
||||
slirp_deps = []
|
||||
if targetos == 'windows'
|
||||
slirp_deps = cc.find_library('iphlpapi')
|
||||
endif
|
||||
slirp_conf = configuration_data()
|
||||
slirp_conf.set('SLIRP_MAJOR_VERSION', meson.project_version().split('.')[0])
|
||||
slirp_conf.set('SLIRP_MINOR_VERSION', meson.project_version().split('.')[1])
|
||||
slirp_conf.set('SLIRP_MICRO_VERSION', meson.project_version().split('.')[2])
|
||||
slirp_conf.set_quoted('SLIRP_VERSION_STRING', meson.project_version())
|
||||
slirp_cargs = ['-DG_LOG_DOMAIN="Slirp"']
|
||||
slirp_files = [
|
||||
'slirp/src/arp_table.c',
|
||||
'slirp/src/bootp.c',
|
||||
'slirp/src/cksum.c',
|
||||
'slirp/src/dhcpv6.c',
|
||||
'slirp/src/dnssearch.c',
|
||||
'slirp/src/if.c',
|
||||
'slirp/src/ip6_icmp.c',
|
||||
'slirp/src/ip6_input.c',
|
||||
'slirp/src/ip6_output.c',
|
||||
'slirp/src/ip_icmp.c',
|
||||
'slirp/src/ip_input.c',
|
||||
'slirp/src/ip_output.c',
|
||||
'slirp/src/mbuf.c',
|
||||
'slirp/src/misc.c',
|
||||
'slirp/src/ncsi.c',
|
||||
'slirp/src/ndp_table.c',
|
||||
'slirp/src/sbuf.c',
|
||||
'slirp/src/slirp.c',
|
||||
'slirp/src/socket.c',
|
||||
'slirp/src/state.c',
|
||||
'slirp/src/stream.c',
|
||||
'slirp/src/tcp_input.c',
|
||||
'slirp/src/tcp_output.c',
|
||||
'slirp/src/tcp_subr.c',
|
||||
'slirp/src/tcp_timer.c',
|
||||
'slirp/src/tftp.c',
|
||||
'slirp/src/udp.c',
|
||||
'slirp/src/udp6.c',
|
||||
'slirp/src/util.c',
|
||||
'slirp/src/version.c',
|
||||
'slirp/src/vmstate.c',
|
||||
]
|
||||
|
||||
configure_file(
|
||||
input : 'slirp/src/libslirp-version.h.in',
|
||||
output : 'libslirp-version.h',
|
||||
configuration: slirp_conf)
|
||||
|
||||
slirp_inc = include_directories('slirp', 'slirp/src')
|
||||
libslirp = static_library('slirp',
|
||||
build_by_default: false,
|
||||
sources: slirp_files,
|
||||
c_args: slirp_cargs,
|
||||
include_directories: slirp_inc)
|
||||
slirp = declare_dependency(link_with: libslirp,
|
||||
dependencies: slirp_deps,
|
||||
include_directories: slirp_inc)
|
||||
libslirp = subproject('libslirp',
|
||||
default_options: ['default_library=static'])
|
||||
slirp = libslirp.get_variable('libslirp_dep')
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -1633,9 +1615,18 @@ if not fdt.found() and fdt_required.length() > 0
|
||||
error('fdt not available but required by targets ' + ', '.join(fdt_required))
|
||||
endif
|
||||
|
||||
ucontext = dependency('libucontext', kwargs: static_kwargs, required : false)
|
||||
if not ucontext.found() and get_option('ucontext').enabled()
|
||||
libucontext_proj = subproject('libucontext',
|
||||
default_options: ['default_library=static',
|
||||
'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 #
|
||||
@@ -1844,6 +1835,7 @@ if have_system or have_user
|
||||
'accel/tcg',
|
||||
'hw/core',
|
||||
'target/arm',
|
||||
'target/arm/hvf',
|
||||
'target/hppa',
|
||||
'target/i386',
|
||||
'target/i386/kvm',
|
||||
@@ -1883,7 +1875,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)
|
||||
|
||||
@@ -2212,14 +2204,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 = [{
|
||||
@@ -2253,6 +2262,17 @@ 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
|
||||
exe_name = exe['name']
|
||||
exe_sign = 'CONFIG_HVF' in config_target
|
||||
@@ -2264,11 +2284,10 @@ foreach target : target_dirs
|
||||
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 exe_sign
|
||||
emulators += {exe['name'] : custom_target(exe['name'],
|
||||
@@ -2435,6 +2454,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 submodules': config_host['GIT_SUBMODULES']}
|
||||
summary(summary_info, bool_yn: true, section: 'Directories')
|
||||
|
||||
@@ -2451,7 +2471,7 @@ summary_info += {'genisoimage': config_host['GENISOIMAGE']}
|
||||
if targetos == 'windows' and config_host.has_key('CONFIG_GUEST_AGENT')
|
||||
summary_info += {'wixl': wixl.found() ? wixl.full_path() : false}
|
||||
endif
|
||||
if slirp_opt != 'disabled'
|
||||
if slirp_opt != 'disabled' and 'CONFIG_SLIRP_SMBD' in config_host
|
||||
summary_info += {'smbd': config_host['CONFIG_SMBD_COMMAND']}
|
||||
endif
|
||||
summary(summary_info, bool_yn: true, section: 'Host binaries')
|
||||
@@ -2585,6 +2605,8 @@ summary_info += {'TCG support': config_all.has_key('CONFIG_TCG')}
|
||||
if config_all.has_key('CONFIG_TCG')
|
||||
if get_option('tcg_interpreter')
|
||||
summary_info += {'TCG backend': 'TCI (TCG with bytecode interpreter, experimental and slow)'}
|
||||
elif get_option('tcg_threaded_interpreter')
|
||||
summary_info += {'TCG backend': 'TCTI (TCG with threaded-dispatch bytecode interpreter, experimental and slow; but faster than TCI)'}
|
||||
else
|
||||
summary_info += {'TCG backend': 'native (@0@)'.format(cpu)}
|
||||
endif
|
||||
@@ -2599,6 +2621,7 @@ summary(summary_info, bool_yn: true, section: 'Targets and accelerators')
|
||||
|
||||
# Block layer
|
||||
summary_info = {}
|
||||
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'}
|
||||
if have_block
|
||||
|
||||
@@ -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('default_devices', type : 'boolean', value : true,
|
||||
description: 'Include a default selection of devices in emulators')
|
||||
@@ -41,6 +43,8 @@ option('tcg', type: 'feature', value: 'auto',
|
||||
description: 'TCG support')
|
||||
option('tcg_interpreter', type: 'boolean', value: false,
|
||||
description: 'TCG with bytecode interpreter (experimental and slow)')
|
||||
option('tcg_threaded_interpreter', type: 'boolean', value: false,
|
||||
description: 'TCG with threaded-dispatch bytecode interpreter (experimental and slow, but less slow than TCI)')
|
||||
option('cfi', type: 'boolean', value: 'false',
|
||||
description: 'Control-Flow Integrity (CFI)')
|
||||
option('cfi_debug', type: 'boolean', value: 'false',
|
||||
@@ -108,6 +112,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('vhost_user_blk_server', type: 'feature', value: 'auto',
|
||||
description: 'build vhost-user-blk server')
|
||||
|
||||
@@ -63,4 +63,9 @@ int net_init_vhost_user(const Netdev *netdev, const char *name,
|
||||
|
||||
int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
|
||||
NetClientState *peer, Error **errp);
|
||||
|
||||
#ifdef CONFIG_VMNET
|
||||
int net_init_vmnet_macos(const Netdev *netdev, const char *name,
|
||||
NetClientState *peer, Error **errp);
|
||||
#endif
|
||||
#endif /* QEMU_NET_CLIENTS_H */
|
||||
@@ -37,5 +37,6 @@ endif
|
||||
softmmu_ss.add(when: 'CONFIG_POSIX', if_true: files(tap_posix))
|
||||
softmmu_ss.add(when: 'CONFIG_WIN32', if_true: files('tap-win32.c'))
|
||||
softmmu_ss.add(when: 'CONFIG_VHOST_NET_VDPA', if_true: files('vhost-vdpa.c'))
|
||||
softmmu_ss.add(when: vmnet, if_true: files('vmnet-macos.c'))
|
||||
|
||||
subdir('can')
|
||||
@@ -1002,6 +1002,9 @@ static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
|
||||
#ifdef CONFIG_L2TPV3
|
||||
[NET_CLIENT_DRIVER_L2TPV3] = net_init_l2tpv3,
|
||||
#endif
|
||||
#ifdef CONFIG_VMNET
|
||||
[NET_CLIENT_DRIVER_VMNET_MACOS] = net_init_vmnet_macos,
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
+8
-8
@@ -27,7 +27,7 @@
|
||||
#include "net/slirp.h"
|
||||
|
||||
|
||||
#ifndef _WIN32
|
||||
#if defined(CONFIG_SLIRP_SMBD)
|
||||
#include <pwd.h>
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
@@ -91,7 +91,7 @@ typedef struct SlirpState {
|
||||
Slirp *slirp;
|
||||
Notifier poll_notifier;
|
||||
Notifier exit_notifier;
|
||||
#ifndef _WIN32
|
||||
#if defined(CONFIG_SLIRP_SMBD)
|
||||
gchar *smb_dir;
|
||||
#endif
|
||||
GSList *fwd;
|
||||
@@ -104,7 +104,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(CONFIG_SLIRP_SMBD)
|
||||
static int slirp_smb(SlirpState *s, const char *exported_dir,
|
||||
struct in_addr vserver_addr, Error **errp);
|
||||
static void slirp_smb_cleanup(SlirpState *s);
|
||||
@@ -377,7 +377,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(CONFIG_SLIRP_SMBD)
|
||||
struct in_addr smbsrv = { .s_addr = 0 };
|
||||
#endif
|
||||
NetClientState *nc;
|
||||
@@ -487,7 +487,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
#if defined(CONFIG_SLIRP_SMBD)
|
||||
if (vsmbserver && !inet_aton(vsmbserver, &smbsrv)) {
|
||||
error_setg(errp, "Failed to parse SMB address");
|
||||
return -1;
|
||||
@@ -602,7 +602,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifndef _WIN32
|
||||
#if defined(CONFIG_SLIRP_SMBD)
|
||||
if (smb_export) {
|
||||
if (slirp_smb(s, smb_export, smbsrv, errp) < 0) {
|
||||
goto error;
|
||||
@@ -794,7 +794,7 @@ void hmp_hostfwd_add(Monitor *mon, const QDict *qdict)
|
||||
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
#if defined(CONFIG_SLIRP_SMBD)
|
||||
|
||||
/* automatic user mode samba server configuration */
|
||||
static void slirp_smb_cleanup(SlirpState *s)
|
||||
@@ -909,7 +909,7 @@ static int slirp_smb(SlirpState* s, const char *exported_dir,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* !defined(_WIN32) */
|
||||
#endif /* defined(CONFIG_SLIRP_SMBD) */
|
||||
|
||||
static int guestfwd_can_read(void *opaque)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,446 @@
|
||||
/*
|
||||
* vmnet.framework backed netdev for macOS 10.15+ hosts
|
||||
*
|
||||
* Copyright (c) 2021 Phillip Tennen <phillip@axleos.com>
|
||||
*
|
||||
* 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/main-loop.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qapi/qapi-types-net.h"
|
||||
#include "net/net.h"
|
||||
/* macOS vmnet framework header */
|
||||
#include <vmnet/vmnet.h>
|
||||
|
||||
typedef struct vmnet_state {
|
||||
NetClientState nc;
|
||||
interface_ref vmnet_iface_ref;
|
||||
/* Switched on after vmnet informs us that the interface has started */
|
||||
bool link_up;
|
||||
/*
|
||||
* If qemu_send_packet_async returns 0, this is switched off until our
|
||||
* delivery callback is invoked
|
||||
*/
|
||||
bool qemu_ready_to_receive;
|
||||
} vmnet_state_t;
|
||||
|
||||
int net_init_vmnet_macos(const Netdev *netdev, const char *name,
|
||||
NetClientState *peer, Error **errp);
|
||||
|
||||
static const char *_vmnet_status_repr(vmnet_return_t status)
|
||||
{
|
||||
switch (status) {
|
||||
case VMNET_SUCCESS:
|
||||
return "success";
|
||||
case VMNET_FAILURE:
|
||||
return "generic failure";
|
||||
case VMNET_MEM_FAILURE:
|
||||
return "out of memory";
|
||||
case VMNET_INVALID_ARGUMENT:
|
||||
return "invalid argument";
|
||||
case VMNET_SETUP_INCOMPLETE:
|
||||
return "setup is incomplete";
|
||||
case VMNET_INVALID_ACCESS:
|
||||
return "insufficient permissions";
|
||||
case VMNET_PACKET_TOO_BIG:
|
||||
return "packet size exceeds MTU";
|
||||
case VMNET_BUFFER_EXHAUSTED:
|
||||
return "kernel buffers temporarily exhausted";
|
||||
case VMNET_TOO_MANY_PACKETS:
|
||||
return "number of packets exceeds system limit";
|
||||
/* This error code was introduced in macOS 11.0 */
|
||||
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 110000
|
||||
case VMNET_SHARING_SERVICE_BUSY:
|
||||
return "sharing service busy";
|
||||
#endif
|
||||
default:
|
||||
return "unknown status code";
|
||||
}
|
||||
}
|
||||
|
||||
static operating_modes_t _vmnet_operating_mode_enum_compat(
|
||||
VmnetOperatingMode mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case VMNET_OPERATING_MODE_HOST:
|
||||
return VMNET_HOST_MODE;
|
||||
case VMNET_OPERATING_MODE_SHARED:
|
||||
return VMNET_SHARED_MODE;
|
||||
case VMNET_OPERATING_MODE_BRIDGED:
|
||||
return VMNET_BRIDGED_MODE;
|
||||
default:
|
||||
/* Should never happen as the modes are parsed before we get here */
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
static bool vmnet_can_receive(NetClientState *nc)
|
||||
{
|
||||
vmnet_state_t *s = DO_UPCAST(vmnet_state_t, nc, nc);
|
||||
return s->link_up;
|
||||
}
|
||||
|
||||
static ssize_t vmnet_receive_iov(NetClientState *nc,
|
||||
const struct iovec *iovs,
|
||||
int iovcnt)
|
||||
{
|
||||
vmnet_state_t *s = DO_UPCAST(vmnet_state_t, nc, nc);
|
||||
|
||||
/* Combine the provided iovs into a single vmnet packet */
|
||||
struct vmpktdesc *packet = g_new0(struct vmpktdesc, 1);
|
||||
packet->vm_pkt_iov = g_new0(struct iovec, iovcnt);
|
||||
memcpy(packet->vm_pkt_iov, iovs, sizeof(struct iovec) * iovcnt);
|
||||
packet->vm_pkt_iovcnt = iovcnt;
|
||||
packet->vm_flags = 0;
|
||||
|
||||
/* Figure out the packet size by iterating the iov's */
|
||||
for (int i = 0; i < iovcnt; i++) {
|
||||
const struct iovec *iov = iovs + i;
|
||||
packet->vm_pkt_size += iov->iov_len;
|
||||
}
|
||||
|
||||
/* Finally, write the packet to the vmnet interface */
|
||||
int packet_count = 1;
|
||||
vmnet_return_t result = vmnet_write(s->vmnet_iface_ref, packet,
|
||||
&packet_count);
|
||||
if (result != VMNET_SUCCESS || packet_count != 1) {
|
||||
error_printf("Failed to send packet to host: %s\n",
|
||||
_vmnet_status_repr(result));
|
||||
}
|
||||
ssize_t wrote_bytes = packet->vm_pkt_size;
|
||||
g_free(packet->vm_pkt_iov);
|
||||
g_free(packet);
|
||||
return wrote_bytes;
|
||||
}
|
||||
|
||||
static void vmnet_send_completed(NetClientState *nc, ssize_t len)
|
||||
{
|
||||
vmnet_state_t *vmnet_client_state = DO_UPCAST(vmnet_state_t, nc, nc);
|
||||
/* Ready to receive more packets! */
|
||||
vmnet_client_state->qemu_ready_to_receive = true;
|
||||
}
|
||||
|
||||
static NetClientInfo net_vmnet_macos_info = {
|
||||
.type = NET_CLIENT_DRIVER_VMNET_MACOS,
|
||||
.size = sizeof(vmnet_state_t),
|
||||
.receive_iov = vmnet_receive_iov,
|
||||
.can_receive = vmnet_can_receive,
|
||||
};
|
||||
|
||||
static bool _validate_ifname_is_valid_bridge_target(const char *ifname)
|
||||
{
|
||||
/* Iterate available bridge interfaces, ensure the provided one is valid */
|
||||
xpc_object_t bridge_interfaces = vmnet_copy_shared_interface_list();
|
||||
bool failed_to_match_iface_name = xpc_array_apply(
|
||||
bridge_interfaces,
|
||||
^bool(size_t index, xpc_object_t _Nonnull value) {
|
||||
if (!strcmp(xpc_string_get_string_ptr(value), ifname)) {
|
||||
/* The interface name is valid! Stop iterating */
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (failed_to_match_iface_name) {
|
||||
error_printf("Invalid bridge interface name provided: %s\n", ifname);
|
||||
error_printf("Valid bridge interfaces:\n");
|
||||
xpc_array_apply(
|
||||
vmnet_copy_shared_interface_list(),
|
||||
^bool(size_t index, xpc_object_t _Nonnull value) {
|
||||
error_printf("\t%s\n", xpc_string_get_string_ptr(value));
|
||||
/* Keep iterating */
|
||||
return true;
|
||||
});
|
||||
exit(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static xpc_object_t _construct_vmnet_interface_description(
|
||||
const NetdevVmnetModeOptions *vmnet_opts)
|
||||
{
|
||||
operating_modes_t mode = _vmnet_operating_mode_enum_compat(
|
||||
vmnet_opts->mode);
|
||||
|
||||
/* Validate options */
|
||||
if (mode == VMNET_HOST_MODE || mode == VMNET_SHARED_MODE) {
|
||||
NetdevVmnetModeOptionsHostOrShared mode_opts = vmnet_opts->u.host;
|
||||
/* If one DHCP parameter is configured, all 3 are required */
|
||||
if (mode_opts.has_dhcp_start_address ||
|
||||
mode_opts.has_dhcp_end_address ||
|
||||
mode_opts.has_dhcp_subnet_mask) {
|
||||
if (!(mode_opts.has_dhcp_start_address &&
|
||||
mode_opts.has_dhcp_end_address &&
|
||||
mode_opts.has_dhcp_subnet_mask)) {
|
||||
error_printf("Incomplete DHCP configuration provided\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
} else if (mode == VMNET_BRIDGED_MODE) {
|
||||
/* Nothing to validate */
|
||||
} else {
|
||||
error_printf("Unknown vmnet mode %d\n", mode);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
xpc_object_t interface_desc = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_uint64(
|
||||
interface_desc,
|
||||
vmnet_operation_mode_key,
|
||||
mode
|
||||
);
|
||||
|
||||
if (mode == VMNET_BRIDGED_MODE) {
|
||||
/*
|
||||
* Configure the provided physical interface to act
|
||||
* as a bridge with QEMU
|
||||
*/
|
||||
NetdevVmnetModeOptionsBridged mode_opts = vmnet_opts->u.bridged;
|
||||
/* Bridge with en0 by default */
|
||||
const char *physical_ifname = mode_opts.has_ifname ? mode_opts.ifname :
|
||||
"en0";
|
||||
_validate_ifname_is_valid_bridge_target(physical_ifname);
|
||||
xpc_dictionary_set_string(interface_desc,
|
||||
vmnet_shared_interface_name_key,
|
||||
physical_ifname);
|
||||
} else if (mode == VMNET_HOST_MODE || mode == VMNET_SHARED_MODE) {
|
||||
/* Pass the DHCP configuration to vmnet, if the user provided one */
|
||||
NetdevVmnetModeOptionsHostOrShared mode_opts = vmnet_opts->u.host;
|
||||
if (mode_opts.has_dhcp_start_address) {
|
||||
/* All DHCP arguments are available, as per the checks above */
|
||||
xpc_dictionary_set_string(interface_desc,
|
||||
vmnet_start_address_key,
|
||||
mode_opts.dhcp_start_address);
|
||||
xpc_dictionary_set_string(interface_desc,
|
||||
vmnet_end_address_key,
|
||||
mode_opts.dhcp_end_address);
|
||||
xpc_dictionary_set_string(interface_desc,
|
||||
vmnet_subnet_mask_key,
|
||||
mode_opts.dhcp_subnet_mask);
|
||||
}
|
||||
}
|
||||
|
||||
return interface_desc;
|
||||
}
|
||||
|
||||
int net_init_vmnet_macos(const Netdev *netdev, const char *name,
|
||||
NetClientState *peer, Error **errp)
|
||||
{
|
||||
assert(netdev->type == NET_CLIENT_DRIVER_VMNET_MACOS);
|
||||
|
||||
NetdevVmnetModeOptions *vmnet_opts = netdev->u.vmnet_macos.options;
|
||||
xpc_object_t iface_desc = _construct_vmnet_interface_description(vmnet_opts);
|
||||
|
||||
NetClientState *nc = qemu_new_net_client(&net_vmnet_macos_info, peer,
|
||||
"vmnet", name);
|
||||
vmnet_state_t *vmnet_client_state = DO_UPCAST(vmnet_state_t, nc, nc);
|
||||
|
||||
dispatch_queue_t vmnet_dispatch_queue = dispatch_queue_create(
|
||||
"org.qemu.vmnet.iface_queue",
|
||||
DISPATCH_QUEUE_SERIAL
|
||||
);
|
||||
|
||||
__block vmnet_return_t vmnet_start_status = 0;
|
||||
__block uint64_t vmnet_iface_mtu = 0;
|
||||
__block uint64_t vmnet_max_packet_size = 0;
|
||||
__block const char *vmnet_mac_address = NULL;
|
||||
/*
|
||||
* We can't refer to an array type directly within a block,
|
||||
* so hold a pointer instead.
|
||||
*/
|
||||
uuid_string_t vmnet_iface_uuid = {0};
|
||||
__block uuid_string_t *vmnet_iface_uuid_ptr = &vmnet_iface_uuid;
|
||||
/* These are only provided in VMNET_HOST_MODE and VMNET_SHARED_MODE */
|
||||
bool vmnet_provides_dhcp_info = (
|
||||
vmnet_opts->mode == VMNET_OPERATING_MODE_HOST ||
|
||||
vmnet_opts->mode == VMNET_OPERATING_MODE_SHARED);
|
||||
__block const char *vmnet_subnet_mask = NULL;
|
||||
__block const char *vmnet_dhcp_range_start = NULL;
|
||||
__block const char *vmnet_dhcp_range_end = NULL;
|
||||
|
||||
/* Create the vmnet interface */
|
||||
dispatch_semaphore_t vmnet_iface_sem = dispatch_semaphore_create(0);
|
||||
interface_ref vmnet_iface_ref = vmnet_start_interface(
|
||||
iface_desc,
|
||||
vmnet_dispatch_queue,
|
||||
^(vmnet_return_t status, xpc_object_t _Nullable interface_param) {
|
||||
vmnet_start_status = status;
|
||||
if (vmnet_start_status != VMNET_SUCCESS || !interface_param) {
|
||||
/* Early return if the interface couldn't be started */
|
||||
dispatch_semaphore_signal(vmnet_iface_sem);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the configuration that vmnet provided us.
|
||||
* The provided dictionary is owned by XPC and may be freed
|
||||
* shortly after this block's execution.
|
||||
* So, copy data buffers now.
|
||||
*/
|
||||
vmnet_iface_mtu = xpc_dictionary_get_uint64(
|
||||
interface_param,
|
||||
vmnet_mtu_key
|
||||
);
|
||||
vmnet_max_packet_size = xpc_dictionary_get_uint64(
|
||||
interface_param,
|
||||
vmnet_max_packet_size_key
|
||||
);
|
||||
vmnet_mac_address = strdup(xpc_dictionary_get_string(
|
||||
interface_param,
|
||||
vmnet_mac_address_key
|
||||
));
|
||||
|
||||
const uint8_t *iface_uuid = xpc_dictionary_get_uuid(
|
||||
interface_param,
|
||||
vmnet_interface_id_key
|
||||
);
|
||||
uuid_unparse_upper(iface_uuid, *vmnet_iface_uuid_ptr);
|
||||
|
||||
/* If we're in a mode that provides DHCP info, read it out now */
|
||||
if (vmnet_provides_dhcp_info) {
|
||||
vmnet_dhcp_range_start = strdup(xpc_dictionary_get_string(
|
||||
interface_param,
|
||||
vmnet_start_address_key
|
||||
));
|
||||
vmnet_dhcp_range_end = strdup(xpc_dictionary_get_string(
|
||||
interface_param,
|
||||
vmnet_end_address_key
|
||||
));
|
||||
vmnet_subnet_mask = strdup(xpc_dictionary_get_string(
|
||||
interface_param,
|
||||
vmnet_subnet_mask_key
|
||||
));
|
||||
}
|
||||
dispatch_semaphore_signal(vmnet_iface_sem);
|
||||
});
|
||||
|
||||
/* And block until we receive a response from vmnet */
|
||||
dispatch_semaphore_wait(vmnet_iface_sem, DISPATCH_TIME_FOREVER);
|
||||
|
||||
/* Did we manage to start the interface? */
|
||||
if (vmnet_start_status != VMNET_SUCCESS || !vmnet_iface_ref) {
|
||||
error_printf("Failed to start interface: %s\n",
|
||||
_vmnet_status_repr(vmnet_start_status));
|
||||
if (vmnet_start_status == VMNET_FAILURE) {
|
||||
error_printf("Hint: vmnet requires running with root access\n");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
info_report("Started vmnet interface with configuration:");
|
||||
info_report("MTU: %llu", vmnet_iface_mtu);
|
||||
info_report("Max packet size: %llu", vmnet_max_packet_size);
|
||||
info_report("MAC: %s", vmnet_mac_address);
|
||||
if (vmnet_provides_dhcp_info) {
|
||||
info_report("DHCP IPv4 start: %s", vmnet_dhcp_range_start);
|
||||
info_report("DHCP IPv4 end: %s", vmnet_dhcp_range_end);
|
||||
info_report("IPv4 subnet mask: %s", vmnet_subnet_mask);
|
||||
}
|
||||
info_report("UUID: %s", vmnet_iface_uuid);
|
||||
|
||||
/* The interface is up! Set a block to run when packets are received */
|
||||
vmnet_client_state->vmnet_iface_ref = vmnet_iface_ref;
|
||||
vmnet_return_t event_cb_stat = vmnet_interface_set_event_callback(
|
||||
vmnet_iface_ref,
|
||||
VMNET_INTERFACE_PACKETS_AVAILABLE,
|
||||
vmnet_dispatch_queue,
|
||||
^(interface_event_t event_mask, xpc_object_t _Nonnull event) {
|
||||
if (event_mask != VMNET_INTERFACE_PACKETS_AVAILABLE) {
|
||||
error_printf("Unknown vmnet interface event 0x%08x\n", event_mask);
|
||||
return;
|
||||
}
|
||||
|
||||
/* If we're unable to handle more packets now, drop this packet */
|
||||
if (!vmnet_client_state->qemu_ready_to_receive) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO(Phillip Tennen <phillip@axleos.com>): There may be more than
|
||||
* one packet available.
|
||||
* As an optimization, we could read
|
||||
* vmnet_estimated_packets_available_key packets now.
|
||||
*/
|
||||
char *packet_buf = g_malloc0(vmnet_max_packet_size);
|
||||
struct iovec *iov = g_new0(struct iovec, 1);
|
||||
iov->iov_base = packet_buf;
|
||||
iov->iov_len = vmnet_max_packet_size;
|
||||
|
||||
int pktcnt = 1;
|
||||
struct vmpktdesc *v = g_new0(struct vmpktdesc, pktcnt);
|
||||
v->vm_pkt_size = vmnet_max_packet_size;
|
||||
v->vm_pkt_iov = iov;
|
||||
v->vm_pkt_iovcnt = 1;
|
||||
v->vm_flags = 0;
|
||||
|
||||
vmnet_return_t result = vmnet_read(vmnet_iface_ref, v, &pktcnt);
|
||||
if (result != VMNET_SUCCESS) {
|
||||
error_printf("Failed to read packet from host: %s\n",
|
||||
_vmnet_status_repr(result));
|
||||
}
|
||||
|
||||
/* Ensure we read exactly one packet */
|
||||
assert(pktcnt == 1);
|
||||
|
||||
/* Dispatch this block to a global queue instead of the main queue,
|
||||
* which is only created when the program has a Cocoa event loop.
|
||||
* If QEMU is started with -nographic, no Cocoa event loop will be
|
||||
* created and thus the main queue will be unavailable.
|
||||
*/
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,
|
||||
0),
|
||||
^{
|
||||
qemu_mutex_lock_iothread();
|
||||
|
||||
/*
|
||||
* Deliver the packet to the guest
|
||||
* If the delivery succeeded synchronously, this returns the length
|
||||
* of the sent packet.
|
||||
*/
|
||||
if (qemu_send_packet_async(nc, iov->iov_base,
|
||||
v->vm_pkt_size,
|
||||
vmnet_send_completed) == 0) {
|
||||
vmnet_client_state->qemu_ready_to_receive = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* It's safe to free the packet buffers.
|
||||
* Even if delivery needs to wait, qemu_net_queue_append copies
|
||||
* the packet buffer.
|
||||
*/
|
||||
g_free(v);
|
||||
g_free(iov);
|
||||
g_free(packet_buf);
|
||||
|
||||
qemu_mutex_unlock_iothread();
|
||||
});
|
||||
});
|
||||
|
||||
/* Did we manage to set an event callback? */
|
||||
if (event_cb_stat != VMNET_SUCCESS) {
|
||||
error_printf("Failed to set up a callback to receive packets: %s\n",
|
||||
_vmnet_status_repr(vmnet_start_status));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* We're now ready to receive packets */
|
||||
vmnet_client_state->qemu_ready_to_receive = true;
|
||||
vmnet_client_state->link_up = true;
|
||||
|
||||
/* Include DHCP info if we're in a relevant mode */
|
||||
if (vmnet_provides_dhcp_info) {
|
||||
snprintf(nc->info_str, sizeof(nc->info_str), "dhcp_start=%s,dhcp_end=%s,mask=%s",
|
||||
vmnet_dhcp_range_start,
|
||||
vmnet_dhcp_range_end,
|
||||
vmnet_subnet_mask);
|
||||
} else {
|
||||
snprintf(nc->info_str, sizeof(nc->info_str), "mac=%s", vmnet_mac_address);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -897,7 +897,8 @@
|
||||
'discriminator': 'driver',
|
||||
'data': {
|
||||
'file': 'BlockStatsSpecificFile',
|
||||
'host_device': 'BlockStatsSpecificFile',
|
||||
'host_device': { 'type': 'BlockStatsSpecificFile',
|
||||
'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' },
|
||||
'nvme': 'BlockStatsSpecificNvme' } }
|
||||
|
||||
##
|
||||
@@ -2814,7 +2815,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(HAVE_HOST_BLOCK_DEVICE)' },
|
||||
'http', 'https', 'iscsi',
|
||||
'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels',
|
||||
'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd',
|
||||
{ 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' },
|
||||
@@ -4017,7 +4020,8 @@
|
||||
'ftps': 'BlockdevOptionsCurlFtps',
|
||||
'gluster': 'BlockdevOptionsGluster',
|
||||
'host_cdrom': 'BlockdevOptionsFile',
|
||||
'host_device':'BlockdevOptionsFile',
|
||||
'host_device': { 'type': 'BlockdevOptionsFile',
|
||||
'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' },
|
||||
'http': 'BlockdevOptionsCurlHttp',
|
||||
'https': 'BlockdevOptionsCurlHttps',
|
||||
'iscsi': 'BlockdevOptionsIscsi',
|
||||
|
||||
+118
-2
@@ -450,6 +450,115 @@
|
||||
'*vhostdev': 'str',
|
||||
'*queues': 'int' } }
|
||||
|
||||
##
|
||||
# @VmnetOperatingMode:
|
||||
#
|
||||
# The operating modes in which a vmnet netdev can run
|
||||
# Only available on macOS
|
||||
#
|
||||
# @host: the guest may communicate with the host
|
||||
# and other guest network interfaces
|
||||
#
|
||||
# @shared: the guest may reach the Internet through a NAT,
|
||||
# and may communicate with the host and other guest
|
||||
# network interfaces
|
||||
#
|
||||
# @bridged: the guest's traffic is bridged with a
|
||||
# physical network interface of the host
|
||||
#
|
||||
# Since: 6.0
|
||||
##
|
||||
{ 'enum': 'VmnetOperatingMode',
|
||||
'data': [ 'host', 'shared', 'bridged' ],
|
||||
'if': 'defined(CONFIG_VMNET)' }
|
||||
|
||||
##
|
||||
# @NetdevVmnetModeOptionsBridged:
|
||||
#
|
||||
# Options for the vmnet-macos netdev
|
||||
# that are only available in 'bridged' mode
|
||||
# Only available on macOS
|
||||
#
|
||||
# @ifname: the physical network interface to bridge with
|
||||
# (defaults to en0 if not specified)
|
||||
#
|
||||
# Since: 6.0
|
||||
##
|
||||
{ 'struct': 'NetdevVmnetModeOptionsBridged',
|
||||
'data': { '*ifname': 'str' },
|
||||
'if': 'defined(CONFIG_VMNET)' }
|
||||
|
||||
##
|
||||
# @NetdevVmnetModeOptionsHostOrShared:
|
||||
#
|
||||
# Options for the vmnet-macos netdev
|
||||
# that are only available in 'host' or 'shared' mode
|
||||
# Only available on macOS
|
||||
#
|
||||
# @dhcp-start-address: the gateway address to use for the interface.
|
||||
# The range to dhcp_end_address is placed in the DHCP pool.
|
||||
# (only valid with mode=host|shared)
|
||||
# (must be specified with dhcp-end-address and
|
||||
# dhcp-subnet-mask)
|
||||
# (allocated automatically if unset)
|
||||
#
|
||||
# @dhcp-end-address: the DHCP IPv4 range end address to use for the interface.
|
||||
# (only valid with mode=host|shared)
|
||||
# (must be specified with dhcp-start-address and
|
||||
# dhcp-subnet-mask)
|
||||
# (allocated automatically if unset)
|
||||
#
|
||||
# @dhcp-subnet-mask: the IPv4 subnet mask (string) to use on the interface.
|
||||
# (only valid with mode=host|shared)
|
||||
# (must be specified with dhcp-start-address and
|
||||
# dhcp-end-address)
|
||||
# (allocated automatically if unset)
|
||||
#
|
||||
# Since: 6.0
|
||||
##
|
||||
{ 'struct': 'NetdevVmnetModeOptionsHostOrShared',
|
||||
'data': {
|
||||
'*dhcp-start-address': 'str' ,
|
||||
'*dhcp-end-address': 'str',
|
||||
'*dhcp-subnet-mask': 'str' },
|
||||
'if': 'defined(CONFIG_VMNET)' }
|
||||
|
||||
##
|
||||
# @NetdevVmnetModeOptions:
|
||||
#
|
||||
# Options specific to different operating modes of a vmnet netdev
|
||||
# Only available on macOS
|
||||
#
|
||||
# @mode: the operating mode vmnet should run in
|
||||
#
|
||||
# Since: 6.0
|
||||
##
|
||||
{ 'union': 'NetdevVmnetModeOptions',
|
||||
'base': { 'mode': 'VmnetOperatingMode' },
|
||||
'discriminator': 'mode',
|
||||
'data': {
|
||||
'bridged': 'NetdevVmnetModeOptionsBridged',
|
||||
'host': 'NetdevVmnetModeOptionsHostOrShared',
|
||||
'shared': 'NetdevVmnetModeOptionsHostOrShared' },
|
||||
'if': 'defined(CONFIG_VMNET)' }
|
||||
|
||||
##
|
||||
# @NetdevVmnetOptions:
|
||||
#
|
||||
# vmnet network backend
|
||||
# Only available on macOS
|
||||
#
|
||||
# @options: a structure specifying the mode and mode-specific options
|
||||
# (once QAPI supports a union type as a branch to another union type,
|
||||
# this structure can be changed to a union, and the contents of
|
||||
# NetdevVmnetModeOptions moved here)
|
||||
#
|
||||
# Since: 6.0
|
||||
##
|
||||
{ 'struct': 'NetdevVmnetOptions',
|
||||
'data': {'options': 'NetdevVmnetModeOptions' },
|
||||
'if': 'defined(CONFIG_VMNET)' }
|
||||
|
||||
##
|
||||
# @NetClientDriver:
|
||||
#
|
||||
@@ -458,10 +567,13 @@
|
||||
# Since: 2.7
|
||||
#
|
||||
# @vhost-vdpa since 5.1
|
||||
#
|
||||
# @vmnet-macos since 6.0 (only available on macOS)
|
||||
##
|
||||
{ 'enum': 'NetClientDriver',
|
||||
'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde',
|
||||
'bridge', 'hubport', 'netmap', 'vhost-user', 'vhost-vdpa' ] }
|
||||
'bridge', 'hubport', 'netmap', 'vhost-user', 'vhost-vdpa',
|
||||
{ 'name': 'vmnet-macos', 'if': 'defined(CONFIG_VMNET)' } ] }
|
||||
|
||||
##
|
||||
# @Netdev:
|
||||
@@ -475,6 +587,8 @@
|
||||
# Since: 1.2
|
||||
#
|
||||
# 'l2tpv3' - since 2.1
|
||||
#
|
||||
# 'vmnet-macos' since 6.0 (only available on macOS)
|
||||
##
|
||||
{ 'union': 'Netdev',
|
||||
'base': { 'id': 'str', 'type': 'NetClientDriver' },
|
||||
@@ -490,7 +604,9 @@
|
||||
'hubport': 'NetdevHubPortOptions',
|
||||
'netmap': 'NetdevNetmapOptions',
|
||||
'vhost-user': 'NetdevVhostUserOptions',
|
||||
'vhost-vdpa': 'NetdevVhostVDPAOptions' } }
|
||||
'vhost-vdpa': 'NetdevVhostVDPAOptions',
|
||||
'vmnet-macos': { 'type': 'NetdevVmnetOptions',
|
||||
'if': 'defined(CONFIG_VMNET)' } } }
|
||||
|
||||
##
|
||||
# @RxState:
|
||||
|
||||
@@ -2542,6 +2542,15 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
|
||||
#ifdef __linux__
|
||||
"-netdev vhost-vdpa,id=str,vhostdev=/path/to/dev\n"
|
||||
" configure a vhost-vdpa network,Establish a vhost-vdpa netdev\n"
|
||||
#endif
|
||||
#ifdef CONFIG_VMNET
|
||||
"-netdev vmnet-macos,id=str,mode=bridged[,ifname=ifname]\n"
|
||||
" configure a macOS-provided vmnet network in \"physical interface bridge\" mode\n"
|
||||
" the physical interface to bridge with defaults to en0 if unspecified\n"
|
||||
"-netdev vmnet-macos,id=str,mode=host|shared\n"
|
||||
" [,dhcp_start_address=addr,dhcp_end_address=addr,dhcp_subnet_mask=mask]\n"
|
||||
" configure a macOS-provided vmnet network in \"host\" or \"shared\" mode\n"
|
||||
" the DHCP configuration will be set automatically if unspecified\n"
|
||||
#endif
|
||||
"-netdev hubport,id=str,hubid=n[,netdev=nd]\n"
|
||||
" configure a hub port on the hub with ID 'n'\n", QEMU_ARCH_ALL)
|
||||
|
||||
+12
-12
@@ -75,18 +75,18 @@ def process_tests(test, targets, suites):
|
||||
print('run-test-%d: $(.test.deps.%d)' % (i,i))
|
||||
print('\t@$(call .test.run,%d,$(.test.output-format))' % (i,))
|
||||
|
||||
test_suites = test['suite'] or ['default']
|
||||
is_slow = any(s.endswith('-slow') for s in test_suites)
|
||||
for s in test_suites:
|
||||
# The suite name in the introspection info is "PROJECT:SUITE"
|
||||
s = s.split(':')[1]
|
||||
if s.endswith('-slow'):
|
||||
s = s[:-5]
|
||||
if is_slow:
|
||||
suites[s].slow_tests.append(i)
|
||||
else:
|
||||
suites[s].tests.append(i)
|
||||
suites[s].executables.add(executable)
|
||||
#test_suites = test['suite'] or ['default']
|
||||
#is_slow = any(s.endswith('-slow') for s in test_suites)
|
||||
#for s in test_suites:
|
||||
# # The suite name in the introspection info is "PROJECT:SUITE"
|
||||
# s = s.split(':')[1]
|
||||
# if s.endswith('-slow'):
|
||||
# s = s[:-5]
|
||||
# if is_slow:
|
||||
# suites[s].slow_tests.append(i)
|
||||
# else:
|
||||
# suites[s].tests.append(i)
|
||||
# suites[s].executables.add(executable)
|
||||
|
||||
def emit_prolog(suites, prefix):
|
||||
all_tap = ' '.join(('%s-report-%s.tap' % (prefix, k) for k in suites.keys()))
|
||||
|
||||
-1
Submodule slirp deleted from 8f43a99191.
Submodule
+1
Submodule subprojects/libslirp added at bacb71f1c3.
Submodule
+1
Submodule subprojects/libucontext added at 9b1d8f01a6.
+9
-4
@@ -40,6 +40,7 @@
|
||||
#include "sysemu/tcg.h"
|
||||
#include "sysemu/hw_accel.h"
|
||||
#include "kvm_arm.h"
|
||||
#include "hvf_arm.h"
|
||||
#include "disas/capstone.h"
|
||||
#include "fpu/softfloat.h"
|
||||
|
||||
@@ -1079,8 +1080,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 */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1999,15 +2000,19 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
|
||||
#endif /* CONFIG_TCG */
|
||||
}
|
||||
|
||||
#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);
|
||||
if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
|
||||
aarch64_add_sve_properties(obj);
|
||||
}
|
||||
#else
|
||||
hvf_arm_set_cpu_features_from_host(cpu);
|
||||
#endif
|
||||
arm_cpu_post_init(obj);
|
||||
}
|
||||
|
||||
@@ -2067,7 +2072,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
|
||||
}
|
||||
|
||||
@@ -2972,6 +2972,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,962 @@
|
||||
/*
|
||||
* 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 "hvf_arm.h"
|
||||
|
||||
#include <mach/mach_time.h>
|
||||
|
||||
#include "exec/address-spaces.h"
|
||||
#include "hw/irq.h"
|
||||
#include "qemu/main-loop.h"
|
||||
#include "sysemu/cpus.h"
|
||||
#include "arm-powerctl.h"
|
||||
#include "target/arm/cpu.h"
|
||||
#include "target/arm/internals.h"
|
||||
#include "trace/trace-target_arm_hvf.h"
|
||||
|
||||
#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, crn, crm, op2) \
|
||||
((op0 << 20) | (op2 << 17) | (op1 << 14) | (crn << 10) | (crm << 1))
|
||||
#define SYSREG_MASK SYSREG(0x3, 0x7, 0xf, 0xf, 0x7)
|
||||
#define SYSREG_CNTPCT_EL0 SYSREG(3, 3, 14, 0, 1)
|
||||
#define SYSREG_PMCCNTR_EL0 SYSREG(3, 3, 9, 13, 0)
|
||||
|
||||
#define WFX_IS_WFE (1 << 0)
|
||||
|
||||
#define TMR_CTL_ENABLE (1 << 0)
|
||||
#define TMR_CTL_IMASK (1 << 1)
|
||||
#define TMR_CTL_ISTATUS (1 << 2)
|
||||
|
||||
static void hvf_wfi(CPUState *cpu);
|
||||
|
||||
typedef struct ARMHostCPUFeatures {
|
||||
ARMISARegisters isar;
|
||||
uint64_t features;
|
||||
uint64_t midr;
|
||||
uint32_t reset_sctlr;
|
||||
const char *dtb_compatible;
|
||||
} ARMHostCPUFeatures;
|
||||
|
||||
static ARMHostCPUFeatures arm_host_cpu_features;
|
||||
|
||||
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) },
|
||||
};
|
||||
|
||||
static const struct hvf_reg_match hvf_fpreg_match[] = {
|
||||
{ HV_SIMD_FP_REG_Q0, offsetof(CPUARMState, vfp.zregs[0]) },
|
||||
{ HV_SIMD_FP_REG_Q1, offsetof(CPUARMState, vfp.zregs[1]) },
|
||||
{ HV_SIMD_FP_REG_Q2, offsetof(CPUARMState, vfp.zregs[2]) },
|
||||
{ HV_SIMD_FP_REG_Q3, offsetof(CPUARMState, vfp.zregs[3]) },
|
||||
{ HV_SIMD_FP_REG_Q4, offsetof(CPUARMState, vfp.zregs[4]) },
|
||||
{ HV_SIMD_FP_REG_Q5, offsetof(CPUARMState, vfp.zregs[5]) },
|
||||
{ HV_SIMD_FP_REG_Q6, offsetof(CPUARMState, vfp.zregs[6]) },
|
||||
{ HV_SIMD_FP_REG_Q7, offsetof(CPUARMState, vfp.zregs[7]) },
|
||||
{ HV_SIMD_FP_REG_Q8, offsetof(CPUARMState, vfp.zregs[8]) },
|
||||
{ HV_SIMD_FP_REG_Q9, offsetof(CPUARMState, vfp.zregs[9]) },
|
||||
{ HV_SIMD_FP_REG_Q10, offsetof(CPUARMState, vfp.zregs[10]) },
|
||||
{ HV_SIMD_FP_REG_Q11, offsetof(CPUARMState, vfp.zregs[11]) },
|
||||
{ HV_SIMD_FP_REG_Q12, offsetof(CPUARMState, vfp.zregs[12]) },
|
||||
{ HV_SIMD_FP_REG_Q13, offsetof(CPUARMState, vfp.zregs[13]) },
|
||||
{ HV_SIMD_FP_REG_Q14, offsetof(CPUARMState, vfp.zregs[14]) },
|
||||
{ HV_SIMD_FP_REG_Q15, offsetof(CPUARMState, vfp.zregs[15]) },
|
||||
{ HV_SIMD_FP_REG_Q16, offsetof(CPUARMState, vfp.zregs[16]) },
|
||||
{ HV_SIMD_FP_REG_Q17, offsetof(CPUARMState, vfp.zregs[17]) },
|
||||
{ HV_SIMD_FP_REG_Q18, offsetof(CPUARMState, vfp.zregs[18]) },
|
||||
{ HV_SIMD_FP_REG_Q19, offsetof(CPUARMState, vfp.zregs[19]) },
|
||||
{ HV_SIMD_FP_REG_Q20, offsetof(CPUARMState, vfp.zregs[20]) },
|
||||
{ HV_SIMD_FP_REG_Q21, offsetof(CPUARMState, vfp.zregs[21]) },
|
||||
{ HV_SIMD_FP_REG_Q22, offsetof(CPUARMState, vfp.zregs[22]) },
|
||||
{ HV_SIMD_FP_REG_Q23, offsetof(CPUARMState, vfp.zregs[23]) },
|
||||
{ HV_SIMD_FP_REG_Q24, offsetof(CPUARMState, vfp.zregs[24]) },
|
||||
{ HV_SIMD_FP_REG_Q25, offsetof(CPUARMState, vfp.zregs[25]) },
|
||||
{ HV_SIMD_FP_REG_Q26, offsetof(CPUARMState, vfp.zregs[26]) },
|
||||
{ HV_SIMD_FP_REG_Q27, offsetof(CPUARMState, vfp.zregs[27]) },
|
||||
{ HV_SIMD_FP_REG_Q28, offsetof(CPUARMState, vfp.zregs[28]) },
|
||||
{ HV_SIMD_FP_REG_Q29, offsetof(CPUARMState, vfp.zregs[29]) },
|
||||
{ HV_SIMD_FP_REG_Q30, offsetof(CPUARMState, vfp.zregs[30]) },
|
||||
{ HV_SIMD_FP_REG_Q31, offsetof(CPUARMState, vfp.zregs[31]) },
|
||||
};
|
||||
|
||||
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;
|
||||
hv_simd_fp_uchar16_t fpval;
|
||||
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);
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(hvf_fpreg_match); i++) {
|
||||
ret = hv_vcpu_get_simd_fp_reg(cpu->hvf->fd, hvf_fpreg_match[i].reg,
|
||||
&fpval);
|
||||
memcpy((void *)env + hvf_fpreg_match[i].offset, &fpval, sizeof(fpval));
|
||||
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;
|
||||
hv_simd_fp_uchar16_t fpval;
|
||||
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);
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(hvf_fpreg_match); i++) {
|
||||
memcpy(&fpval, (void *)env + hvf_fpreg_match[i].offset, sizeof(fpval));
|
||||
ret = hv_vcpu_set_simd_fp_reg(cpu->hvf->fd, hvf_fpreg_match[i].reg,
|
||||
fpval);
|
||||
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;
|
||||
}
|
||||
|
||||
static void hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
|
||||
{
|
||||
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;
|
||||
|
||||
ahcf->dtb_compatible = "arm,arm-v8";
|
||||
ahcf->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, &ahcf->midr));
|
||||
assert_hvf_ok(hv_vcpu_destroy(fd));
|
||||
|
||||
ahcf->isar = host_isar;
|
||||
ahcf->reset_sctlr = 0x00c50078;
|
||||
|
||||
/* Make sure we don't advertise AArch32 support for EL0/EL1 */
|
||||
g_assert((host_isar.id_aa64pfr0 & 0xff) == 0x11);
|
||||
}
|
||||
|
||||
void hvf_arm_set_cpu_features_from_host(ARMCPU *cpu)
|
||||
{
|
||||
if (!arm_host_cpu_features.dtb_compatible) {
|
||||
if (!hvf_enabled()) {
|
||||
cpu->host_cpu_probe_failed = true;
|
||||
return;
|
||||
}
|
||||
hvf_arm_get_host_cpu_features(&arm_host_cpu_features);
|
||||
}
|
||||
|
||||
cpu->dtb_compatible = arm_host_cpu_features.dtb_compatible;
|
||||
cpu->isar = arm_host_cpu_features.isar;
|
||||
cpu->env.features = arm_host_cpu_features.features;
|
||||
cpu->midr = arm_host_cpu_features.midr;
|
||||
cpu->reset_sctlr = arm_host_cpu_features.reset_sctlr;
|
||||
}
|
||||
|
||||
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 void hvf_raise_exception(CPUARMState *env, uint32_t excp,
|
||||
uint32_t syndrome)
|
||||
{
|
||||
unsigned int new_el = 1;
|
||||
unsigned int old_mode = pstate_read(env);
|
||||
unsigned int new_mode = aarch64_pstate_mode(new_el, true);
|
||||
target_ulong addr = env->cp15.vbar_el[new_el];
|
||||
|
||||
env->cp15.esr_el[new_el] = syndrome;
|
||||
aarch64_save_sp(env, arm_current_el(env));
|
||||
env->elr_el[new_el] = env->pc;
|
||||
env->banked_spsr[aarch64_banked_spsr_index(new_el)] = old_mode;
|
||||
pstate_write(env, PSTATE_DAIF | new_mode);
|
||||
aarch64_restore_sp(env, new_el);
|
||||
env->pc = addr;
|
||||
}
|
||||
|
||||
static int hvf_psci_cpu_off(ARMCPU *arm_cpu)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
ret = arm_set_cpu_off(arm_cpu->mp_affinity);
|
||||
assert(ret == QEMU_ARM_POWERCTL_RET_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hvf_handle_psci_call(CPUState *cpu)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
CPUARMState *env = &arm_cpu->env;
|
||||
uint64_t param[4] = {
|
||||
env->xregs[0],
|
||||
env->xregs[1],
|
||||
env->xregs[2],
|
||||
env->xregs[3]
|
||||
};
|
||||
uint64_t context_id, mpidr;
|
||||
bool target_aarch64 = true;
|
||||
CPUState *target_cpu_state;
|
||||
ARMCPU *target_cpu;
|
||||
target_ulong entry;
|
||||
int target_el = 1;
|
||||
int32_t ret = 0;
|
||||
|
||||
trace_hvf_psci_call(param[0], param[1], param[2], param[3],
|
||||
arm_cpu->mp_affinity);
|
||||
|
||||
switch (param[0]) {
|
||||
case QEMU_PSCI_0_2_FN_PSCI_VERSION:
|
||||
ret = QEMU_PSCI_0_2_RET_VERSION_0_2;
|
||||
break;
|
||||
case QEMU_PSCI_0_2_FN_MIGRATE_INFO_TYPE:
|
||||
ret = QEMU_PSCI_0_2_RET_TOS_MIGRATION_NOT_REQUIRED; /* No trusted OS */
|
||||
break;
|
||||
case QEMU_PSCI_0_2_FN_AFFINITY_INFO:
|
||||
case QEMU_PSCI_0_2_FN64_AFFINITY_INFO:
|
||||
mpidr = param[1];
|
||||
|
||||
switch (param[2]) {
|
||||
case 0:
|
||||
target_cpu_state = arm_get_cpu_by_id(mpidr);
|
||||
if (!target_cpu_state) {
|
||||
ret = QEMU_PSCI_RET_INVALID_PARAMS;
|
||||
break;
|
||||
}
|
||||
target_cpu = ARM_CPU(target_cpu_state);
|
||||
|
||||
ret = target_cpu->power_state;
|
||||
break;
|
||||
default:
|
||||
/* Everything above affinity level 0 is always on. */
|
||||
ret = 0;
|
||||
}
|
||||
break;
|
||||
case QEMU_PSCI_0_2_FN_SYSTEM_RESET:
|
||||
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
||||
/* QEMU reset and shutdown are async requests, but PSCI
|
||||
* mandates that we never return from the reset/shutdown
|
||||
* call, so power the CPU off now so it doesn't execute
|
||||
* anything further.
|
||||
*/
|
||||
return hvf_psci_cpu_off(arm_cpu);
|
||||
case QEMU_PSCI_0_2_FN_SYSTEM_OFF:
|
||||
qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
|
||||
return hvf_psci_cpu_off(arm_cpu);
|
||||
case QEMU_PSCI_0_1_FN_CPU_ON:
|
||||
case QEMU_PSCI_0_2_FN_CPU_ON:
|
||||
case QEMU_PSCI_0_2_FN64_CPU_ON:
|
||||
mpidr = param[1];
|
||||
entry = param[2];
|
||||
context_id = param[3];
|
||||
ret = arm_set_cpu_on(mpidr, entry, context_id,
|
||||
target_el, target_aarch64);
|
||||
break;
|
||||
case QEMU_PSCI_0_1_FN_CPU_OFF:
|
||||
case QEMU_PSCI_0_2_FN_CPU_OFF:
|
||||
return hvf_psci_cpu_off(arm_cpu);
|
||||
case QEMU_PSCI_0_1_FN_CPU_SUSPEND:
|
||||
case QEMU_PSCI_0_2_FN_CPU_SUSPEND:
|
||||
case QEMU_PSCI_0_2_FN64_CPU_SUSPEND:
|
||||
/* Affinity levels are not supported in QEMU */
|
||||
if (param[1] & 0xfffe0000) {
|
||||
ret = QEMU_PSCI_RET_INVALID_PARAMS;
|
||||
break;
|
||||
}
|
||||
/* Powerdown is not supported, we always go into WFI */
|
||||
env->xregs[0] = 0;
|
||||
hvf_wfi(cpu);
|
||||
break;
|
||||
case QEMU_PSCI_0_1_FN_MIGRATE:
|
||||
case QEMU_PSCI_0_2_FN_MIGRATE:
|
||||
ret = QEMU_PSCI_RET_NOT_SUPPORTED;
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
||||
env->xregs[0] = ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
default:
|
||||
trace_hvf_unhandled_sysreg_read(reg,
|
||||
(reg >> 20) & 0x3,
|
||||
(reg >> 14) & 0x7,
|
||||
(reg >> 10) & 0xf,
|
||||
(reg >> 1) & 0xf,
|
||||
(reg >> 17) & 0x7);
|
||||
break;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static void hvf_sysreg_write(CPUState *cpu, uint32_t reg, uint64_t val)
|
||||
{
|
||||
switch (reg) {
|
||||
case SYSREG_CNTPCT_EL0:
|
||||
break;
|
||||
default:
|
||||
trace_hvf_unhandled_sysreg_write(reg,
|
||||
(reg >> 20) & 0x3,
|
||||
(reg >> 14) & 0x7,
|
||||
(reg >> 10) & 0xf,
|
||||
(reg >> 1) & 0xf,
|
||||
(reg >> 17) & 0x7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int hvf_inject_interrupts(CPUState *cpu)
|
||||
{
|
||||
if (cpu->interrupt_request & CPU_INTERRUPT_FIQ) {
|
||||
trace_hvf_inject_fiq();
|
||||
hv_vcpu_set_pending_interrupt(cpu->hvf->fd, HV_INTERRUPT_TYPE_FIQ,
|
||||
true);
|
||||
}
|
||||
|
||||
if (cpu->interrupt_request & CPU_INTERRUPT_HARD) {
|
||||
trace_hvf_inject_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();
|
||||
}
|
||||
|
||||
static void hvf_wfi(CPUState *cpu)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
hv_return_t r;
|
||||
uint64_t ctl;
|
||||
|
||||
if (cpu->interrupt_request & (CPU_INTERRUPT_HARD | CPU_INTERRUPT_FIQ)) {
|
||||
/* Interrupt pending, no need to wait */
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
||||
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 the time a context switch would take,
|
||||
* so that we can satisfy fast timer requests on the same CPU.
|
||||
* Measurements on M1 show the sweet spot to be ~2ms.
|
||||
*/
|
||||
if (!seconds && nanos < 2000000) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct timespec ts = { seconds, nanos };
|
||||
hvf_wait_for_ipi(cpu, &ts);
|
||||
}
|
||||
|
||||
static void hvf_sync_vtimer(CPUState *cpu)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
hv_return_t r;
|
||||
uint64_t ctl;
|
||||
bool irq_state;
|
||||
|
||||
if (!cpu->hvf->vtimer_masked) {
|
||||
/* We will get notified on vtimer changes by hvf, nothing to do */
|
||||
return;
|
||||
}
|
||||
|
||||
r = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_CNTV_CTL_EL0, &ctl);
|
||||
assert_hvf_ok(r);
|
||||
|
||||
irq_state = (ctl & (TMR_CTL_ENABLE | TMR_CTL_IMASK | TMR_CTL_ISTATUS)) ==
|
||||
(TMR_CTL_ENABLE | TMR_CTL_ISTATUS);
|
||||
qemu_set_irq(arm_cpu->gt_timer_outputs[GTIMER_VIRT], irq_state);
|
||||
|
||||
if (!irq_state) {
|
||||
/* Timer no longer asserting, we can unmask it */
|
||||
hv_vcpu_set_vtimer_mask(cpu->hvf->fd, false);
|
||||
cpu->hvf->vtimer_masked = false;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
bool advance_pc = false;
|
||||
|
||||
flush_cpu_state(cpu);
|
||||
|
||||
hvf_sync_vtimer(cpu);
|
||||
|
||||
if (hvf_inject_interrupts(cpu)) {
|
||||
return EXCP_INTERRUPT;
|
||||
}
|
||||
|
||||
if (cpu->halted) {
|
||||
/* On unhalt, we usually have CPU state changes. Prepare for them. */
|
||||
cpu_synchronize_state(cpu);
|
||||
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);
|
||||
cpu->hvf->vtimer_masked = true;
|
||||
return 0;
|
||||
case HV_EXIT_REASON_CANCELED:
|
||||
/* we got kicked, no exit to process */
|
||||
return 0;
|
||||
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;
|
||||
|
||||
trace_hvf_data_abort(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);
|
||||
} 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;
|
||||
|
||||
if (isread) {
|
||||
val = hvf_sysreg_read(cpu, reg);
|
||||
trace_hvf_sysreg_read(reg,
|
||||
(reg >> 20) & 0x3,
|
||||
(reg >> 14) & 0x7,
|
||||
(reg >> 10) & 0xf,
|
||||
(reg >> 1) & 0xf,
|
||||
(reg >> 17) & 0x7,
|
||||
val);
|
||||
hvf_set_reg(cpu, rt, val);
|
||||
} else {
|
||||
val = hvf_get_reg(cpu, rt);
|
||||
trace_hvf_sysreg_write(reg,
|
||||
(reg >> 20) & 0x3,
|
||||
(reg >> 14) & 0x7,
|
||||
(reg >> 10) & 0xf,
|
||||
(reg >> 1) & 0xf,
|
||||
(reg >> 17) & 0x7,
|
||||
val);
|
||||
hvf_sysreg_write(cpu, reg, val);
|
||||
}
|
||||
|
||||
advance_pc = true;
|
||||
break;
|
||||
}
|
||||
case EC_WFX_TRAP:
|
||||
advance_pc = true;
|
||||
if (!(syndrome & WFX_IS_WFE)) {
|
||||
hvf_wfi(cpu);
|
||||
}
|
||||
break;
|
||||
case EC_AA64_HVC:
|
||||
cpu_synchronize_state(cpu);
|
||||
if (hvf_handle_psci_call(cpu)) {
|
||||
trace_hvf_unknown_hvf(env->xregs[0]);
|
||||
hvf_raise_exception(env, EXCP_UDEF, syn_uncategorized());
|
||||
}
|
||||
break;
|
||||
case EC_AA64_SMC:
|
||||
cpu_synchronize_state(cpu);
|
||||
if (!hvf_handle_psci_call(cpu)) {
|
||||
advance_pc = true;
|
||||
} else if (env->xregs[0] == QEMU_SMCCC_TC_WINDOWS10_BOOT) {
|
||||
/* This special SMC is called by Windows 10 on boot. Return error */
|
||||
env->xregs[0] = -1;
|
||||
advance_pc = true;
|
||||
} else {
|
||||
trace_hvf_unknown_smc(env->xregs[0]);
|
||||
hvf_raise_exception(env, EXCP_UDEF, syn_uncategorized());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
cpu_synchronize_state(cpu);
|
||||
trace_hvf_exit(syndrome, ec, env->pc);
|
||||
error_report("0x%llx: unhandled exit 0x%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);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
arm_softmmu_ss.add(when: [hvf, 'CONFIG_HVF'], if_true: files(
|
||||
'hvf.c',
|
||||
))
|
||||
@@ -0,0 +1,11 @@
|
||||
hvf_unhandled_sysreg_read(uint32_t reg, uint32_t op0, uint32_t op1, uint32_t crn, uint32_t crm, uint32_t op2) "unhandled sysreg read 0x%08x (op0=%d op1=%d crn=%d crm=%d op2=%d)"
|
||||
hvf_unhandled_sysreg_write(uint32_t reg, uint32_t op0, uint32_t op1, uint32_t crn, uint32_t crm, uint32_t op2) "unhandled sysreg write 0x%08x (op0=%d op1=%d crn=%d crm=%d op2=%d)"
|
||||
hvf_inject_fiq(void) "injecting FIQ"
|
||||
hvf_inject_irq(void) "injecting IRQ"
|
||||
hvf_data_abort(uint64_t pc, uint64_t va, uint64_t pa, bool isv, bool iswrite, bool s1ptw, uint32_t len, uint32_t srt) "data abort: [pc=0x%"PRIx64" va=0x%016"PRIx64" pa=0x%016"PRIx64" isv=%d iswrite=%d s1ptw=%d len=%d srt=%d]"
|
||||
hvf_sysreg_read(uint32_t reg, uint32_t op0, uint32_t op1, uint32_t crn, uint32_t crm, uint32_t op2, uint64_t val) "sysreg read 0x%08x (op0=%d op1=%d crn=%d crm=%d op2=%d) = 0x%016"PRIx64
|
||||
hvf_sysreg_write(uint32_t reg, uint32_t op0, uint32_t op1, uint32_t crn, uint32_t crm, uint32_t op2, uint64_t val) "sysreg write 0x%08x (op0=%d op1=%d crn=%d crm=%d op2=%d, val=0x%016"PRIx64")"
|
||||
hvf_unknown_hvf(uint64_t x0) "unknown HVC! 0x%016"PRIx64
|
||||
hvf_unknown_smc(uint64_t x0) "unknown SMC! 0x%016"PRIx64
|
||||
hvf_exit(uint64_t syndrome, uint32_t ec, uint64_t pc) "exit: 0x%"PRIx64" [ec=0x%x pc=0x%"PRIx64"]"
|
||||
hvf_psci_call(uint64_t x0, uint64_t x1, uint64_t x2, uint64_t x3, uint32_t cpuid) "PSCI Call x0=0x%016"PRIx64" x1=0x%016"PRIx64" x2=0x%016"PRIx64" x3=0x%016"PRIx64" cpu=0x%x"
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* QEMU Hypervisor.framework (HVF) support -- ARM specifics
|
||||
*
|
||||
* Copyright (c) 2021 Alexander Graf
|
||||
*
|
||||
* 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_HVF_ARM_H
|
||||
#define QEMU_HVF_ARM_H
|
||||
|
||||
#include "qemu/accel.h"
|
||||
#include "cpu.h"
|
||||
|
||||
void hvf_arm_set_cpu_features_from_host(struct ARMCPU *cpu);
|
||||
|
||||
#endif
|
||||
@@ -85,6 +85,8 @@ MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_CPU_SUSPEND, PSCI_0_2_FN64_CPU_SUSPEND);
|
||||
MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_CPU_ON, PSCI_0_2_FN64_CPU_ON);
|
||||
MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_MIGRATE, PSCI_0_2_FN64_MIGRATE);
|
||||
|
||||
#define QEMU_SMCCC_TC_WINDOWS10_BOOT 0xc3000001
|
||||
|
||||
/* PSCI v0.2 return values used by TCG emulation of PSCI */
|
||||
|
||||
/* No Trusted OS migration to worry about when offlining CPUs */
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -54,5 +54,7 @@ arm_softmmu_ss.add(files(
|
||||
'psci.c',
|
||||
))
|
||||
|
||||
subdir('hvf')
|
||||
|
||||
target_arch += {'arm': arm_ss}
|
||||
target_softmmu_arch += {'arm': arm_softmmu_ss}
|
||||
@@ -69,6 +69,7 @@ bool arm_is_psci_call(ARMCPU *cpu, int excp_type)
|
||||
case QEMU_PSCI_0_2_FN64_CPU_SUSPEND:
|
||||
case QEMU_PSCI_0_1_FN_MIGRATE:
|
||||
case QEMU_PSCI_0_2_FN_MIGRATE:
|
||||
case QEMU_SMCCC_TC_WINDOWS10_BOOT:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -194,6 +195,7 @@ void arm_handle_psci_call(ARMCPU *cpu)
|
||||
break;
|
||||
case QEMU_PSCI_0_1_FN_MIGRATE:
|
||||
case QEMU_PSCI_0_2_FN_MIGRATE:
|
||||
case QEMU_SMCCC_TC_WINDOWS10_BOOT:
|
||||
ret = QEMU_PSCI_RET_NOT_SUPPORTED;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -1,146 +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-accel-ops.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);
|
||||
}
|
||||
|
||||
static void hvf_accel_ops_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
|
||||
|
||||
ops->create_vcpu_thread = hvf_start_vcpu_thread;
|
||||
|
||||
ops->synchronize_post_reset = hvf_cpu_synchronize_post_reset;
|
||||
ops->synchronize_post_init = hvf_cpu_synchronize_post_init;
|
||||
ops->synchronize_state = hvf_cpu_synchronize_state;
|
||||
ops->synchronize_pre_loadvm = hvf_cpu_synchronize_pre_loadvm;
|
||||
};
|
||||
static const TypeInfo hvf_accel_ops_type = {
|
||||
.name = ACCEL_OPS_NAME("hvf"),
|
||||
|
||||
.parent = TYPE_ACCEL_OPS,
|
||||
.class_init = hvf_accel_ops_class_init,
|
||||
.abstract = true,
|
||||
};
|
||||
static void hvf_accel_ops_register_types(void)
|
||||
{
|
||||
type_register_static(&hvf_accel_ops_type);
|
||||
}
|
||||
type_init(hvf_accel_ops_register_types);
|
||||
@@ -1,23 +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"
|
||||
|
||||
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,42 +18,11 @@
|
||||
|
||||
#include "qemu/accel.h"
|
||||
#include "sysemu/hvf.h"
|
||||
#include "sysemu/hvf_int.h"
|
||||
#include "cpu.h"
|
||||
#include "x86.h"
|
||||
|
||||
/* 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 */
|
||||
|
||||
+55
-409
@@ -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"
|
||||
@@ -73,171 +74,6 @@
|
||||
#include "qemu/accel.h"
|
||||
#include "target/i386/cpu.h"
|
||||
|
||||
#include "hvf-accel-ops.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 */
|
||||
@@ -245,11 +81,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);
|
||||
}
|
||||
}
|
||||
@@ -257,7 +93,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);
|
||||
}
|
||||
|
||||
@@ -277,56 +113,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;
|
||||
@@ -371,90 +157,12 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
static void init_tsc_freq(CPUX86State *env)
|
||||
@@ -499,23 +207,10 @@ static inline bool apic_bus_freq_is_known(CPUX86State *env)
|
||||
return env->apic_bus_freq != 0;
|
||||
}
|
||||
|
||||
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();
|
||||
@@ -532,10 +227,6 @@ int hvf_init_vcpu(CPUState *cpu)
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
@@ -554,43 +245,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;
|
||||
}
|
||||
@@ -631,16 +322,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;
|
||||
@@ -719,20 +410,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();
|
||||
|
||||
@@ -762,7 +453,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)) {
|
||||
@@ -807,7 +498,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;
|
||||
@@ -823,21 +514,21 @@ 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);
|
||||
|
||||
if (rax == 1) {
|
||||
/* CPUID1.ecx.OSXSAVE needs to know CR4 */
|
||||
env->cr[4] = rvmcs(cpu->hvf_fd, VMCS_GUEST_CR4);
|
||||
env->cr[4] = rvmcs(cpu->hvf->fd, VMCS_GUEST_CR4);
|
||||
}
|
||||
hvf_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;
|
||||
@@ -845,16 +536,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;
|
||||
}
|
||||
@@ -893,11 +584,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: {
|
||||
@@ -933,7 +624,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
|
||||
@@ -946,8 +637,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:
|
||||
@@ -963,48 +654,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);
|
||||
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-accel-ops.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
@@ -674,7 +674,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);
|
||||
@@ -683,16 +683,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();
|
||||
@@ -780,13 +780,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();
|
||||
@@ -799,9 +799,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):
|
||||
@@ -1425,21 +1425,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)
|
||||
@@ -1448,20 +1448,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);
|
||||
}
|
||||
+112
-110
@@ -26,14 +26,13 @@
|
||||
#include "cpu.h"
|
||||
#include "x86_descr.h"
|
||||
#include "x86_decode.h"
|
||||
#include "sysemu/hw_accel.h"
|
||||
|
||||
#include "hw/i386/apic_internal.h"
|
||||
|
||||
#include <Hypervisor/hv.h>
|
||||
#include <Hypervisor/hv_vmx.h>
|
||||
|
||||
#include "hvf-accel-ops.h"
|
||||
|
||||
void hvf_set_segment(struct CPUState *cpu, struct vmx_segment *vmx_seg,
|
||||
SegmentCache *qseg, bool is_tr)
|
||||
{
|
||||
@@ -81,7 +80,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 +90,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 +128,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 +162,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 +201,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 +219,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 +247,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 +274,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 +291,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 +333,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 +378,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 +387,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 +405,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 +417,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 +433,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 +453,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);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,21 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
/*
|
||||
* TCI target-specific constraint sets.
|
||||
* Copyright (c) 2021 Linaro
|
||||
*/
|
||||
|
||||
/*
|
||||
* C_On_Im(...) defines a constraint set with <n> outputs and <m> inputs.
|
||||
* Each operand should be a sequence of constraint letters as defined by
|
||||
* tcg-target-con-str.h; the constraint combination is inclusive or.
|
||||
*/
|
||||
C_O0_I2(r, r)
|
||||
C_O0_I3(r, r, r)
|
||||
C_O0_I4(r, r, r, r)
|
||||
C_O1_I1(r, r)
|
||||
C_O1_I2(r, 0, r)
|
||||
C_O1_I2(r, r, r)
|
||||
C_O1_I4(r, r, r, r, r)
|
||||
C_O2_I1(r, r, r)
|
||||
C_O2_I2(r, r, r, r)
|
||||
C_O2_I4(r, r, r, r, r, r)
|
||||
@@ -0,0 +1,11 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
/*
|
||||
* Define TCI target-specific operand constraints.
|
||||
* Copyright (c) 2021 Linaro
|
||||
*/
|
||||
|
||||
/*
|
||||
* Define constraint letters for register sets:
|
||||
* REGS(letter, register_mask)
|
||||
*/
|
||||
REGS('r', MAKE_64BIT_MASK(0, TCG_TARGET_NB_REGS))
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Tiny Code Generator for QEMU
|
||||
*
|
||||
* Copyright (c) 2009, 2011 Stefan Weil
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code implements a TCG which does not generate machine code for some
|
||||
* real target machine but which generates virtual machine code for an
|
||||
* interpreter. Interpreted pseudo code is slow, but it works on any host.
|
||||
*
|
||||
* Some remarks might help in understanding the code:
|
||||
*
|
||||
* "target" or "TCG target" is the machine which runs the generated code.
|
||||
* This is different to the usual meaning in QEMU where "target" is the
|
||||
* emulated machine. So normally QEMU host is identical to TCG target.
|
||||
* Here the TCG target is a virtual machine, but this virtual machine must
|
||||
* use the same word size like the real machine.
|
||||
* Therefore, we need both 32 and 64 bit virtual machines (interpreter).
|
||||
*/
|
||||
|
||||
#ifndef TCG_TARGET_H
|
||||
#define TCG_TARGET_H
|
||||
|
||||
#if UINTPTR_MAX == UINT32_MAX
|
||||
# error We only support AArch64 running in 64B mode.
|
||||
#elif UINTPTR_MAX == UINT64_MAX
|
||||
# define TCG_TARGET_REG_BITS 64
|
||||
#else
|
||||
# error Unknown pointer size for tcti target
|
||||
#endif
|
||||
|
||||
#define TCG_TARGET_INSN_UNIT_SIZE 1
|
||||
#define TCG_TARGET_TLB_DISPLACEMENT_BITS 32
|
||||
|
||||
// We're an interpreted target; even if we're JIT-compiling to our interpreter's
|
||||
// weird psuedo-native bytecode. We'll indicate that we're intepreted.
|
||||
#define TCG_TARGET_INTERPRETER 1
|
||||
|
||||
//
|
||||
// Supported optional instructions.
|
||||
//
|
||||
|
||||
// Divs.
|
||||
#define TCG_TARGET_HAS_div_i32 1
|
||||
#define TCG_TARGET_HAS_rem_i32 1
|
||||
#define TCG_TARGET_HAS_div_i64 1
|
||||
#define TCG_TARGET_HAS_rem_i64 1
|
||||
|
||||
// Extends.
|
||||
#define TCG_TARGET_HAS_ext8s_i32 1
|
||||
#define TCG_TARGET_HAS_ext16s_i32 1
|
||||
#define TCG_TARGET_HAS_ext8u_i32 1
|
||||
#define TCG_TARGET_HAS_ext16u_i32 1
|
||||
#define TCG_TARGET_HAS_ext8s_i64 1
|
||||
#define TCG_TARGET_HAS_ext16s_i64 1
|
||||
#define TCG_TARGET_HAS_ext32s_i64 1
|
||||
#define TCG_TARGET_HAS_ext8u_i64 1
|
||||
#define TCG_TARGET_HAS_ext16u_i64 1
|
||||
#define TCG_TARGET_HAS_ext32u_i64 1
|
||||
|
||||
// Logicals.
|
||||
#define TCG_TARGET_HAS_neg_i32 1
|
||||
#define TCG_TARGET_HAS_not_i32 1
|
||||
#define TCG_TARGET_HAS_neg_i64 1
|
||||
#define TCG_TARGET_HAS_not_i64 1
|
||||
|
||||
#define TCG_TARGET_HAS_andc_i32 1
|
||||
#define TCG_TARGET_HAS_orc_i32 1
|
||||
#define TCG_TARGET_HAS_eqv_i32 1
|
||||
#define TCG_TARGET_HAS_andc_i64 1
|
||||
#define TCG_TARGET_HAS_eqv_i64 1
|
||||
#define TCG_TARGET_HAS_orc_i64 1
|
||||
|
||||
// We don't curretly support rotates, since AArch64 lacks ROL.
|
||||
// We'll fix this later.
|
||||
#define TCG_TARGET_HAS_rot_i32 0
|
||||
#define TCG_TARGET_HAS_rot_i64 0
|
||||
|
||||
// Swaps.
|
||||
#define TCG_TARGET_HAS_bswap16_i32 1
|
||||
#define TCG_TARGET_HAS_bswap32_i32 1
|
||||
#define TCG_TARGET_HAS_bswap16_i64 1
|
||||
#define TCG_TARGET_HAS_bswap32_i64 1
|
||||
#define TCG_TARGET_HAS_bswap64_i64 1
|
||||
#define TCG_TARGET_HAS_MEMORY_BSWAP 1
|
||||
|
||||
// Specify we'll handle direct jumps.
|
||||
#define TCG_TARGET_HAS_direct_jump 1
|
||||
|
||||
//
|
||||
// Potential TODOs.
|
||||
//
|
||||
|
||||
// TODO: implement DEPOSIT as BFI.
|
||||
#define TCG_TARGET_HAS_deposit_i32 0
|
||||
#define TCG_TARGET_HAS_deposit_i64 0
|
||||
|
||||
// TODO: implement EXTRACT as BFX.
|
||||
#define TCG_TARGET_HAS_extract_i32 0
|
||||
#define TCG_TARGET_HAS_sextract_i32 0
|
||||
#define TCG_TARGET_HAS_extract_i64 0
|
||||
#define TCG_TARGET_HAS_sextract_i64 0
|
||||
|
||||
// TODO: it might be worth writing a gadget for this
|
||||
#define TCG_TARGET_HAS_movcond_i32 0
|
||||
#define TCG_TARGET_HAS_movcond_i64 0
|
||||
|
||||
//
|
||||
// Unsupported instructions.
|
||||
//
|
||||
|
||||
// ARMv8 doesn't have instructions for NAND/NOR.
|
||||
#define TCG_TARGET_HAS_nand_i32 0
|
||||
#define TCG_TARGET_HAS_nor_i32 0
|
||||
#define TCG_TARGET_HAS_nor_i64 0
|
||||
#define TCG_TARGET_HAS_nand_i64 0
|
||||
|
||||
// aarch64's CLZ is implemented without a condition, so it
|
||||
#define TCG_TARGET_HAS_clz_i32 0
|
||||
#define TCG_TARGET_HAS_ctz_i32 0
|
||||
#define TCG_TARGET_HAS_ctpop_i32 0
|
||||
#define TCG_TARGET_HAS_clz_i64 0
|
||||
#define TCG_TARGET_HAS_ctz_i64 0
|
||||
#define TCG_TARGET_HAS_ctpop_i64 0
|
||||
|
||||
|
||||
// GOTO_PTR is too complex to emit a simple gadget for.
|
||||
// We'll let C handle it, since the overhead is similar.
|
||||
#define TCG_TARGET_HAS_goto_ptr 0
|
||||
|
||||
// We don't have a simple gadget for this, since we're always assuming softmmu.
|
||||
#define TCG_TARGET_HAS_qemu_st8_i32 0
|
||||
|
||||
// No AArch64 equivalent.a
|
||||
#define TCG_TARGET_HAS_extrl_i64_i32 0
|
||||
#define TCG_TARGET_HAS_extrh_i64_i32 0
|
||||
|
||||
#define TCG_TARGET_HAS_extract2_i64 0
|
||||
|
||||
// These should always be zero on our 64B platform.
|
||||
#define TCG_TARGET_HAS_muls2_i64 0
|
||||
#define TCG_TARGET_HAS_add2_i32 0
|
||||
#define TCG_TARGET_HAS_sub2_i32 0
|
||||
#define TCG_TARGET_HAS_mulu2_i32 0
|
||||
#define TCG_TARGET_HAS_add2_i64 0
|
||||
#define TCG_TARGET_HAS_sub2_i64 0
|
||||
#define TCG_TARGET_HAS_mulu2_i64 0
|
||||
#define TCG_TARGET_HAS_muluh_i64 0
|
||||
#define TCG_TARGET_HAS_mulsh_i64 0
|
||||
#define TCG_TARGET_HAS_extract2_i32 0
|
||||
#define TCG_TARGET_HAS_muls2_i32 0
|
||||
#define TCG_TARGET_HAS_muluh_i32 0
|
||||
#define TCG_TARGET_HAS_mulsh_i32 0
|
||||
|
||||
//
|
||||
// Platform metadata.
|
||||
//
|
||||
|
||||
// Number of registers available.
|
||||
// It might make sense to up these, since we can also use x16 -> x25?
|
||||
#define TCG_TARGET_NB_REGS 16
|
||||
|
||||
/* List of registers which are used by TCG. */
|
||||
typedef enum {
|
||||
TCG_REG_R0 = 0,
|
||||
TCG_REG_R1,
|
||||
TCG_REG_R2,
|
||||
TCG_REG_R3,
|
||||
TCG_REG_R4,
|
||||
TCG_REG_R5,
|
||||
TCG_REG_R6,
|
||||
TCG_REG_R7,
|
||||
TCG_REG_R8,
|
||||
TCG_REG_R9,
|
||||
TCG_REG_R10,
|
||||
TCG_REG_R11,
|
||||
TCG_REG_R12,
|
||||
TCG_REG_R13,
|
||||
TCG_REG_R14,
|
||||
TCG_REG_R15,
|
||||
|
||||
TCG_AREG0 = TCG_REG_R14,
|
||||
TCG_REG_CALL_STACK = TCG_REG_R15,
|
||||
} TCGReg;
|
||||
|
||||
// Specify the shape of the stack our runtime will use.
|
||||
#define TCG_TARGET_CALL_STACK_OFFSET 0
|
||||
#define TCG_TARGET_STACK_ALIGN 16
|
||||
|
||||
// We're interpreted, so we'll use our own code to run TB_EXEC.
|
||||
#define HAVE_TCG_QEMU_TB_EXEC
|
||||
|
||||
// We'll need to enforce memory ordering with barriers.
|
||||
#define TCG_TARGET_DEFAULT_MO (0)
|
||||
|
||||
void tci_disas(uint8_t opc);
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
||||
|
||||
|
||||
#endif /* TCG_TARGET_H */
|
||||
Executable
+788
@@ -0,0 +1,788 @@
|
||||
#!/usr/bin/env python3
|
||||
""" Gadget-code generator for QEMU TCTI on AArch64.
|
||||
|
||||
Generates a C-code include file containing 'gadgets' for use by TCTI.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import itertools
|
||||
|
||||
# Get a handle on the file we'll be working with, and redirect print to it.
|
||||
if len(sys.argv) > 1:
|
||||
out_file = open(sys.argv[1], "w")
|
||||
|
||||
# Hook our print function, so it always outputs to the relevant file.
|
||||
core_print = print
|
||||
print = lambda *a, **k : core_print(*a, **k, file=out_file)
|
||||
|
||||
# Epilogue code follows at the end of each gadget, and handles continuing execution.
|
||||
EPILOGUE = (
|
||||
# Load our next gadget address from our bytecode stream, advancing it.
|
||||
"ldr x27, [x28], #8",
|
||||
|
||||
# Jump to the next gadget.
|
||||
"br x27"
|
||||
)
|
||||
|
||||
# The number of general-purpose registers we're affording the TCG. This must match
|
||||
# the configuration in the TCTI target.
|
||||
TCG_REGISTER_COUNT = 16
|
||||
TCG_REGISTER_NUMBERS = list(range(TCG_REGISTER_COUNT))
|
||||
|
||||
# Helper that provides each of the AArch64 condition codes of interest.
|
||||
ARCH_CONDITION_CODES = ["eq", "ne", "lt", "ge", "le", "gt", "lo", "hs", "ls", "hi"]
|
||||
|
||||
# We'll create a variety of gadgets that assume the MMU's TLB is stored at certain
|
||||
# offsets into its structure. These should match the offsets in tcg-target.c.in.
|
||||
QEMU_ALLOWED_MMU_OFFSETS = [ 64, 96, 128 ]
|
||||
|
||||
# Statistics.
|
||||
gadgets = 0
|
||||
instructions = 0
|
||||
|
||||
def simple(name, *lines):
|
||||
""" Generates a simple gadget that needs no per-register specialization. """
|
||||
|
||||
global gadgets, instructions
|
||||
|
||||
gadgets += 1
|
||||
|
||||
# Create our C/ASM framing.
|
||||
#print(f"__attribute__((naked)) static void gadget_{name}(void)")
|
||||
print(f"__attribute__((naked)) static void gadget_{name}(void);")
|
||||
print(f"__attribute__((naked)) static void gadget_{name}(void)")
|
||||
print("{")
|
||||
|
||||
# Add the core gadget
|
||||
print("\tasm(")
|
||||
for line in lines + EPILOGUE:
|
||||
print(f"\t\t\"{line} \\n\"")
|
||||
instructions += 1
|
||||
print("\t);")
|
||||
|
||||
# End our framing.
|
||||
print("}\n")
|
||||
|
||||
|
||||
def with_register_substitutions(name, substitutions, *lines, immediate_range=range(0)):
|
||||
""" Generates a collection of gadgtes with register substitutions. """
|
||||
|
||||
def substitutions_for_letter(letter, number, line):
|
||||
""" Helper that transforms Wd => w1, implementing gadget substitutions. """
|
||||
|
||||
# Register substitutions...
|
||||
line = line.replace(f"X{letter}", f"x{number}")
|
||||
line = line.replace(f"W{letter}", f"w{number}")
|
||||
|
||||
# ... immediate substitutions.
|
||||
line = line.replace(f"I{letter}", f"{number}")
|
||||
return line
|
||||
|
||||
|
||||
# Build a list of all the various stages we'll iterate over...
|
||||
immediate_parameters = list(immediate_range)
|
||||
parameters = ([TCG_REGISTER_NUMBERS] * len(substitutions))
|
||||
|
||||
# ... adding immediates, if need be.
|
||||
if immediate_parameters:
|
||||
parameters.append(immediate_parameters)
|
||||
substitutions = substitutions + ['i']
|
||||
|
||||
# Generate a list of register-combinations we'll support.
|
||||
permutations = itertools.product(*parameters)
|
||||
|
||||
# For each permutation...
|
||||
for permutation in permutations:
|
||||
new_lines = lines
|
||||
|
||||
# Replace each placeholder element with its proper value...
|
||||
for index, element in enumerate(permutation):
|
||||
letter = substitutions[index]
|
||||
number = element
|
||||
|
||||
# Create new gadgets for the releavnt line...
|
||||
new_lines = [substitutions_for_letter(letter, number, line) for line in new_lines]
|
||||
|
||||
# ... and emit the gadget.
|
||||
permutation_id = "_arg".join(str(number) for number in permutation)
|
||||
simple(f"{name}_arg{permutation_id}", *new_lines)
|
||||
|
||||
|
||||
def with_dnm(name, *lines):
|
||||
""" Generates a collection of gadgets with substitutions for Xd, Xn, and Xm, and equivalents. """
|
||||
with_register_substitutions(name, ("d", "n", "m"), *lines)
|
||||
|
||||
# Print out an array that contains all of our gadgets, for lookup.
|
||||
print(f"static void* gadget_{name}[{TCG_REGISTER_COUNT}][{TCG_REGISTER_COUNT}][{TCG_REGISTER_COUNT}] = ", end="")
|
||||
print("{")
|
||||
|
||||
# D array
|
||||
for d in TCG_REGISTER_NUMBERS:
|
||||
print("\t{")
|
||||
|
||||
# N array
|
||||
for n in TCG_REGISTER_NUMBERS:
|
||||
print("\t\t{", end="")
|
||||
|
||||
# M array
|
||||
for m in TCG_REGISTER_NUMBERS:
|
||||
print(f"gadget_{name}_arg{d}_arg{n}_arg{m}", end=", ")
|
||||
|
||||
print("},")
|
||||
print("\t},")
|
||||
print("};")
|
||||
|
||||
|
||||
def with_dn_immediate(name, *lines, immediate_range):
|
||||
""" Generates a collection of gadgets with substitutions for Xd, Xn, and Xm, and equivalents. """
|
||||
with_register_substitutions(name, ["d", "n"], *lines, immediate_range=immediate_range)
|
||||
|
||||
# Print out an array that contains all of our gadgets, for lookup.
|
||||
print(f"static void* gadget_{name}[{TCG_REGISTER_COUNT}][{TCG_REGISTER_COUNT}][{len(immediate_range)}] = ", end="")
|
||||
print("{")
|
||||
|
||||
# D array
|
||||
for d in TCG_REGISTER_NUMBERS:
|
||||
print("\t{")
|
||||
|
||||
# N array
|
||||
for n in TCG_REGISTER_NUMBERS:
|
||||
print("\t\t{", end="")
|
||||
|
||||
# M array
|
||||
for i in immediate_range:
|
||||
print(f"gadget_{name}_arg{d}_arg{n}_arg{i}", end=", ")
|
||||
|
||||
print("},")
|
||||
print("\t},")
|
||||
print("};")
|
||||
|
||||
|
||||
def with_pair(name, substitutions, *lines):
|
||||
""" Generates a collection of gadgets with two subtstitutions."""
|
||||
with_register_substitutions(name, substitutions, *lines)
|
||||
|
||||
# Print out an array that contains all of our gadgets, for lookup.
|
||||
print(f"static void* gadget_{name}[{TCG_REGISTER_COUNT}][{TCG_REGISTER_COUNT}] = ", end="")
|
||||
print("{")
|
||||
|
||||
# N array
|
||||
for a in TCG_REGISTER_NUMBERS:
|
||||
print("\t\t{", end="")
|
||||
|
||||
# M array
|
||||
for b in TCG_REGISTER_NUMBERS:
|
||||
print(f"gadget_{name}_arg{a}_arg{b}", end=", ")
|
||||
|
||||
print("},")
|
||||
print("};")
|
||||
|
||||
|
||||
def math_dnm(name, mnemonic):
|
||||
""" Equivalent to `with_dnm`, but creates a _i32 and _i64 variant. For simple math. """
|
||||
with_dnm(f'{name}_i32', f"{mnemonic} Wd, Wn, Wm")
|
||||
with_dnm(f'{name}_i64', f"{mnemonic} Xd, Xn, Xm")
|
||||
|
||||
def math_dn(name, mnemonic):
|
||||
""" Equivalent to `with_dn`, but creates a _i32 and _i64 variant. For simple math. """
|
||||
with_dn(f'{name}_i32', f"{mnemonic} Wd, Wn")
|
||||
with_dn(f'{name}_i64', f"{mnemonic} Xd, Xn")
|
||||
|
||||
|
||||
def with_nm(name, *lines):
|
||||
""" Generates a collection of gadgets with substitutions for Xn, and Xm, and equivalents. """
|
||||
with_pair(name, ('n', 'm',), *lines)
|
||||
|
||||
|
||||
def with_dn(name, *lines):
|
||||
""" Generates a collection of gadgets with substitutions for Xd, and Xn, and equivalents. """
|
||||
with_pair(name, ('d', 'n',), *lines)
|
||||
|
||||
|
||||
def ldst_dn(name, *lines):
|
||||
""" Generates a collection of gadgets with substitutions for Xd, and Xn, and equivalents.
|
||||
|
||||
This variant is optimized for loads and stores, and optimizes common offset cases.
|
||||
"""
|
||||
|
||||
#
|
||||
# Simple case: create our gadgets.
|
||||
#
|
||||
with_dn(name, "ldr x27, [x28], #8", *lines)
|
||||
|
||||
#
|
||||
# Optimization case: create variants of our gadgets with our offsets replaced with common immediates.
|
||||
#
|
||||
immediate_lines_pos = [line.replace("x27", "#Ii") for line in lines]
|
||||
with_dn_immediate(f"{name}_imm", *immediate_lines_pos, immediate_range=range(64))
|
||||
|
||||
immediate_lines_aligned = [line.replace("x27", "#(Ii << 3)") for line in lines]
|
||||
with_dn_immediate(f"{name}_sh8_imm", *immediate_lines_aligned, immediate_range=range(64))
|
||||
|
||||
immediate_lines_neg = [line.replace("x27", "#-Ii") for line in lines]
|
||||
with_dn_immediate(f"{name}_neg_imm", *immediate_lines_neg, immediate_range=range(64))
|
||||
|
||||
|
||||
def with_single(name, substitution, *lines):
|
||||
""" Generates a collection of gadgets with two subtstitutions."""
|
||||
with_register_substitutions(name, (substitution,), *lines)
|
||||
|
||||
# Print out an array that contains all of our gadgets, for lookup.
|
||||
print(f"static void* gadget_{name}[{TCG_REGISTER_COUNT}] = ", end="")
|
||||
print("{")
|
||||
|
||||
for n in TCG_REGISTER_NUMBERS:
|
||||
print(f"gadget_{name}_arg{n}", end=", ")
|
||||
|
||||
print("};")
|
||||
|
||||
|
||||
def with_d_immediate(name, *lines, immediate_range=range(0)):
|
||||
""" Generates a collection of gadgets with two subtstitutions."""
|
||||
with_register_substitutions(name, ['d'], *lines, immediate_range=immediate_range)
|
||||
|
||||
# Print out an array that contains all of our gadgets, for lookup.
|
||||
print(f"static void* gadget_{name}[{TCG_REGISTER_COUNT}][{len(immediate_range)}] = ", end="")
|
||||
print("{")
|
||||
|
||||
# D array
|
||||
for a in TCG_REGISTER_NUMBERS:
|
||||
print("\t\t{", end="")
|
||||
|
||||
# I array
|
||||
for b in immediate_range:
|
||||
print(f"gadget_{name}_arg{a}_arg{b}", end=", ")
|
||||
|
||||
print("},")
|
||||
print("};")
|
||||
|
||||
|
||||
|
||||
def with_d(name, *lines):
|
||||
""" Generates a collection of gadgets with substitutions for Xd. """
|
||||
with_single(name, 'd', *lines)
|
||||
|
||||
|
||||
# Assembly code for saving our machine state before entering the C runtime.
|
||||
C_CALL_PROLOGUE = [
|
||||
# Store our machine state.
|
||||
"str x25, [sp, #-16]!",
|
||||
"stp x14, x15, [sp, #-16]!",
|
||||
"stp x12, x13, [sp, #-16]!",
|
||||
"stp x10, x11, [sp, #-16]!",
|
||||
"stp x8, x9, [sp, #-16]!",
|
||||
"stp x6, x7, [sp, #-16]!",
|
||||
"stp x4, x5, [sp, #-16]!",
|
||||
"stp x2, x3, [sp, #-16]!",
|
||||
"stp x0, x1, [sp, #-16]!",
|
||||
"stp x28, lr, [sp, #-16]!",
|
||||
]
|
||||
|
||||
# Assembly code for restoring our machine state after leaving the C runtime.
|
||||
C_CALL_EPILOGUE = [
|
||||
"ldp x28, lr, [sp], #16",
|
||||
"ldp x0, x1, [sp], #16",
|
||||
"ldp x2, x3, [sp], #16",
|
||||
"ldp x4, x5, [sp], #16",
|
||||
"ldp x6, x7, [sp], #16",
|
||||
"ldp x8, x9, [sp], #16",
|
||||
"ldp x10, x11, [sp], #16",
|
||||
"ldp x12, x13, [sp], #16",
|
||||
"ldp x14, x15, [sp], #16",
|
||||
"ldr x25, [sp], #16",
|
||||
]
|
||||
|
||||
|
||||
def create_tlb_fastpath(is_aligned, is_write, offset, miss_label="0"):
|
||||
""" Creates a set of instructions that perform a soft-MMU TLB lookup.
|
||||
|
||||
This is used for `qemu_ld`/qemu_st` instructions; to emit a prologue that
|
||||
hopefully helps us skip a slow call into the C runtime when a Guest Virtual
|
||||
-> Host Virtual mapping is in the softmmu's TLB.
|
||||
|
||||
This "fast-path" prelude behaves as follows:
|
||||
- If a TLB entry is found for the address stored in Xn, then x27
|
||||
is stored to an "addend" that can be added to the guest virtual addres
|
||||
to get the host virtual address (the address in our local memory space).
|
||||
- If a TLB entry isn't found, it branches to the "miss_label" (by default, 0:),
|
||||
so address lookup can be handled by the fastpath.
|
||||
|
||||
Clobbers x24, and x26; provides output in x27.
|
||||
"""
|
||||
|
||||
fast_path = [
|
||||
# Load env_tlb(env)->f[mmu_idx].{mask,table} into {x26,x27}.
|
||||
f"ldp x26, x27, [x14, #-{offset}]",
|
||||
|
||||
# Extract the TLB index from the address into X26.
|
||||
"and x26, x26, Xn, lsr #7", # Xn = addr regsiter
|
||||
|
||||
# Add the tlb_table pointer, creating the CPUTLBEntry address into X27.
|
||||
"add x27, x27, x26",
|
||||
|
||||
# Load the tlb comparator into X26, and the fast path addend into X27.
|
||||
"ldr x26, [x27, #8]" if is_write else "ldr x26, [x27]",
|
||||
"ldr x27, [x27, #0x18]",
|
||||
|
||||
]
|
||||
|
||||
if is_aligned:
|
||||
fast_path.extend([
|
||||
# Store the page mask part of the address into X24.
|
||||
"and x24, Xn, #0xfffffffffffff000",
|
||||
|
||||
# Compare the masked address with the TLB value.
|
||||
"cmp x26, x24",
|
||||
|
||||
# If we're not equal, this isn't a TLB hit. Jump to our miss handler.
|
||||
f"b.ne {miss_label}f",
|
||||
])
|
||||
else:
|
||||
fast_path.extend([
|
||||
# If we're not aligned, add in our alignment value to ensure we don't
|
||||
# don't straddle the end of a page.
|
||||
"add x24, Xn, #7",
|
||||
|
||||
# Store the page mask part of the address into X24.
|
||||
"and x24, x24, #0xfffffffffffff000",
|
||||
|
||||
# Compare the masked address with the TLB value.
|
||||
"cmp x26, x24",
|
||||
|
||||
# If we're not equal, this isn't a TLB hit. Jump to our miss handler.
|
||||
f"b.ne {miss_label}f",
|
||||
])
|
||||
|
||||
return fast_path
|
||||
|
||||
|
||||
|
||||
def ld_thunk(name, fastpath_32b, fastpath_64b, slowpath_helper, immediate=None, is_aligned=False, force_slowpath=False):
|
||||
""" Creates a thunk into our C runtime for a QEMU ST operation. """
|
||||
|
||||
# Use only offset 0 (no real offset) if we're forcing slowpath;
|
||||
# otherwise, use all of our allowed MMU offsets.
|
||||
offsets = [0] if force_slowpath else QEMU_ALLOWED_MMU_OFFSETS
|
||||
for offset in offsets:
|
||||
for is_32b in (True, False):
|
||||
fastpath = fastpath_32b if is_32b else fastpath_64b
|
||||
|
||||
gadget_name = f"{name}_off{offset}_i32" if is_32b else f"{name}_off{offset}_i64"
|
||||
postscript = () if immediate else ("add x28, x28, #8",)
|
||||
|
||||
# If we have a pure-assembly fast path, start our gadget with it.
|
||||
if fastpath and not force_slowpath:
|
||||
fastpath_ops = [
|
||||
# Create a fastpath that jumps to miss_lable on a TLB miss,
|
||||
# or sets x27 to the TLB addend on a TLB hit.
|
||||
*create_tlb_fastpath(is_aligned=is_aligned, is_write=False, offset=offset),
|
||||
|
||||
# On a hit, we can just perform an appropriate load...
|
||||
*fastpath,
|
||||
|
||||
# Run our patch-up post-script, if we have one.
|
||||
*postscript,
|
||||
|
||||
# ... and then we're done!
|
||||
*EPILOGUE,
|
||||
]
|
||||
# Otherwise, we'll save arguments for our slow path.
|
||||
else:
|
||||
fastpath_ops = []
|
||||
|
||||
#
|
||||
# If we're not taking our fast path, we'll call into our C runtime to take the slow path.
|
||||
#
|
||||
with_dn(gadget_name,
|
||||
*fastpath_ops,
|
||||
|
||||
"0:",
|
||||
"mov x27, Xn",
|
||||
|
||||
# Save our registers in preparation for entering a C call.
|
||||
*C_CALL_PROLOGUE,
|
||||
|
||||
# Per our calling convention:
|
||||
# - Move our architectural environment into x0, from x14.
|
||||
# - Move our target address into x1. [Placed in x27 below.]
|
||||
# - Move our operation info into x2, from an immediate32.
|
||||
# - Move the next bytecode pointer into x3, from x28.
|
||||
"mov x0, x14",
|
||||
"mov x1, x27",
|
||||
f"mov x2, #{immediate}" if (immediate is not None) else "ldr x2, [x28], #8",
|
||||
"mov x3, x28",
|
||||
|
||||
# Perform our actual core code.
|
||||
f"bl _{slowpath_helper}",
|
||||
|
||||
# Temporarily store our result in a register that won't get trashed.
|
||||
"mov x27, x0",
|
||||
|
||||
# Restore our registers after our C call.
|
||||
*C_CALL_EPILOGUE,
|
||||
|
||||
# Finally, call our postscript...
|
||||
*postscript,
|
||||
|
||||
# ... and place our results in the target register.
|
||||
"mov Wd, w27" if is_32b else "mov Xd, x27"
|
||||
)
|
||||
|
||||
|
||||
def st_thunk(name, fastpath_32b, fastpath_64b, slowpath_helper, immediate=None, is_aligned=False, force_slowpath=False):
|
||||
""" Creates a thunk into our C runtime for a QEMU ST operation. """
|
||||
|
||||
# Use only offset 0 (no real offset) if we're forcing slowpath;
|
||||
# otherwise, use all of our allowed MMU offsets.
|
||||
offsets = [0] if force_slowpath else QEMU_ALLOWED_MMU_OFFSETS
|
||||
for offset in offsets:
|
||||
|
||||
for is_32b in (True, False):
|
||||
fastpath = fastpath_32b if is_32b else fastpath_64b
|
||||
|
||||
gadget_name = f"{name}_off{offset}_i32" if is_32b else f"{name}_off{offset}_i64"
|
||||
postscript = () if immediate else ("add x28, x28, #8",)
|
||||
|
||||
# If we have a pure-assembly fast path, start our gadget with it.
|
||||
if fastpath and not force_slowpath:
|
||||
fastpath_ops = [
|
||||
|
||||
# Create a fastpath that jumps to miss_lable on a TLB miss,
|
||||
# or sets x27 to the TLB addend on a TLB hit.
|
||||
*create_tlb_fastpath(is_aligned=is_aligned, is_write=True, offset=offset),
|
||||
|
||||
# On a hit, we can just perform an appropriate load...
|
||||
*fastpath,
|
||||
|
||||
# Run our patch-up post-script, if we have one.
|
||||
*postscript,
|
||||
|
||||
# ... and then we're done!
|
||||
*EPILOGUE,
|
||||
]
|
||||
else:
|
||||
fastpath_ops = []
|
||||
|
||||
|
||||
#
|
||||
# If we're not taking our fast path, we'll call into our C runtime to take the slow path.
|
||||
#
|
||||
with_dn(gadget_name,
|
||||
*fastpath_ops,
|
||||
|
||||
"0:",
|
||||
# Move our arguments into registers that we're not actively using.
|
||||
# This ensures that they won't be trounced by our calling convention
|
||||
# if this is reading values from x0-x4.
|
||||
"mov w27, Wd" if is_32b else "mov x27, Xd",
|
||||
"mov x26, Xn",
|
||||
|
||||
# Save our registers in preparation for entering a C call.
|
||||
*C_CALL_PROLOGUE,
|
||||
|
||||
# Per our calling convention:
|
||||
# - Move our architectural environment into x0, from x14.
|
||||
# - Move our target address into x1. [Moved into x26 above].
|
||||
# - Move our target value into x2. [Moved into x27 above].
|
||||
# - Move our operation info into x3, from an immediate32.
|
||||
# - Move the next bytecode pointer into x4, from x28.
|
||||
"mov x0, x14",
|
||||
"mov x1, x26",
|
||||
"mov x2, x27",
|
||||
f"mov x3, #{immediate}" if (immediate is not None) else "ldr x3, [x28], #8",
|
||||
"mov x4, x28",
|
||||
|
||||
# Perform our actual core code.
|
||||
f"bl _{slowpath_helper}",
|
||||
|
||||
# Restore our registers after our C call.
|
||||
*C_CALL_EPILOGUE,
|
||||
|
||||
# Finally, call our postscript.
|
||||
*postscript
|
||||
)
|
||||
|
||||
|
||||
#
|
||||
# Gadget definitions.
|
||||
#
|
||||
|
||||
print("/* Automatically generated by tcti-gadget-gen.py. Do not edit. */\n")
|
||||
|
||||
# Call a C language helper function by address.
|
||||
simple("call",
|
||||
# Get our C runtime function's location as a pointer-sized immediate...
|
||||
"ldr x27, [x28], #8",
|
||||
|
||||
# Store our TB return address for our helper.
|
||||
"str x28, [x25]",
|
||||
|
||||
# Prepare ourselves to call into our C runtime...
|
||||
*C_CALL_PROLOGUE,
|
||||
|
||||
# ... perform the call itself ...
|
||||
"blr x27",
|
||||
|
||||
# Save the result of our call for later.
|
||||
"mov x27, x0",
|
||||
|
||||
# ... and restore our environment.
|
||||
*C_CALL_EPILOGUE,
|
||||
|
||||
# Restore our return value.
|
||||
"mov x0, x27"
|
||||
)
|
||||
|
||||
# Branch to a given immediate address.
|
||||
simple("br",
|
||||
# Use our immediate argument as our new bytecode-pointer location.
|
||||
"ldr x28, [x28]"
|
||||
)
|
||||
|
||||
# Exit from a translation buffer execution.
|
||||
simple("exit_tb",
|
||||
|
||||
# We have a single immediate argument, which contains our return code.
|
||||
# Place it into x0, as one would a return code.
|
||||
"ldr x0, [x28], #8",
|
||||
|
||||
# And finally, return back to the code that invoked our gadget stream.
|
||||
"ret"
|
||||
)
|
||||
|
||||
|
||||
for condition in ARCH_CONDITION_CODES:
|
||||
|
||||
# Performs a comparison between two operands.
|
||||
with_dnm(f"setcond_i32_{condition}",
|
||||
"subs Wd, Wn, Wm",
|
||||
f"cset Wd, {condition}"
|
||||
)
|
||||
with_dnm(f"setcond_i64_{condition}",
|
||||
"subs Xd, Xn, Xm",
|
||||
f"cset Xd, {condition}"
|
||||
)
|
||||
|
||||
#
|
||||
# NOTE: we use _dnm for the conditional branches, even though we don't
|
||||
# actually do anything different based on the d argument. This gemerates
|
||||
# effectively 16 identical `brcond` gadgets for each condition; which we
|
||||
# use in the backend to spread out the actual branch sources we use.
|
||||
#
|
||||
# This is a slight mercy for the branch predictor, as not every conditional
|
||||
# branch is funneled throught the same address.
|
||||
#
|
||||
|
||||
# Branches iff a given comparison is true.
|
||||
with_dnm(f'brcond_i32_{condition}',
|
||||
|
||||
# Grab our immediate argument.
|
||||
"ldr x27, [x28], #8",
|
||||
|
||||
# Perform our comparison and conditional branch.
|
||||
"subs Wzr, Wn, Wm",
|
||||
f"b{condition} 1f",
|
||||
|
||||
"0:", # not taken
|
||||
# Perform our end-of-instruction epilogue.
|
||||
*EPILOGUE,
|
||||
|
||||
"1:" # taken
|
||||
# Update our bytecode pointer to take the label.
|
||||
"mov x28, x27"
|
||||
)
|
||||
|
||||
# Branches iff a given comparison is true.
|
||||
with_dnm(f'brcond_i64_{condition}',
|
||||
|
||||
# Grab our immediate argument.
|
||||
"ldr x27, [x28], #8",
|
||||
|
||||
# Perform our comparison and conditional branch.
|
||||
"subs Xzr, Xn, Xm",
|
||||
f"b{condition} 1f",
|
||||
|
||||
"0:", # not taken
|
||||
# Perform our end-of-instruction epilogue.
|
||||
*EPILOGUE,
|
||||
|
||||
"1:" # taken
|
||||
# Update our bytecode pointer to take the label.
|
||||
"mov x28, x27"
|
||||
)
|
||||
|
||||
|
||||
# MOV variants.
|
||||
with_dn("mov_i32", "mov Wd, Wn")
|
||||
with_dn("mov_i64", "mov Xd, Xn")
|
||||
with_d("movi_i32", "ldr Wd, [x28], #8")
|
||||
with_d("movi_i64", "ldr Xd, [x28], #8")
|
||||
|
||||
# Create MOV variants that have common constants built in to the gadget.
|
||||
# This optimization helps costly reads from memories for simple operations.
|
||||
with_d_immediate("movi_imm_i32", "mov Wd, #Ii", immediate_range=range(64))
|
||||
with_d_immediate("movi_imm_i64", "mov Xd, #Ii", immediate_range=range(64))
|
||||
|
||||
# LOAD variants.
|
||||
# TODO: should the signed variants have X variants for _i64?
|
||||
ldst_dn("ld8u", "ldrb Wd, [Xn, x27]")
|
||||
ldst_dn("ld8s_i32", "ldrsb Wd, [Xn, x27]")
|
||||
ldst_dn("ld8s_i64", "ldrsb Xd, [Xn, x27]")
|
||||
ldst_dn("ld16u", "ldrh Wd, [Xn, x27]")
|
||||
ldst_dn("ld16s_i32", "ldrsh Wd, [Xn, x27]")
|
||||
ldst_dn("ld16s_i64", "ldrsh Xd, [Xn, x27]")
|
||||
ldst_dn("ld32u", "ldr Wd, [Xn, x27]")
|
||||
ldst_dn("ld32s_i64", "ldrsw Xd, [Xn, x27]")
|
||||
ldst_dn("ld_i64", "ldr Xd, [Xn, x27]")
|
||||
|
||||
# STORE variants.
|
||||
ldst_dn("st8", "strb Wd, [Xn, x27]")
|
||||
ldst_dn("st16", "strh Wd, [Xn, x27]")
|
||||
ldst_dn("st_i32", "str Wd, [Xn, x27]")
|
||||
ldst_dn("st_i64", "str Xd, [Xn, x27]")
|
||||
|
||||
# QEMU LD/ST are handled in our C runtime rather than with simple gadgets,
|
||||
# as they're nontrivial.
|
||||
|
||||
# Trivial arithmetic.
|
||||
math_dnm("add" , "add" )
|
||||
math_dnm("sub" , "sub" )
|
||||
math_dnm("mul" , "mul" )
|
||||
math_dnm("div" , "sdiv")
|
||||
math_dnm("divu", "udiv")
|
||||
|
||||
# Division remainder
|
||||
with_dnm("rem_i32", "sdiv w27, Wn, Wm", "msub Wd, w27, Wm, Wn")
|
||||
with_dnm("rem_i64", "sdiv x27, Xn, Xm", "msub Xd, x27, Xm, Xn")
|
||||
with_dnm("remu_i32", "udiv w27, Wn, Wm", "msub Wd, w27, Wm, Wn")
|
||||
with_dnm("remu_i64", "udiv x27, Xn, Xm", "msub Xd, x27, Xm, Xn")
|
||||
|
||||
# Trivial logical.
|
||||
math_dn( "not", "mvn")
|
||||
math_dn( "neg", "neg")
|
||||
math_dnm("and", "and")
|
||||
math_dnm("andc", "bic")
|
||||
math_dnm("or", "orr")
|
||||
math_dnm("orc", "orn")
|
||||
math_dnm("xor", "eor")
|
||||
math_dnm("eqv", "eon")
|
||||
math_dnm("shl", "lsl")
|
||||
math_dnm("shr", "lsr")
|
||||
math_dnm("sar", "asr")
|
||||
|
||||
# AArch64 lacks a Rotate Left; so we instead rotate right by a negative.
|
||||
# TODO: validate this?
|
||||
#math_dnm("rotr", "ror")
|
||||
#with_dnm("rotl_i32", "neg w27, Wm", "ror Wd, Wn, w27")
|
||||
#with_dnm("rotl_i64", "neg x27, Xm", "ror Xd, Xn, x27")
|
||||
|
||||
# Numeric extension.
|
||||
math_dn("ext8s", "sxtb")
|
||||
with_dn("ext8u", "and Xd, Xn, #0xff")
|
||||
math_dn("ext16s", "sxth")
|
||||
with_dn("ext16u", "and Wd, Wn, #0xffff")
|
||||
with_dn("ext32s_i64", "sxtw Xd, Wn")
|
||||
with_dn("ext32u_i64", "and Xd, Xn, #0xffffffff")
|
||||
|
||||
# Byte swapping.
|
||||
with_dn("bswap16", "rev w27, Wn", "lsr Wd, w27, #16")
|
||||
with_dn("bswap32", "rev Wd, Wn")
|
||||
with_dn("bswap64", "rev Xd, Xn")
|
||||
|
||||
# Memory barriers.
|
||||
simple("mb_all", "dmb ish")
|
||||
simple("mb_st", "dmb ishst")
|
||||
simple("mb_ld", "dmb ishld")
|
||||
|
||||
# Handlers for QEMU_LD, which handles guest <- host loads.
|
||||
for subtype in ('aligned', 'unaligned', 'slowpath'):
|
||||
is_aligned = (subtype == 'aligned')
|
||||
is_slowpath = (subtype == 'slowpath')
|
||||
|
||||
ld_thunk(f"qemu_ld_ub_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_ret_ldub_mmu",
|
||||
fastpath_32b=["ldrb Wd, [Xn, x27]"], fastpath_64b=["ldrb Wd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
ld_thunk(f"qemu_ld_sb_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_ret_ldub_mmu_signed",
|
||||
fastpath_32b=["ldrsb Wd, [Xn, x27]"], fastpath_64b=["ldrsb Xd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
ld_thunk(f"qemu_ld_leuw_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_le_lduw_mmu",
|
||||
fastpath_32b=["ldrh Wd, [Xn, x27]"], fastpath_64b=["ldrh Wd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
ld_thunk(f"qemu_ld_lesw_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_le_lduw_mmu_signed",
|
||||
fastpath_32b=["ldrsh Wd, [Xn, x27]"], fastpath_64b=["ldrsh Xd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
ld_thunk(f"qemu_ld_leul_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_le_ldul_mmu",
|
||||
fastpath_32b=["ldr Wd, [Xn, x27]"], fastpath_64b=["ldr Wd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
ld_thunk(f"qemu_ld_lesl_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_le_ldul_mmu_signed",
|
||||
fastpath_32b=["ldrsw Xd, [Xn, x27]"], fastpath_64b=["ldrsw Xd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
ld_thunk(f"qemu_ld_leq_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_le_ldq_mmu",
|
||||
fastpath_32b=["ldr Xd, [Xn, x27]"], fastpath_64b=["ldr Xd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
|
||||
# Special variant for the most common mode, as a speedup optimization.
|
||||
ld_thunk(f"qemu_ld_leq_{subtype}_mode3a", is_aligned=is_aligned, slowpath_helper="helper_le_ldq_mmu",
|
||||
fastpath_32b=["ldr Xd, [Xn, x27]"], fastpath_64b=["ldr Xd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath, immediate=0x3a
|
||||
)
|
||||
|
||||
# For now, leave the rare/big-endian stuff slow-path only.
|
||||
ld_thunk(f"qemu_ld_beuw_{subtype}", None, None, "helper_be_lduw_mmu",
|
||||
is_aligned=is_aligned, force_slowpath=is_slowpath)
|
||||
ld_thunk(f"qemu_ld_besw_{subtype}", None, None, "helper_be_lduw_mmu_signed",
|
||||
is_aligned=is_aligned, force_slowpath=is_slowpath)
|
||||
ld_thunk(f"qemu_ld_beul_{subtype}", None, None, "helper_be_ldul_mmu",
|
||||
is_aligned=is_aligned, force_slowpath=is_slowpath)
|
||||
ld_thunk(f"qemu_ld_besl_{subtype}", None, None, "helper_be_ldul_mmu_signed",
|
||||
is_aligned=is_aligned, force_slowpath=is_slowpath)
|
||||
ld_thunk(f"qemu_ld_beq_{subtype}", None, None, "helper_be_ldq_mmu",
|
||||
is_aligned=is_aligned, force_slowpath=is_slowpath)
|
||||
|
||||
|
||||
# Handlers for QEMU_ST, which handles guest -> host stores.
|
||||
for subtype in ('aligned', 'unaligned', 'slowpath'):
|
||||
is_aligned = (subtype == 'aligned')
|
||||
is_slowpath = (subtype == 'slowpath')
|
||||
|
||||
st_thunk(f"qemu_st_ub_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_ret_stb_mmu",
|
||||
fastpath_32b=["strb Wd, [Xn, x27]"], fastpath_64b=["strb Wd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
st_thunk(f"qemu_st_leuw_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_le_stw_mmu",
|
||||
fastpath_32b=["strh Wd, [Xn, x27]"], fastpath_64b=["strh Wd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
st_thunk(f"qemu_st_leul_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_le_stl_mmu",
|
||||
fastpath_32b=["str Wd, [Xn, x27]"], fastpath_64b=["str Wd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
st_thunk(f"qemu_st_leq_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_le_stq_mmu",
|
||||
fastpath_32b=["str Xd, [Xn, x27]"], fastpath_64b=["str Xd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
|
||||
# Special optimization for the most common modes.
|
||||
st_thunk(f"qemu_st_leq_{subtype}_mode3a", is_aligned=is_aligned, slowpath_helper="helper_le_stq_mmu",
|
||||
fastpath_32b=["str Xd, [Xn, x27]"], fastpath_64b=["str Xd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath, immediate=0x3a
|
||||
)
|
||||
|
||||
# For now, leave the rare/big-endian stuff slow-path only.
|
||||
st_thunk(f"qemu_st_beuw_{subtype}", None, None, "helper_be_stw_mmu",
|
||||
is_aligned=is_aligned, force_slowpath=is_slowpath)
|
||||
st_thunk(f"qemu_st_beul_{subtype}", None, None, "helper_be_stl_mmu",
|
||||
is_aligned=is_aligned, force_slowpath=is_slowpath)
|
||||
st_thunk(f"qemu_st_beq_{subtype}", None, None, "helper_be_stq_mmu",
|
||||
is_aligned=is_aligned, force_slowpath=is_slowpath)
|
||||
|
||||
|
||||
# Statistics.
|
||||
sys.stderr.write(f"\nGenerated {gadgets} gadgets with {instructions} instructions ({instructions * 4} B).\n\n")
|
||||
@@ -49,6 +49,7 @@
|
||||
#include "hw/boards.h"
|
||||
#endif
|
||||
|
||||
#include "tcg/tcg-apple-jit.h"
|
||||
#include "tcg/tcg-op.h"
|
||||
|
||||
#if UINTPTR_MAX == UINT32_MAX
|
||||
@@ -164,7 +165,7 @@ TCGv_env cpu_env = 0;
|
||||
const void *tcg_code_gen_epilogue;
|
||||
uintptr_t tcg_splitwx_diff;
|
||||
|
||||
#ifndef CONFIG_TCG_INTERPRETER
|
||||
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
|
||||
tcg_prologue_fn *tcg_qemu_tb_exec;
|
||||
#endif
|
||||
|
||||
@@ -1226,7 +1227,7 @@ void tcg_prologue_init(TCGContext *s)
|
||||
region.start = buf0;
|
||||
region.end = buf0 + total_size;
|
||||
|
||||
#ifndef CONFIG_TCG_INTERPRETER
|
||||
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
|
||||
tcg_qemu_tb_exec = (tcg_prologue_fn *)tcg_splitwx_to_rx(buf0);
|
||||
#endif
|
||||
|
||||
@@ -1252,7 +1253,7 @@ void tcg_prologue_init(TCGContext *s)
|
||||
#endif
|
||||
|
||||
buf1 = s->code_ptr;
|
||||
#ifndef CONFIG_TCG_INTERPRETER
|
||||
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
|
||||
flush_idcache_range((uintptr_t)tcg_splitwx_to_rx(buf0), (uintptr_t)buf0,
|
||||
tcg_ptr_byte_diff(buf1, buf0));
|
||||
#endif
|
||||
@@ -1980,7 +1981,7 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args)
|
||||
#endif
|
||||
|
||||
#if defined(__sparc__) && !defined(__arch64__) \
|
||||
&& !defined(CONFIG_TCG_INTERPRETER)
|
||||
&& !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
|
||||
/* We have 64-bit values in one register, but need to pass as two
|
||||
separate parameters. Split them. */
|
||||
int orig_sizemask = sizemask;
|
||||
@@ -2030,7 +2031,7 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args)
|
||||
pi = 0;
|
||||
if (ret != NULL) {
|
||||
#if defined(__sparc__) && !defined(__arch64__) \
|
||||
&& !defined(CONFIG_TCG_INTERPRETER)
|
||||
&& !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
|
||||
if (orig_sizemask & 1) {
|
||||
/* The 32-bit ABI is going to return the 64-bit value in
|
||||
the %o0/%o1 register pair. Prepare for this by using
|
||||
@@ -2108,7 +2109,7 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args)
|
||||
tcg_debug_assert(pi <= ARRAY_SIZE(op->args));
|
||||
|
||||
#if defined(__sparc__) && !defined(__arch64__) \
|
||||
&& !defined(CONFIG_TCG_INTERPRETER)
|
||||
&& !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
|
||||
/* Free all of the parts we allocated above. */
|
||||
for (i = real_args = 0; i < orig_nargs; ++i) {
|
||||
int is_64bit = orig_sizemask & (1 << (i+1)*2);
|
||||
@@ -4788,7 +4789,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
|
||||
return -2;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_TCG_INTERPRETER
|
||||
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
|
||||
/* flush instruction cache */
|
||||
flush_idcache_range((uintptr_t)tcg_splitwx_to_rx(s->code_buf),
|
||||
(uintptr_t)s->code_buf,
|
||||
|
||||
@@ -23,7 +23,16 @@
|
||||
#undef _FORTIFY_SOURCE
|
||||
#endif
|
||||
#include "qemu/osdep.h"
|
||||
#if defined(CONFIG_LIBUCONTEXT)
|
||||
#include <libucontext/libucontext.h>
|
||||
#define ucontext_t libucontext_ucontext_t
|
||||
#define getcontext libucontext_getcontext
|
||||
#define setcontext libucontext_setcontext
|
||||
#define swapcontext libucontext_swapcontext
|
||||
#define makecontext libucontext_makecontext
|
||||
#else
|
||||
#include <ucontext.h>
|
||||
#endif
|
||||
#include "qemu/coroutine_int.h"
|
||||
|
||||
#ifdef CONFIG_VALGRIND_H
|
||||
|
||||
@@ -39,6 +39,10 @@ extern int madvise(char *, size_t, int);
|
||||
#include "qemu/error-report.h"
|
||||
#include "monitor/monitor.h"
|
||||
|
||||
#ifdef CONFIG_DARWIN
|
||||
#include "tcg/tcg-apple-jit.h"
|
||||
#endif
|
||||
|
||||
static bool fips_enabled = false;
|
||||
|
||||
static const char *hw_version = QEMU_HW_VERSION;
|
||||
|
||||
Reference in new issue
Block a user