Skip to content

The emulator against the hardware

The original firmware and Chikuma boot the same disk on the same emulated machine, so their differences can be measured. That holds only while the emulator refuses what the real iPod refuses. Each time the model forgave something the hardware would not, a bug passed every test and turned up on the device with nothing to reproduce it. This page lists those gaps, closed and open.

The rule

A bug that reproduces only on the device means the model accepts something the device refuses.

  1. Reproduce the device's symptom in the emulator, from a cold start. If it passes there, the model is wrong, and that comes first.
  2. Tighten the model until a cold start fails the same way the device does.
  3. Fix the code, and confirm that both pass.

An audio stutter, an accessory interrupt that never arrived and a panel that stayed dark all fall in that class. A stricter emulator shows each of them in minutes.

Why a cold start

For day-to-day work the emulator can start a bare OS image with every clock already running and the panel already reset. That saves time, and it hides code that relies on a block it never switched on. A cold-start flag runs the same image from the state the boot ROM leaves the machine in. Anything that touches the boot path runs that way.

Differences the model now reproduces

Each of these let a bug through to the device until the model changed.

Unaligned accesses

The boot ROM hands over with alignment checking on, so the CPU faults on an unaligned load or store. The emulator used to start bare images with it off, and so forgave every one of them. That gap is what broke audio on the device. Images now start with checking on, in the emulator and on the device alike.

A timer on the wrong line

The model raised every timer interrupt on one line, and the bootloader's tick is on the other. The bootloader's interrupt path therefore never ran until it ran on the device, where it hung with a dark screen. The lines are split now, as the hardware has them.

What sits at address 0

With the MMU off, a stray interrupt vectors through physical address 0. The model had RAM there. Reading the device showed the boot ROM mirrored across the whole region, and the model now has the mirror. The failure it produces matches the device's.

AES and clock gates

The model did a whole decrypt the moment a job started, so a bootloader that did not wait for the job to finish still passed. On the device the job takes a fifth of a second, and that bootloader went on with most of the OS image still unreadable.

Two more facts come from the device since. The engine has a busy bit, and gating its clock under a running job freezes the job. The model now refuses writes to a block whose clock is gated, for the panel, the I2C bus, AES and the video decoder.

USB

What The hardware The model used to
arming an endpoint that was never activated stalls accept it silently, and now warns
a bus reset clears every endpoint's registers clear only the link state
a 512-byte bulk packet is one packet of a transfer complete the whole transfer, so a 4 KiB write delivered one good packet and seven stale ones

A transfer now completes when its armed size drains or when a short packet ends it.

The audio DSP's handshake

The model answered "ready" to any command. The device answers only to the right sequence, so code that skipped the original's handshake passed in the emulator and failed on the device. The model now wants the sequence, and its ready flag comes out of reset at the value the device reads.

The same block had a second gap. The model has no data cache, so buffers the DSP reads through the cache looked fine in the emulator. Chikuma now writes them through the uncached view of memory, as the original does.

A 4 KiB drive

The drive in the development unit refuses any command that does not cover a whole 4 KiB physical sector, and the model accepted 512-byte writes. The model has a mode that refuses them now, and Chikuma's writes are whole-sector read-modify-write cycles.

Saved states

Restoring a saved machine has to bring back everything the hardware holds. A DMA channel the model did not rebuild from its registers stalled the original's sound engine, and with it the hand-over of the disk to USB. A restore without the CPU's control registers looked alive and never scheduled its tasks again. Both are carried now.

Differences the model still has

Gap What the model does Known effect
the audio DSP's run state treats the block as always running, ignores the enable registers
USB interrupt latches sets some raw interrupt bits unconditionally, where the hardware gates them at the source none traced yet
USB completion timing raises the line in the same instant as the transfer, where real completion lags by a few bus cycles
GPIO inputs returns the last value written, not the level outside the chip doing it right needs an external level per pin, deferred
the MMU and caches runs bare images identity-mapped with caches off, where the real chain leaves translation on and the data cache dirty none traced yet, though a cache cleaned on one way of four has turned up on the device once
clock gates for the other blocks does not tie their gate bits to the code that uses them yet

Adding to it

When a failure on the device traces back to a gap in the model, it goes on this page with the symptom, what the hardware does, the model fix and the commit. Bring-up on a real iPod covers the boot-chain side, and the device models describes the emulator.