Skip to content

mac99: Mac OS X guest fixes (ATAPI, NVRAM, cpu-mhz, OHCI, tablet, gamepad) - #33

Open
brunocastello wants to merge 10 commits into
utmapp:utm-editionfrom
brunocastello:pr/mac99-macosx
Open

brunocastello wants to merge 10 commits into
utmapp:utm-editionfrom
brunocastello:pr/mac99-macosx

Conversation

@brunocastello

@brunocastello brunocastello commented Nov 27, 2026 •

Copy link
Copy Markdown

Mac OS X Tiger and Leopard on mac99 hit a few small device problems: the install DVD and CD drive misbehave, Mac OS X can't read the NVRAM, the reported CPU speed is fixed, USB stalls under load, and the tablet pointer doesn't line up on 10.4. This collects those fixes. Most of them come from Spartan0285/poweremu-qemu and linuxkid473/ppc-osx-vgpu (GPL-2.0-or-later); original authors are kept on the commits.

Changes

  • ide: answer the ATAPI questions Mac OS X asks (GET CONFIGURATION features, MODE SENSE(6)); new trace event ide_atapi_cmd_name.
  • macio-ide: a status read waits for the PIO sector still being read (fixes BootX hangs).
  • mac_dbdma: also clear io.len and current on reset, so a restart with I/O in flight doesn't leave a channel stuck.
  • hcd-ohci: bound TD processing per frame and drop missed frames instead of catching up forever.
  • mac99: cpu-mhz=N machine option (default 900, unchanged) and opt-in osx-nvram=on with an NVRAM layout Mac OS X can read. The default layout is unchanged byte for byte.
  • usb-tablet: opt-in abs-scale property to undo Tiger's tablet stretch (-global usb-tablet.abs-scale=11775).
  • ui/input: send button events to the device that got the motion, so a tablet click doesn't go to another pointer device.
  • hw/usb: opt-in poweremu-gamepad, a USB game controller Mac OS X 10.4 understands, fed by a host controller or a chardev.

Everything that changes behaviour for existing VMs is opt-in, except the IDE, DBDMA and OHCI fixes.

Testing

  • Tiger and Leopard on mac99 have been running with these changes in my UTM builds (boot, desktop, CD images, tablet, game controller).
  • This branch builds on macOS arm64 (ppc-softmmu); mac99 starts with all the new options. The SPICE part of the input change was not built in that CI run, but it's the same code that builds in my UTM builds.
  • Not tested: Linux or x86 hosts.

To be upfront: I built this with Claude (Anthropic) through Claude Code. The code and analysis are largely Claude's work; I directed it and tested it in my own VMs. Please review it with that in mind, and I'm happy to split it or change anything.

brunocastello and others added 10 commits November 27, 2026 22:10
An installed Mac OS X 10.4 maps USB tablet input onto a rectangle about
1.1775x the screen, centred, so the guest cursor drifts away from the
host pointer towards the edges (measured 1.176-1.18 with several display
devices). That breaks absolute pointer mode on Tiger.

abs-scale (units of 1/10000, default 0) shrinks absolute positions about
the centre of the range by that factor, which undoes the stretch, e.g.

  -global usb-tablet.abs-scale=11775

Opt-in: with the default of 0 (or any value up to 10000) positions are
passed through unchanged.

Signed-off-by: Bruno Castelló <bfcastello@gmail.com>
Assisted-by: Claude:claude-opus-5-5
Two ways the OHCI frame timer could livelock the main loop while holding
the BQL under host overload or a starved vCPU:

 - a TD list the guest has left circular was walked forever, so the
   guest could never repair it. At most 256 TDs per ED are now serviced
   per frame; the rest resume at the next frame.

 - after a host stall every missed 1 ms frame was replayed back to back,
   which never catches up when a frame costs more than 1 ms. Frames more
   than 10 behind are now dropped, as real hardware would.

Always on; no property.

Based on code from Spartan0285/poweremu-qemu (GPL-2.0-or-later).

Signed-off-by: Bruno Castelló <bfcastello@gmail.com>
Assisted-by: Claude:claude-opus-5-5
The clock-frequency handed to the firmware, and from there to the device
tree, About This Mac, hw.cpufrequency and applications' minimum-speed
checks, was fixed at 900 MHz. Make it a machine property:

  -machine mac99,cpu-mhz=2000

Accepted range is 100-4000. Only the reported value changes: the guest
times itself from the timebase and TCG speed is unaffected. Tiger 10.4.11
boots normally at 2000 and shows "2 GHz PowerPC G4".

Opt-in: the default is unchanged at 900 MHz.
Signed-off-by: Bruno Castelló <bfcastello@gmail.com>
Assisted-by: Claude:claude-opus-5-5
Mac OS X could not read any of this machine's NVRAM. The "options" node
matched IODTNVRAM but had no properties, so `nvram -p` failed, and so did
`bless --setBoot`, which reads boot-args through /usr/sbin/nvram and died
with a bus error - the last step of every Mac OS X install.

The two readers of the chip disagree. Mac OS X reads one byte per
address and takes the second 8 KB of the 16 KB window as a whole bank.
OpenBIOS reads one byte per address too, but takes every other byte as
its storage. The chip was 8 KB with a stride of two, which suits OpenBIOS
and makes Mac OS X read every byte twice, so it finds no partitions.

With osx-nvram the chip is 16 KB, addressed one byte per address, with
Open Firmware's bank written into the first half twice over (each byte at
both addresses its stride would read it from) and Mac OS X's bank in the
second half, now with the "common" partition IODTNVRAM matches on. In the
guest `nvram -p` lists the variables, `nvram boot-args=-v` reads back and
`bless --setBoot` succeeds; OpenBIOS still obeys auto-boot?=false.

  -machine mac99,osx-nvram=on

Opt-in: the layout changes the device size and stride, so it changes the
saved-state layout and what Mac OS 9 reads. By default (and for the
OldWorld machines) the original layout is kept byte for byte.

Based on code from Spartan0285/poweremu-qemu (GPL-2.0-or-later).

Signed-off-by: Bruno Castelló <bfcastello@gmail.com>
Assisted-by: Claude:claude-opus-5-5
Finding out what a guest asks an ATAPI drive for is hard when the answer
is a hex dump: a command the drive does not implement shows up only as a
number. Add the ide_atapi_cmd_name trace event, which names each packet
command (the whole MMC set a burner is asked, not just the implemented
subset) and says whether a handler exists, so an unimplemented command
appears by name and in the order the guest wanted it.

Off unless the trace event is enabled; no behaviour change.

Based on code from Spartan0285/poweremu-qemu (GPL-2.0-or-later).

Signed-off-by: Bruno Castelló <bfcastello@gmail.com>
Assisted-by: Claude:claude-opus-5-5
The ATAPI trace shows what Mac OS X sends a CD drive that QEMU could not
answer:

 - GET CONFIGURATION refused every feature but 0, and Mac OS X asks for 0
   and then 1, so the second question got ILLEGAL REQUEST. It now honours
   the request type field (all, current, or the one feature named) and
   answers for the Profile List, Core, Removable Medium and Random
   Readable features.

 - MODE SENSE(6) was not implemented at all, and Mac OS X uses it as well
   as (10). The pages are now built in one place so the two cannot drift.

The answer is built in full and truncated to the allocation length on the
way out, not while building: an initiator asks once with a small buffer
to learn the length and again with room for it, and truncating early
made the first answer say the drive had no features, which panicked the
guest.

Always on; no property.

Based on code from Spartan0285/poweremu-qemu (GPL-2.0-or-later).

Signed-off-by: Bruno Castelló <bfcastello@gmail.com>
Assisted-by: Claude:claude-opus-5-5
OpenBIOS gives a drive 5 s of timebase (host wall clock) per status wait
while QEMU completes PIO sector reads asynchronously. One slow host read
therefore left BootX reading a half-read sector and hanging at the grey
Apple. A status read (and alternate status) now waits for an in-flight
PIO request; DMA and a guest-held SRST are excluded. Measured with host
reads throttled: 4 of 6 boots hung before, 0 of 6 after, and cold boot to
login went from 150 s to 51 s.

Also clear dma_active on device reset, so a reset taken mid-DMA does not
leave the new boot looking busy.

Always on; no property.

Based on code from linuxkid473/poweremu-qemu 56e6984633
(GPL-2.0-or-later).

Signed-off-by: Bruno Castelló <bfcastello@gmail.com>
Assisted-by: Claude:claude-opus-5-5
A reset during a transfer (guest restart with disk or sound DMA in
flight) left a channel's transfer length and current command behind.
mac_dbdma_reset already clears io.processing; also clear io.len and the
current command so the next boot starts from a clean channel.

Reset path only; the transfer paths are untouched. Always on.

Based on code from linuxkid473/poweremu-qemu 56e6984633
(GPL-2.0-or-later).

Signed-off-by: Bruno Castelló <bfcastello@gmail.com>
Assisted-by: Claude:claude-opus-5-5
With both a USB mouse and a USB tablet in the guest, a click could reach
the guest through whichever device was polled last, landing where the
pointer used to be. Add qemu_input_handler_activate_kind(), which brings
the first handler taking absolute (or relative) motion to the front, and
call it from the SPICE mouse and tablet motion handlers so the buttons
follow the position.

Always on for the SPICE display; no property.

Based on code from linuxkid473/ppc-osx-vgpu and Spartan0285/poweremu-qemu
a86b33dabc (GPL-2.0-or-later).

Signed-off-by: Bruno Castelló <bfcastello@gmail.com>
Assisted-by: Claude:claude-opus-5-5
A host game controller given to the guest as a USB gamepad: sixteen
buttons, two sticks, two triggers and a hat. A host program sends nine
bytes whenever something moves, over a Unix socket or a chardev:

  -device poweremu-gamepad,path=/tmp/pad.sock
  -device poweremu-gamepad,chardev=pad0

Most of the work is in the report descriptor, because 10.4's HID parser
is not the one in a modern Mac. It wants the three-byte form of Logical
Maximum for a 0-255 axis (the one-byte form reads 255 as -1 and inverts
every axis), has no use for report IDs, and wants byte-aligned padding.
The vendor id is pid.codes' rather than Apple's or Logitech's, which the
system handles specially.

The device NAKs while nothing has changed, as a real gamepad does. With
path= it redials every couple of seconds so a controller can be paired,
or the host program restarted, with the guest running. chardev= exists
for front ends that cannot pass a Unix socket path (UTM's lie past the
sun_path limit and its channels run over SPICE ports); the reading in
progress is dropped when the other end connects or goes away and the
controls are released when it goes away.

Opt-in: nothing happens unless the device is added.

Based on code from Spartan0285/poweremu-qemu (Copyright (c) 2026
Spartan0285, GPL-2.0-or-later).

Signed-off-by: Bruno Castelló <bfcastello@gmail.com>
Assisted-by: Claude:claude-opus-5-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants