For years I've had to just enable the FPU for nearly every 030 machine in MAME because otherwise the OS would die immediately after Welcome to Macintosh with an unexpected F-line trap. I just found out it's because of the extremely non-intuitive way Apple was detecting the FPU.
This is from the Quadra 700/900 and PowerBook 140/170 ROM, but many other pre-1992 ROMs have the same code at the same place:
The comments should be pretty self-explanatory, but the upshot is that it uses the rarely seen MOVES instruction to read RAM with the 68k set to assert function code 7 (CPU private) instead of Mac OS's normal FC 5 (supervisor mode data). I'm unclear if this is a 68K feature or a Mac hardware feature, as I certainly haven't seen it documented either place.
Interestingly, in 1992 Apple threw away this code and switched to a more obvious and straightforward detection method, which you see in the SuperMario tree. This is from the PowerBook 160/180/165c/180c ROM:
This is ultimately how they differentiate a PowerBook 140 from a 170 or a 160 from a 180. If you've played with unirom you've seen that there are only entries in the tables for the 170 and 180, and some code we don't see in the SuperMario tree fudges the Gestalt values for those machines if an FPU is not present.
This is from the Quadra 700/900 and PowerBook 140/170 ROM, but many other pre-1992 ROMs have the same code at the same place:
Code:
ROM:40803DBA CheckOptionals:
ROM:40803DBA btst #$1C,d2 ; did the Universal table say this machine can have an FPU?
ROM:40803DBE beq.w FPUDone ; if not, no need for more checking
ROM:40803DC2 movea.l a6,a2 ; this is the "BSR6" macro you see all over the SuperMario tree
ROM:40803DC4 lea CheckFPUReturn,a6
ROM:40803DC8 jmp TestForFPU
ROM:40803DCC
ROM:40803DCC CheckFPUReturn:
ROM:40803DCC beq.s HaveFPU
ROM:40803DCE bclr #$1C,d2 ; clear the HasFPU bit in the hardware config word
ROM:40803DD2
ROM:40803DD2 HaveFPU:
ROM:40803DD2 movea.l a2,a6
ROM:40803DD4 bra.w FPUDone
ROM:40803DEC GotBusError:
ROM:40803DEC btst #$1B,d7 ; Make the BEQ at 40803DCC fall through
ROM:40803DF0 movea.l a5,sp
ROM:40803DF2 jmp (a6)
ROM:40804640 TestForFPU:
ROM:40804640 movec cacr,d1
ROM:40804644 bset #$1F,d1
ROM:40804648 movec d1,cacr
ROM:4080464C movec cacr,d1
ROM:40804650 bclr #$1F,d1
ROM:40804654 beq.s Not040
ROM:40804656 movec d1,cacr
ROM:4080465A bra.s Its040
ROM:4080465C
ROM:4080465C Not040:
ROM:4080465C move.b #7,d1 ; select FC 7 (CPU space)
ROM:40804660 movec d1,sfc
ROM:40804664 moves.w (unk_22000).l,d1 ; read an arbitrary RAM location, but with FC 7
ROM:4080466C
ROM:4080466C Its040:
ROM:4080466C cmp.b d1,d1 ; make the BEQ at 40803DCC succeed
ROM:4080466E jmp (a6)
The comments should be pretty self-explanatory, but the upshot is that it uses the rarely seen MOVES instruction to read RAM with the 68k set to assert function code 7 (CPU private) instead of Mac OS's normal FC 5 (supervisor mode data). I'm unclear if this is a 68K feature or a Mac hardware feature, as I certainly haven't seen it documented either place.
Interestingly, in 1992 Apple threw away this code and switched to a more obvious and straightforward detection method, which you see in the SuperMario tree. This is from the PowerBook 160/180/165c/180c ROM:
Code:
ROM:40804640 TestForFPU:
ROM:40804640 movec vbr,d1 ; mess with the vector table so F-line traps are caught
ROM:40804644 subi.l #$24,d1
ROM:4080464A movec d1,vbr
ROM:4080464E moveq #1,d1
ROM:40804650 lea NoFPU,a6 ; tell the F-line trap handler where to jump to
ROM:40804654 fnop ; this will cause an F-line trap if there's no FPU
ROM:40804658 moveq #0,d1 ; if there is an FPU this instruction will execute
ROM:4080465A NoFPU:
This is ultimately how they differentiate a PowerBook 140 from a 170 or a 160 from a 180. If you've played with unirom you've seen that there are only entries in the tables for the 170 and 180, and some code we don't see in the SuperMario tree fudges the Gestalt values for those machines if an FPU is not present.