Skip to content

Add the Mixed Mode ABI service, checked against Mac OS 9.2.2 - #49

Merged
colemancda merged 9 commits into
masterfrom
feature/mixed-mode
Dec 1, 2026
Merged

colemancda merged 9 commits into
masterfrom
feature/mixed-mode

Conversation

@colemancda

Copy link
Copy Markdown
Member

Adds a GraphiteMixedMode target that decodes routine descriptors and procedure information, and decides what a universal procedure pointer calls, as data for the host to run. A new Retro68 probe captured Mac OS 9.2.2's behavior, and the tests check Graphite against it. This is the Mixed Mode half of stage 5 in the BlueBox requirements: descriptor format and selection move into Graphite, and the host keeps CPU invocation.

What Mac OS 9.2.2 showed

The capture is ReferenceTests/Retro68/MixedMode-macos-9.2.2-ppc.txt, summarized in the Retro68 README. It covers CallUniversalProc called from PowerPC code.

  • Record choice: with one record, record 0 runs. With more than one, record 1 always runs, whatever the records' ISAs, flags and selectors or the descriptor's flags say. A [PowerPC, 68k] descriptor ran its 68k code. Rewriting a descriptor in place changed what ran, so this isn't caching by address.
  • No dispatching: the selector reached the target as its first argument, kDontPassSelector or not. A selector no record had, with no default, ran record 0.
  • Descriptor bytes:
    • NewRoutineDescriptor writes 32 bytes: one record with kUseNativeISA and the ISA byte as given, even 02, 10 or 11. A nil procedure gives nil with MemError 0.
    • NewFatRoutineDescriptor writes 52 bytes: a 68k record, then a PowerPC one, with no flags.
  • Targets:
    • 68k code passed without a descriptor runs as 68k.
    • A relative 68k target is an offset from the descriptor's start.
    • A relative PowerPC target that isn't marked as needing preparation crashed (type 3).

Changes

  • ProcedureInformation decodes ProcInfo words into stack, register-based, dispatched and special-case layouts, following Inside Macintosh's bit layout. It rejects unknown conventions, registers and special cases, and bits after the last parameter.
  • RoutineDescriptor reads and writes the guest format: a 12-byte header and 20-byte records, big-endian. It rejects other trap words, versions other than 7, negative routine counts and truncated input.
  • MixedMode:
    • resolves a universal procedure pointer in guest memory to a MixedModeInvocation: a 68k entry point, a PowerPC transition vector, or a fragment still to be prepared.
    • also provides NewRoutineDescriptor, NewFatRoutineDescriptor and DisposeRoutineDescriptor over HeapZone.
    • always reports a 68k routine as 68k, never as PowerPC code.

For reviewers

  • Mac OS 9's rules, not the documented ones. Record selection follows the capture, not Inside Macintosh's documented dispatch semantics, since the capture is the reference.
  • Throws instead of guessing:
    • the relative PowerPC target that crashed Mac OS 9;
    • CFM-68k and unknown ISAs;
    • preparation without a relative target;
    • versions other than 7.
  • Not covered:
    • 68k callers, which reach a descriptor through its trap word and may dispatch differently;
    • PowerPC fragments that need preparing.
  • Why the probe has a reuse section: the probe ran twice. The first run freed its descriptors between calls, so its "always record 1" result could have been caching by address. The second run keeps every descriptor at its own address and rewrites one in place, which rules that out.

Testing

swift test passes: all 16 test runs, including 11 new GraphiteMixedModeTests. The byte-layout tests parse the capture's descriptor dumps directly.

@colemancda
colemancda merged commit 31796df into master Dec 1, 2026
3 checks passed
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.

1 participant