@@ -504,7 +504,9 @@ function configure_cpu() {
504504 if [ " ${ARCH_VM} " == " aarch64" ]; then
505505 # ARM64 guest support
506506 # https://qemu-project.gitlab.io/qemu/system/arm/virt.html
507- # highmem=on allows RAM above 4GB (required for VMs with >3GB RAM)
507+ # highmem=on allows aarch64 guests on the "virt" machine type to access guest RAM
508+ # above the 4GB boundary. This is required for VMs configured with >3GB RAM and is
509+ # generally more compatible on modern aarch64 systems.
508510 # pflash0/pflash1 reference the blockdev nodes for AAVMF firmware
509511 MACHINE_TYPE=" virt,highmem=on,pflash0=rom,pflash1=efivars"
510512 case ${ARCH_HOST} in
@@ -518,15 +520,28 @@ function configure_cpu() {
518520 esac
519521 elif [ " ${ARCH_VM} " != " ${ARCH_HOST} " ]; then
520522 # If the architecture of the VM is different from the host, disable acceleration
523+ # and use TCG (Tiny Code Generator) software emulation. TCG emulates the target
524+ # architecture in software, allowing cross-architecture virtualisation (e.g.,
525+ # running x86_64 VMs on ARM hosts).
526+ #
527+ # Users can manually force TCG mode by adding this to their VM .conf file:
528+ # cpu_model="qemu64"
529+ # extra_args="-accel tcg"
530+ # or by exporting QEMU_ACCEL in the shell environment:
531+ # export QEMU_ACCEL="tcg"
532+ #
533+ # TCG is useful for:
534+ # - Cross-architecture virtualisation (x86 on ARM, ARM on x86)
535+ # - Testing VMs on hosts without hardware virtualisation support
536+ # - Emulating CPU features in software (e.g., running macOS x86_64 VMs on ARM Macs)
521537 CPU_MODEL=" qemu64"
522538 CPU_KVM_UNHALT=" "
523539 QEMU_ACCEL=" tcg"
524540 fi
525541
526- # TODO: More robust detection of running in a VM
527- # - macOS check for CPU flag: vmx
528- # - Linux AMD check for CPU flag: svm
529- # - Linux Intel check for CPU flag: vmx
542+ # Detect if running inside a VM based on manufacturer detection
543+ # Note: Checking CPU flags (vmx/svm) indicates hardware virtualisation SUPPORT,
544+ # not whether we're inside a VM. Nested virtualisation may expose these flags.
530545 case ${MANUFACTURER,,} in
531546 qemu|virtualbox) CPU_MODEL=" qemu64"
532547 QEMU_ACCEL=" tcg"
@@ -549,8 +564,10 @@ function configure_cpu() {
549564 fi
550565 elif [ " ${ARCH_HOST} " == " aarch64" ] || [ " ${ARCH_HOST} " == " arm64" ]; then
551566 # ARM hosts running native ARM guests with hardware acceleration (HVF on macOS, KVM on Linux)
552- # ARM processors don't have x86-specific virtualisation flags (VT-x/SVM) to check
553- # Cross-architecture guests (x86 on ARM) use TCG and skip this validation block entirely
567+ # ARM processors don't have x86-specific virtualisation flags (VT-x/SVM) to check.
568+ # We use architecture detection here instead of vendor detection (used for x86)
569+ # because ARM CPUs don't have standardised vendor strings like x86 (GenuineIntel/AuthenticAMD).
570+ # Cross-architecture guests (x86 on ARM) use TCG and skip this validation block entirely.
554571 # No validation needed here - ARM virtualisation support is handled by the hypervisor
555572 true
556573 else
@@ -603,7 +620,8 @@ function configure_cpu() {
603620 # A CPU with fma is required for Metal support
604621 # A CPU with invtsc is required for macOS to boot
605622 # Skip CPU feature checks when using TCG emulation (cross-architecture)
606- # as QEMU will emulate the required x86 features in software
623+ # as TCG will emulate the required x86 features in software. This enables
624+ # running macOS x86_64 VMs on ARM Macs through software emulation.
607625 if [ " ${QEMU_ACCEL} " != " tcg" ]; then
608626 case ${macos_release} in
609627 ventura|sonoma|sequoia|tahoe)
@@ -1294,6 +1312,10 @@ function configure_display() {
12941312 # Map Quickemu $display to QEMU -display
12951313 case ${display} in
12961314 cocoa)
1315+ # macOS: prefer OpenGL ES (via ANGLE) for stability and performance
1316+ # ANGLE provides OpenGL ES on macOS through Metal, which is more stable
1317+ # than the deprecated native OpenGL implementation
1318+ # Reference: https://gist.github.com/akihikodaki/87df4149e7ca87f18dc56807ec5a1bc5
12971319 if [ " ${gl} " == " on" ] && check_cocoa_gl_es_support; then
12981320 DISPLAY_RENDER=" ${display} ,gl=es"
12991321 gl=" es"
@@ -1309,6 +1331,8 @@ function configure_display() {
13091331 esac
13101332
13111333 # https://www.kraxel.org/blog/2021/05/virtio-gpu-qemu-graphics-update/
1334+ # For GL-enabled displays, check if dedicated GL device variants are available.
1335+ # Note: virtio-gpu-pci becomes virtio-gpu-gl-pci (not virtio-gpu-pci-gl)
13121336 if [ " ${gl} " != " off" ] && [[ " ${DISPLAY_DEVICE} " =~ ^virtio-(vga| gpu| gpu-pci)$ ]]; then
13131337 local GL_DEVICE=" "
13141338 case " ${DISPLAY_DEVICE} " in
@@ -1334,6 +1358,8 @@ function configure_display() {
13341358 fi
13351359
13361360 # Set display resolution for devices that support xres/yres parameters
1361+ # Use (,|$) anchor to match device names with or without comma-separated parameters
1362+ # Pattern ordered most-specific to least-specific for clarity (vga-gl before vga, etc.)
13371363 if [[ " ${DISPLAY_DEVICE} " =~ ^(virtio-(vga| vga-gl| gpu| gpu-gl| gpu-pci| gpu-gl-pci)| qxl| qxl-vga| bochs-display)(,| $) ]]; then
13381364 VIDEO=" ${VIDEO} ,xres=${X_RES} ,yres=${Y_RES} "
13391365 echo " @ (${X_RES} x ${Y_RES} )"
@@ -1342,6 +1368,9 @@ function configure_display() {
13421368 fi
13431369
13441370 # Allocate VRAM to VGA devices
1371+ # Note: virtio devices (virtio-vga, virtio-gpu-pci, and their -gl variants) use
1372+ # dynamic memory management and don't require explicit VRAM allocation via parameters.
1373+ # They use QEMU's default max_hostmem setting (256 MiB) which is sufficient for most use cases.
13451374 case ${DISPLAY_DEVICE} in
13461375 bochs-display) VIDEO=" ${VIDEO} ,vgamem=67108864" ;;
13471376 qxl|qxl-vga) VIDEO=" ${VIDEO} ,ram_size=65536,vram_size=65536,vgamem_mb=64" ;;
@@ -1618,6 +1647,9 @@ function vm_boot() {
16181647 fi
16191648
16201649 # Build machine arguments - SMM and vmport are x86-only options
1650+ # SMM (System Management Mode) is an x86-specific CPU mode used for firmware operations
1651+ # and is required for Secure Boot. ARM64 uses different mechanisms for firmware security.
1652+ # vmport emulates VMware's I/O port for guest tools, which is also x86-specific.
16211653 if [ " ${ARCH_VM} " == " aarch64" ]; then
16221654 # ARM64 uses 'virt' machine type without x86-specific options
16231655 # shellcheck disable=SC2054,SC2206,SC2140
0 commit comments