Subject: Re: NetBSD without MacOS: Coding time!
To: Michael R. Zucca <mrz5149@acm.org>
From: Paul Goyette <paul@whooppee.com>
List: port-mac68k
Date: 02/27/1999 16:04:54
On Sat, 27 Feb 1999, Michael R. Zucca wrote:

> At 4:21 PM -0500 2/27/99, Mike Frager wrote:
> 
> >Before we try to actually write this thing we should find solutions for
> >the problems that we KNOW we will run into. If you have a way (preferably
> >an assembler or C routine) to do any of these things PLEASE post it:
> >
> >Detect and/or switch to 32-bit addressing
> 
> There may be a trap for this. I forget what its called, though.

Yep.  But how much of the ROM-based OS and ToolBox traps are adequately
initialized at this point?  Many of these routines rely on the settings
of low-memory globals.

> >Read and write to/from PRAM
> 
> These are *definitely* available in the ROM. They need to be used by NuBus
> devices during Primary Init.

Yep, again.  But there are different ways to access different parts of
the PRAM, and some of them rely on the proper set-up of the Cuda/Egret
chips on some systems.  Of course, since the Start Manager has to read
from PRAM to figure out which disk to boot from, PRAM should be useable
at this point.

Which reminds me, you _are_ planning on only running your special "driver" 
code if the user is actually trying to boot from the NetBSD disk, right?
If the user wants to boot from some other disk, you'd better just load
the "normal" driver!  :)

> >Access to SCSI from assembler
> 
> The SCSI manager is available at boot.
> 
> >Using Toolbox traps from ROM without the MacOS
> 
> These should work the same. You just do A-Traps. See IM assembly sections.
> It should be relatively easy to make a C header file that will do the
> appropriate traps and follow enough of the Mac ABI for traps. However, you
> have a "restricted" set depending upon the machine. For instance, I would
> imagine the SE/30 probably has the most minimal ROM of all the machines that
> run NetBSD while machines like the 840AV have most of MacOS resident in ROM.
> 
> On the 840AV there are even Quicktime calls so if you want to play a short
> movie clip while NetBSD loads, feel free :-)
> 
> Let's put it this way: grab a copy of the ROM descriptions from
> dev.info.apple.com. Use the SE ROM as your guide. Write the program as
> though you are writing code for an SE for System 6. If you use a system call
> or library call, look it up in the SE ROM description. If its listed in
> that table you should be able to just use it (although you may have to
> initialize the right packages before hand). If not, you'll have to roll your
> own.
> 
> Looking at the ROM table, you should have pretty much all that you need,
> and much more.
> 
> >Detect hardware without the MacOS (or are Gestalts in ROM?)
> 
> What's to detect? If you're thinking of machine type, I think the ID
> mechanism used before the Gestalt manager is preset. Otherwise you can
> parse the fake S-Resources at the end of the ROM for info.
> 
> >Access partitions from NetBSD in raw (no filesystem) mode
> 
> Use standard unix calls like open/close/read/write on the raw version of
> the device.

Yep.  And you'll need to locate and parse the Partition Table partition.

> >Setup the display/serial ports without the MacOS
> 
> Both of these are handled by the ROM and you should be able to initialize
> and use basic Quickdraw at boot if you need it.

Need to be careful here, with respect to the monitor.  If you're on a
non-internal monitor, things could get dicey.

> However, you may have to "setup" the serial ports on machines like
> powerbooks. The serial ports use standard Zilog chips. Check out the
> NetBSD serial driver for an idea of how to mess with the serial chips.
> The base address for the chips should be listed somewhere either in
> NetBSD or in the tech docs for each machine.
> 
> >Using assembler to move a chunck of data from disk to RAM (should be easy)
> 
> Again, once you have the SCSI manager you can just push the data into memory.
> However, you'll probably need to write a little piece of assembler that will
> copy the kernel so that it starts at address 0 and then kick off the kernel.
> You can probably rip this out of the current booter.

Don't forget to find some place to store all of the info that the
current booter grabs (various low-memory globals, and RAM ranges) before
loading the kernel!

> >If we can get a few of these worked out then we can begin coding. Also,
> >does anyone have an idea of how we can debug this thing since Macsbug
> >won't be loaded yet.
> 
> There is a primitive dialog service that should be available at boot that
> is used to toss up dialogs when the system crashes and for "Welcome to
> Macintosh". You can use this service also. Just "printf" to the dialog
> box.

Hmmm.  Some of this will rely on the existence of QuickDraw as well as
the Font Manager (dialog boxes are drawn with Chicago IIRC).  Most of
this will be unuseable once you've started to load NetBSD.

> Grab a copy of IM: Operating System Utilites. It has alot of the stuff you
> might be looking for.

There's also a fair amount of stuff in the old version of IM (the one
that came in volumes I through VI).  Let me know if there's stuff that
you can't find in the newer IM manuals.


-----------------------------------------------------------------------------
| Paul Goyette      | PGP DSS Key fingerprint:   | E-mail addresses:        |
| Network Engineer  |   BCD7 5301 9513 58A6 0DBC |  paul@whooppee.com       |
| and kernel hacker |   91EB ADB1 A280 3B79 9221 |  paul.goyette@ascend.com |
-----------------------------------------------------------------------------