68k

Notes on old Macs, repairs, and other projects.

7 min read

Starting A/UX from System 7.5.5

Once A/UX was running on the Carrera040, my next annoyance was getting into it. The SE/30 normally runs System 7.5.5 from the nuCF card, and A/UX lives in another partition on the same card. I don’t, necessarily, want to boot into A/UX every time.

The A/UX loader typically expects memory to be available at specific locations, and starting with extensions on tends to break this. Starting with extensions off means the Carrera040 isn’t loaded, so now A/UX needs to kick-start the 040 itself. Secondly, the nuCF mapping was handled by an extension before, so now we need the A/UX loader to also map it to a fake SCSI drive for loading purposes.

A/UX Startup finds the card itself

The new A/UX Startup carries the same shim code as the NuCF SCSI extension in an extra code segment, and installs it when it starts. With extensions off it puts the card on the SCSI bus as ID 6 by itself; with the extension loaded it sees that the shim is already there and doesn’t install it twice. You’re not really supposed to load extensions post-boot, but nothing really stops you from doing it.

A/UX Startup, launch and its bin folder just go on the 7.5.5 disk. Nothing else is needed in the System Folder.

The kernel starts the 68040

MicroMac’s driver starts the 68040 by copying a small reset stub to physical address 0 and writing 1 to the card’s control register at $53000000. The card parks the 68030 and brings the 68040 out of reset, which picks up its stack pointer and program counter from the stub. Writing 0 hands control back to the 68030, which carries on right after its own write.

The A/UX kernel now does the same thing itself, first thing at its entry point, before the MMU is on:

  1. Decide the mode. The kernel stores a default (68030, MED or FAST), and A/UX Startup can override it for one boot (see below).
  2. Check it’s still on the 68030. The 68030 has a CACR bit the 68040 doesn’t, so setting it and reading it back tells them apart. If the Carrera extension already started the 68040, there’s nothing to do except set the cache mode.
  3. Check there’s a Carrera. Reading the control register returns the card’s jumpers, and bus-errors if there’s no card. A temporary vector table catches the bus error, and the jumpers have to say there’s a 68040 with an FPU, since A/UX needs one.
  4. Save the bottom of memory, write the reset stack and PC, and point every exception vector at a fallback.
  5. Flush and turn off the 68030’s caches, and write 1 to the control register.

The 68040 comes up with the MMU and caches off and a supervisor stack, puts the bottom of memory back, and enters the kernel with exactly the registers the 68030 had. From there the kernel starts as if A/UX Startup had launched it on the 68040, using the hackery we got into before.

If anything goes wrong first, the fallback vectors write 0 to the control register. The 68030 wakes up after its write, restores memory, and A/UX starts on the 68030 instead.

The mode is a byte in the kernel, set with se30patch -m 030|med|fast or by newconfig. It also decides the 68040’s cache mode when the Carrera extension started it, which turned out to matter.

It worked in the emulator

In QEMU it booted to the A/UX Finder on the first try. On the real machine it crashed or hung, in a different place almost every run.

The CF card is inside the Mac, and taking it out means taking the Mac apart. So the bot wrote A/UX Kernel Switch, a Mac OS app that finds the nuCF card, finds the A/UX kernel in its partition, and rewrites it in place. It only writes after checking that every byte it changes holds a version it knows, and reads the result back. Each version added either one fix or one diagnostic, and I’d restart with extensions off and take a photo of whatever happened. Having already jostled things with an out-of-town trip the Mac came along for (JawnCon!) and reseating things that apparently got loose, I’d rather spend time taking photos than stripping the SE/30 and reseating everything again.

  • The slot probe, again. The 68040 probe handler only handled faults on slot addresses. Some faults during the scan were elsewhere, with the ROM’s recovery address in a2, and the scan hung on them.
  • A wild jump. One photo showed the Slot Manager jumping to $04000000, just past the end of RAM: the block of card start-up code it had been handed pointed at the last 8 bytes of memory instead of the block the kernel had just allocated. The kernel now runs that Slot Manager call itself, and uses the block it allocated if the pointer it got back is nonsense.
  • A hang reading the card. Console lines through the nuCF driver showed the 68040’s transparent translation registers still set the way the slot scan sets them, which leaves slot $D unmapped. The scan had never come back through its own exit code. The driver now cleans up after it.
  • The real cause. Logging every exception during the slot scan showed the real machine taking exactly the emulator’s 13 probe faults, then hanging with no further exception. Ultimately this is very close to the original hangs with A/UX from before: the BMOW ROM is IIsi-derived, and the IIsi only ever had a 68030. Its Slot Manager copies card code into RAM and jumps to it without pushing the 68040’s caches, so the 68040 could execute whatever stale data was in its cache instead of the code just copied. Any crash, hang or wild jump, different every run. The kernel already turned the caches off for the scan on a 68030 and left them alone on a 68040; now they’re pushed and off on both until the kernel’s own cache setup turns them back on.
  • FAST mode. The last crashes, Finder bus errors and random hangs, were copyback mode. FAST has corrupted memory on this machine under Mac OS too (several times the mouse cursor has corrupted during A/UX loading). With MED (write-through), A/UX reaches the Finder from 7.5.5 with extensions off, and from the old launch disk.

Kernel Switch only knows the kernels it was built against. The fixes are all in se30patch 2.1 now, so a kernel built by newconfig gets them too, and its settings are changed with se30patch inside A/UX.

Setting it up

The A/UX side needs se30patch 2.1 installed and a kernel built with it; see the kit. Then copy A/UX Startup, launch and bin to the top level of the 7.5.5 disk, and set A/UX Startup’s AutoLaunch command (Preferences) to:

launch -n -k 0x0200

Note the -n. Without it, when A/UX Startup decides the kernel’s drivers don’t match the cards it can see, it quietly boots /newunix instead (the stock 1994 kernel) to rebuild things, and that kernel can’t start on the Carrera.

-k sets options for one boot, added together:

Flag Effect
0x100 stay on the 68030
0x200 68040, MED (write-through)
0x400 68040, FAST (copyback); corrupts memory here
0x800 no SCSI bus scan
0x1000 SCSI bus scan
0x2000 leave cards in the other slots out of the slot scan

The same flags can be typed at A/UX Startup’s prompt after cancelling the AutoLaunch, which is handy for trying something once.

Switching is now:

  • To A/UX: restart holding Shift until “Extensions Off” shows up, then open A/UX Startup.
  • Back to 7.5.5: shut down A/UX and start up normally. The Carrera extension loads as usual and Mac OS gets the 68040 too.

Fast mode would be nice

Right now I’m reveling in it actually working, but it would be nice to figure out why the 040-fast mode corrupts so badly when it’s still usable on mac OS.