Subject: LC LCII Sonnet Allegro workaround
To: None <port-mac68k@netbsd.org>
From: None <nigel@ind.tansu.com.au>
List: port-mac68k
Date: 12/23/1998 15:31:13
-------------------------------------

Sonnet Allegro=81 LC, LCII workaround.
Version 1.0, by Marc LaViolette, 1998/12/16, Sainte-Foy, Canada.


If you own a Sonnet Allegro=81 accelerator running on a LC or an LCII, you
can get your favorite free Un*x (I tried NetBSD and Linux=81) to boot and se=
e
the more powerfull CPU and your FPU with this patch.  If you wish to run
Linux=81 you must have a FPU on your Allegro=81. However NetBSD has an FPU
emulator that, although it slows down the machine a lot, works. You can
install NetBSD on your LCII even if you don't have a acceleretor card.
Please read all of this text before attempting this workaround. So that no
american laywer will sue me here is a word of warning. I am not responsible
if you try this and something bad happens. If, after you tried this, your
cat jumps into the microwave and turns it on from the inside causing him to
explode, it is not my fault. Blame the stupid cat or the latest guy to kill
Kenny, but not me.

Before we get to the nitty gritty I must thank Mikael Forselius for his
help and suggestions during th whole time I was trying to get the Allegro=81
to boot Linux. He suggested the present patch. I also wish to thank Sonnet
Technologies=81 and specialy Mike Wilks, who promptly replied to my request
for info about their accelerator card. He sent along the technical
information to activate (and disactivate) the Allegro=81 CPU and cache. Alan
Cox suggested that the kernel might not be the place to turn on and off a
CPU and pointed me toward the penguin booter and Mikael. Who am I to argue.

To understand why the workaround is a bit complex, you need to know what
happens when the Mac is turned on and off with the accelerator.  The LC
actually boots using the motherboard CPU. When the Sonnet Allegro=81
extension is run, it switches control to the daughtercard. From then on,
the faster CPU on the accelerator does all the processing. The FPU along
with the cache is also activated at this time. Because of reboot problems a
standard Mac driver is also installed so that at restart or shutdown the
control is passed back to the mothercard's CPU. The drivers returns the mac
to a known state that the MacOS boot process can deal with. If this is not
done the Mac WILL hang upon trying to turn back on the Allegro and on the
LC it will probaly hang before that (something to do with missing code in
the LC ROM's).

The penguin booter (on the Linux side) and the Booter (on the NetBSD side)
both do about the same things to boot the free Un*x's. They initiate a
restart process (as if you selected it in the Special menu of the Finder)
and take control once all the MacOS stuff has been flushed. This ensures
that all MacOS programs terminate properly and that all drivers are erased
from memory. But in our case this also returns control to the slower CPU on
the mothercard.

The workaround disables the Allegro driver so that it cannot return control
to the slower CPU. As of writting this has to be done with a MacsBug=81, the
Apple=81 software debugger. It is available for free from Apple=81 at
www.apple.com. I will try to write some code to get the booters to do it
when the boot process is initiated.  Once you have MacsBug=81 installed you
will have to "fall into" the debugger then edit the Allegro=81 driver and
return to the finder before launching the Penguin or the Booter. From then
on, the Mac will have to be turned off to restart under MacOS or even if
you reboot your Un*x.  You must have version 2.8 of the Allegro=81 extension=
=2E
If you don't have it get it from www.sonnettech.com.

Here is the exact recipe, once you have MacsBug=81 installed:

1) Press cmnd-option-powerswitch
You will "fall into" into MacsBug=81. If you have never done this, don't be
panicked by the big white screen. This is supposed to happen.  At the
bottom of the screen is where you can enter commands. If you need any help
in MacsBug=81 you can type "?" to get a list of topics or "?" and a topic to
get specifics. This will give you the syntax and a description of all
available commands.

2) Type DRVR and return.
This first command asks the debugger to show you all installed drivers.
Among other things (SCSI, sound, video,  etc), you will see one called
".Accel_68030_Sonnet_Allegro".  This is the driver that turns off the
Allegro. What we are interested in is the address given under the "Drvr at"
column. My Mac always gives 00078800. This will probably be different on
yours. It depends on what drivers have been installed and this depends on
how many peripheral devices you have.  The number is the address (in
hexadecimal notation) in memory where the driver resides. The leading
zero's do not matter.  What we want to do is to edit a certain part of this
assembler code to stop the driver from turning off the Allegro=81.

3) Type  "IR (XXXXX + 440)" and return
where XXXXX is the Allegro driver address.
This will display the code surrounding the code we want to change. It
disassembles the code from address XXXXX+440 until the end of routine
address. Make sure it resembles this:


  Disassembling from (78800 + 440)
  No procedure name
            00078C40   CMPI.W     #$0101,D0                               |
0C40 0101
            00078C44   BEQ.S      *+$0006                    ; 00078C4A   |
6704
            00078C46   MOVEQ      #$FC,D0                                 |
70FC
            00078C48   BRA.S      *+$000C                    ; 00078C54   |
600A
            00078C4A   MOVEQ      #$01,D0                                 |
7001
            00078C4C   BRA.S      *+$0004                    ; 00078C50   |
6002
            00078C4E   MOVEQ      #$00,D0                                 |
7000
            00078C50   BSR        *+$0040                    ; 00078C90   |
6100 003E
            00078C54   MOVEM.L    (A7)+,D1/D2/A0/A1/A4                    |
4CDF 1306
            00078C58   CMPI.W     #$0001,$001A(A0)                        |
0C68 0001 001A
            00078C5E   BNE        *-$008E                    ; 00078BD0   |
6600 FF70
            00078C62   RTS                                                |
4E75

What we want to change is at address 78C4E or (78800 + 44E).

4) Type "SM (XXXXX + 44E) 6004" and return
where XXXXX is again the Allegro driver address.
This will replace the branch command (BRA.S) with a return command (RTS).
By doing this we force the Allegro driver to skip the offending code.

5) Type  "IR (XXXXX + 440)" and return
where XXXXX is the Allegro driver address. The same as step 3)
Do this to make sure the code has been changed. It should look like this:

  Disassembling from (78800 + 440)
  No procedure name
            00078C40   CMPI.W     #$0101,D0                               |
0C40 0101
            00078C44   BEQ.S      *+$0006                    ; 00078C4A   |
6704
            00078C46   MOVEQ      #$FC,D0                                 |
70FC
            00078C48   BRA.S      *+$000C                    ; 00078C54   |
600A
            00078C4A   MOVEQ      #$01,D0                                 |
7001
            00078C4C   BRA.S      *+$0004                    ; 00078C50   |
6002
            00078C4E   BRA.S      *+$0006                    ; 00078C54   |
6004
            00078C50   BSR        *+$0040                    ; 00078C90   |
6100 003E
            00078C54   MOVEM.L    (A7)+,D1/D2/A0/A1/A4                    |
4CDF 1306
            00078C58   CMPI.W     #$0001,$001A(A0)                        |
0C68 0001 001A
            00078C5E   BNE        *-$008E                    ; 00078BD0   |
6600 FF70
            00078C62   RTS                                                |
4E75


6) Type "G" and return
This will return you to the finder. You can now launch the booter of your
choice.

I know this is a bit complicated but it works. Like I mentionned earlier I
will try to automate this by adding something to the booters. From what I
read on device drivers under MacOS there are some toolbox functions that
will allow me to locate the driver and edit it. If anybody wants to help me
with this it would be appreciated. I am a novice Mac programmer but not a
novice programmer. Mikael Forselius (also the Penguin maintainer) thinks
that a special booter version should be made for LC/Allegro owners.

That's about it. I can be contacted at:

marclavi@gmc.ulaval.ca

I am no Mac expert or programming guru, so I cannot answer any questions
that relate to anything other than the workaround. Also I am just finishing
my Doctorat in Mech. Eng. (should leave the university by February) so I do
not know how long the e-mail account will exist.

Marc LaViolette
Universite Laval
Quebec, Canada
G1K 7P4