AppleSilicon/qemu/replay/replay-input.c
Youssef 26710d37c7 orchard: macOS on QEMU, on a Linux host
Boots an arm64 macOS guest on QEMU/TCG on Linux through the genuine Apple
chain -- AVPBooter -> iBootStage1 -> iBootStage2 -> stock XNU -- and renders
its desktop on the host's Vulkan.

QEMU (1044 lines over 18 files, 8 new):

  * the `apple-vm` machine: Apple-style timer-on-FIQ wiring, the paravirtual
    GPU device, a PAC master key installed across CPUs, and GICv2m's
    `macos-compat` bit, without which macOS will not use the MSI frame;
  * `bdif` NVRAM block writes. Upstream drops them, so a guest could never
    persist a boot variable and every install phase repeated forever;
  * `cfg`'s guest-visible random seed at its fixed offset;
  * Apple pointer authentication under TCG: the register definitions come
    from ChefKissInc/Inferno, the per-core key snapshot and the PSCI CPU_ON
    key inheritance (restricted to a kernel caller by testing that its pc is
    in the TTBR1 half) are ours. Without them secondaries run keyless and the
    first cross-core authentication recurses through its own panic path;
  * portability work upstream has not needed before: CONFIG_VMAPPLE was gated
    on HVF and shipped off, hw/vmapple/aes.c has a VLA that only compiled
    under clang, and the architectural op1-to-minimum-EL assertion rejects
    Apple's IMPDEF registers.

The GPU is steelbrain/reims-vgpu, carried as a submodule pinned to the commit
this was tested against; the two changes it needs are in patches/reims-vgpu/.
The AVPBooter patch is NyanSatan's, from Virtual-iBoot-Fun.

Nothing Apple ships is in this repository. The macOS image is fetched from a
public tart image, and Apple's VM firmware is extracted from that image, where
Virtualization.framework carries it -- so no Mac is involved in the setup.

Measured on the reference host: desktop in 75 s at 12 vCPUs and 10 GB.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Youssef <soosef.youssef@gmail.com>
2026-09-20 00:53:26 +03:00

113 lines
3.1 KiB
C

/*
* replay-input.c
*
* Copyright (c) 2010-2015 Institute for System Programming
* of the Russian Academy of Sciences.
*
* 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 "system/replay.h"
#include "replay-internal.h"
#include "qemu/notify.h"
#include "ui/input.h"
#include "qapi/clone-visitor.h"
#include "qapi/qapi-visit-ui.h"
void replay_save_input_event(QemuInputEvent *evt)
{
replay_put_dword(evt->type);
switch (evt->type) {
case INPUT_EVENT_KIND_KEY:
replay_put_dword(evt->key.key);
replay_put_byte(evt->key.down);
break;
case INPUT_EVENT_KIND_BTN:
replay_put_dword(evt->btn.button);
replay_put_byte(evt->btn.down);
break;
case INPUT_EVENT_KIND_REL:
replay_put_dword(evt->rel.axis);
replay_put_qword(evt->rel.value);
break;
case INPUT_EVENT_KIND_ABS:
replay_put_dword(evt->abs.axis);
replay_put_qword(evt->abs.value);
break;
case INPUT_EVENT_KIND_MTT:
replay_put_dword(evt->mtt.type);
replay_put_qword(evt->mtt.slot);
replay_put_qword(evt->mtt.tracking_id);
replay_put_dword(evt->mtt.axis);
replay_put_qword(evt->mtt.value);
break;
case INPUT_EVENT_KIND__MAX:
/* keep gcc happy */
break;
}
}
QemuInputEvent *replay_read_input_event(void)
{
QemuInputEvent *evt = g_new(QemuInputEvent, 1);
evt->type = replay_get_dword();
switch (evt->type) {
case INPUT_EVENT_KIND_KEY:
evt->key.key = replay_get_dword();
evt->key.down = replay_get_byte();
break;
case INPUT_EVENT_KIND_BTN:
evt->btn.button = (InputButton)replay_get_dword();
evt->btn.down = replay_get_byte();
break;
case INPUT_EVENT_KIND_REL:
evt->rel.axis = (InputAxis)replay_get_dword();
evt->rel.value = replay_get_qword();
break;
case INPUT_EVENT_KIND_ABS:
evt->abs.axis = (InputAxis)replay_get_dword();
evt->abs.value = replay_get_qword();
break;
case INPUT_EVENT_KIND_MTT:
evt->mtt.type = (InputMultiTouchType)replay_get_dword();
evt->mtt.slot = replay_get_qword();
evt->mtt.tracking_id = replay_get_qword();
evt->mtt.axis = (InputAxis)replay_get_dword();
evt->mtt.value = replay_get_qword();
break;
case INPUT_EVENT_KIND__MAX:
/* keep gcc happy */
break;
}
return evt;
}
void replay_input_event(QemuConsole *src, QemuInputEvent *evt)
{
if (replay_mode == REPLAY_MODE_PLAY) {
/* Nothing */
} else if (replay_mode == REPLAY_MODE_RECORD) {
QemuInputEvent *clone = g_new(QemuInputEvent, 1);
*clone = *evt;
replay_add_input_event(clone);
} else {
qemu_input_event_send_impl(src, evt);
}
}
void replay_input_sync_event(void)
{
if (replay_mode == REPLAY_MODE_PLAY) {
/* Nothing */
} else if (replay_mode == REPLAY_MODE_RECORD) {
replay_add_input_sync_event();
} else {
qemu_input_event_sync_impl();
}
}