SE/30 + Carrera040 in-system kernel patcher for A/UX 3.1  -  version 2.1 (2026-11-17)
=====================================================================================

New in 2.1
  - Fixes a 2.0 bug: a few instruction words in the patch code (movec, constants) were
    taken for kernel addresses and moved with the kernel's layout.  A kernel built
    with a different set of drivers than mine (e.g. with ae6, the Ethernet driver)
    got them wrong and panicked at startup ("unexpected kernel trap").  2.1 keeps them
    as they are; checked against kernels built with and without ae6.
  - A/UX Startup: use "launch -n" (in Preferences > Booting, AutoLaunch command, with
    any -k flags you use: "launch -n -k 0x0200").  Without -n, when A/UX Startup
    thinks the kernel's drivers don't match the cards it sees, it quietly starts
    /newunix (the stock kernel, which can't start on the Carrera040): a gray screen.

New in 2.0
  - Kernels newconfig builds get every fix Kernel Switch 1.18 has (slot-probe recovery,
    the kernel's own sExec, the scan clean-up at the nuCF driver, 68040 caches off for
    the slot scan) and the 1.18 start code, so a newconfig kernel starts from Mac OS
    with extensions off like the Kernel Switch one.  Mode default: med.
  - newconfig asks about the cards in the other slots (Ethernet).  -l on|off.
  - The startup autoconfig is safe: at every boot /etc/sysinitrc runs
    "autoconfig -a", which rebuilds /unix and restarts when the slot scan finds a card
    the kernel has no driver for (the Ethernet card, once the scan sees it).  That
    rebuilt kernel had no patches and could not start.  Now autoconfig runs
    /etc/se30acfg just before that restart, which patches the new /unix with the
    settings the old one had (sysinitrc saves them in /etc/se30patch.boot).
  - "launch -k 0x2000": leave the cards in the other slots out for one boot (if a
    card's ROM read hangs the slot scan).
  - A kernel newconfig built is not one Kernel Switch knows: from then on change its
    settings with se30patch or newconfig in A/UX, or for one boot with launch -k.

A/UX only starts on the SE/30 + Carrera040 (BMOW ROM) with a set of kernel patches.
Until now they were applied from outside, with Python tools on the disk image.
se30patch applies the same patches from inside A/UX, and newconfig now asks to apply
them to every kernel it builds (and for the Carrera mode, the nuCF card's SCSI ID and
the SCSI scan), so you don't need to take the drive out.

Install:

 1. Get se30patch.tar onto the A/UX disk.  In Mac OS, copy it from the BlueSCSI
    disk "SE30fix" (or wherever you put it) to the card's "nuCF Boot" volume;
    start A/UX; in the A/UX Finder drag it from "nuCF Boot" onto the "/" disk icon.
 2. In CommandShell, as root:

    /mac/bin/fcnvt -p /se30patch.tar /tmp/se30patch.tar
    cd /tmp
    tar xf se30patch.tar
    sh se30/install.sh

    (The Finder stores a copied Mac file with a 512-byte AppleSingle header in
    front; fcnvt -p takes it off.  A tar file that came over the network or with
    ftp doesn't need that step.)

install.sh puts in place (2.0: install over an older version the same way):
    /etc/se30patch               the patcher
    /etc/newconfig               asks "Apply them to the new kernel now? [y]" and
                                 "Scan the SCSI bus at startup?" after it builds a
                                 kernel, and patches it before it replaces /unix
                                 (newconfig.add and newconfig.call go into the stock
                                 A/UX 3.1 script, which is kept as /etc/newconfig.orig;
                                 an older patched newconfig is rebuilt from that copy)
    /etc/install.d/boot.d/nucf   the nuCF driver that lets the Mac environment mount
                                 the card's HFS volumes (old one kept as nucf.orig)
    /etc/se30acfg                patches a kernel the startup autoconfig rebuilt
    /etc/autoconfig              runs /etc/se30acfg in place of /etc/macquery before
                                 its restart (old one kept as /etc/autoconfig.orig)
    /etc/sysinitrc               saves /unix's settings in /etc/se30patch.boot before
                                 autoconfig runs (old one kept as /etc/sysinitrc.orig)
and then runs /etc/se30patch /unix.  On a kernel that is already patched that only
reports "36 of 36 SE/30 Carrera040 patches present" (a Kernel Switch Diagnostic
kernel isn't recognised and is left alone; that's fine, newconfig builds a new one).

Using it:

    /etc/se30patch -c            report what /unix has; change nothing
    /etc/se30patch               patch /unix in place (reboot afterwards)
    /etc/se30patch -i 5          ... and set the nuCF card's SCSI ID (0-6, -1 = unused)
    /etc/se30patch -s off        ... and turn the SCSI bus scan at startup off (or on)
    /etc/se30patch -m med        ... and set the Carrera040 mode: 030, med or fast
    /etc/se30patch -l on         ... and take in the cards in the other slots (or off)
    /etc/se30patch FILE          patch another kernel file
    /etc/se30patch -f OLD FILE   patch FILE, taking the nuCF card's SCSI ID, the
                                 Carrera mode and the scan setting from OLD (-i, -m,
                                 -s given as well win)

The SCSI bus scan at startup: A/UX sends an INQUIRY to every SCSI ID and waits for
all of them to finish.  With nothing at all connected to the SCSI bus, the bus has no
termination (the SE/30 gets it from the internal drive), the requests never finish
and startup hangs right after "I/O Acceleration".  If A/UX starts from the nuCF card
and nothing is on the SCSI bus, turn the scan off (-s off, or answer n in newconfig).
With the scan off SCSI disks aren't found, so A/UX can't start from a SCSI disk and
the Mac environment doesn't see SCSI disks; connect a terminated device and use
-s on before going back to SCSI.  newconfig offers the running kernel's setting as
the default answer.

The patcher checks every patch site before it writes anything.  If a kernel doesn't
match (neither unpatched nor patched), it says so and changes nothing.  Answering "n"
to newconfig's question leaves the new kernel unpatched: run /etc/se30patch /unix
before rebooting, or A/UX won't start on the SE/30.

Starting A/UX with extensions off (new, 2026-11-09): the kernel starts the Carrera's
68040 itself when A/UX Startup ran on the 68030, the way the Carrera extension does
(reset stub at physical 0, 1 to the control register), so A/UX can be started from a
normal Mac OS install restarted with extensions off.  If the 68040 can't start, the
68030 carries on and A/UX runs on it.  The mode (-m, newconfig asks):
    030   don't start the 68040
    med   68040, caches write-through (the safe mode on this machine)
    fast  68040, caches copyback (fastest; showed memory corruption on one SE/30)
With the Carrera extension loaded the 68040 is already running; the mode then only
sets write-through or copyback.
One boot can be different: in A/UX Startup, Preferences > General, AutoLaunch
Command, add -k with the sum of:
    0x100  stay on the 68030      0x200  med      0x400  fast
    0x800  no SCSI bus scan       0x1000 SCSI bus scan
    0x2000 leave the cards in the other slots out of the slot scan
e.g. "launch -k 0x200" or "launch -k 0x1200" (med, scan).  The same works typed in
A/UX Startup's window after cancelling the autolaunch.

Cards in other slots (new, 2026-11-08): to keep the 68040 away from empty slots
(on the Carrera a read of an empty slot never ends), the boot-time slot scan used to
see only the built-in video, so any other card, such as an Ethernet card in slot B,
was missing from the kernel's slot table: its driver found nothing and newconfig
never asked for its network settings ("No ae Ethernet card(s) installed").  The scan
now also takes in every slot that A/UX Startup's board table lists as occupied (empty
slots are still never touched; the nuCF card is left out, its driver doesn't need
the Slot Manager).  se30patch -c reports "cards in occupied slots in the slot scan".

Ethernet (Etherriser / ae6), step by step:
 1. Install this kit, then run newconfig (no arguments) and answer y to "Take in the
    cards in the other slots?" (mode med).  Reboot.
 2. If the slot scan now sees the card, the startup autoconfig says "The kernel was
    inconsistent with the hardware configuration", adds the ae6 driver, se30acfg
    patches that kernel ("se30acfg: autoconfig built a new /unix ...") and the Mac
    restarts once by itself.  If startup hangs in the slot scan instead, start once
    with launch -k 0x2200 (med, no cards) and tell me what the screen showed.
 3. Once A/UX is up with ae6 in the kernel, run newconfig again (e.g. newconfig bnet
    nfs, or no arguments): it asks for the patches and then for the Ethernet card's
    IP settings (/etc/startup.d/ae6).  Reboot.

The patches: 68040 restart, slot probe, Mac low memory through the cache, slot scan
limited to the built-in video, write-through pages, secondaryInit entry for the BMOW
ROM, byte-wise SCSI writes, 68030-style cache flushes, no MOVE16, Slot Manager with the
ROM cached, polled SCSI reads, cached ROM copyin, ROM cacheable for good (same as
carrera_aux_patches.py disk + secinit_fix.py + lowmem_fix.py v5).  Not included: the
nuCF boot-console diagnostics (nucf_diag.py) and the on-screen debug displays.

Sources in src/: se30patch.c (+ tpl.h, sf.h, bo.h, generated from the Python
patchers), nucf.c.
    cd src; cc -O -o se30patch se30patch.c
    cc -c -DKERNEL nucf.c
