[comp.sys.mac.programmer] DRVRs and installing them

tj@oahu.cs.ucla.edu (Tom Johnson) (03/08/90)

I am about to try writing a device driver for the first time.  I have
looked through all of my old MacTutors and Inside Mac and I must confess
I am a little intimidated. (a little?  Actually a lot) The only example
I could find was the IAC driver in the 10/88 issue.  Could someone please
point me to a simpler example of writing DRVRs in Pascal (preferably)
or C?

I am also going to have to install this thing in the system heap using
an INIT.  Does anybody have some sample code on how to find an empty
slot in the driver table?
Once I find the empty slot I guess I would just do the following:
   GetNamedResource
   GetResInfo
   SetResInfo	{change ID to the open slot in the table}
   OpenDeskAcc	{open the driver}
   DetachResource
   SetResInfo	{restore the original ID}

Is this basic outline correct?

Thanks,

Tom Johnson

       Tom Johnson      UCLA Computer Science Department 
			3413 Boelter Hall, Los Angeles CA 90024 (213)825-6952
			UUCP:      {uunet,rutgers,ucbvax}!cs.ucla.edu!tj
			Internet:  tj@cs.ucla.edu

ts@cup.portal.com (Tim W Smith) (03/10/90)

Some things to watch out for:

	1. Searching to find an empty slot is sort of OK, but be
	careful.  What if you pick slot N, and then an INIT that
	runs after your's wants to load a driver that needs slot
	N?

	TOPS tries to work around this by examining all resources
	of type 'DRVR' in currently open resource files and avoiding
	the appropriate unit table slots.

	This is fine as long as everyone who requires that there
	driver be in a certain unit table slot installs their
	driver in the System file.

	You could try using entries used for NuBus slot drivers.
	When a driver for a NuBus slot is opened, the Slot
	Manager picks the first available entry above 63.  So
	nothing should break if you've taken one of these
	yourself.  I don't remember offhand if the Unit Table
	contains these entries on non-NuBus Macs, however.

	2. If you are implementing your driver in some high level
	language, you might be in for a surprise.  The driver will
	probably has some resource that contains the global data
	for that driver.  The glue code that the development system
	provides for you will contain code to load that resource
	when the driver is first opened.

	There is a good chance that it will try to load the resource
	by number.

	For example, THINK C does this.  When I write drivers for
	NuBus cards in THINK C, I have to patch the glue code to
	look for the resource by name rather than ID, and then add
	a name to the resource.  I wish Symantec would fix this.

	3. Be sure to load the driver into the System heap!  There is
	a small Application heap at INIT time, and if you forget
	to make sure the driver goes into the System heap, you will
	get a crash when Finder starts.

	4. OpenDeskAcc ( or however it is spelled ), is probably not
	what you want.  Open is what you want.

						Tim Smith

ps: if you do decide to search for an open slot in the Unit Table,
remember that 32 to 39 are reserved for SCSI devices.  Some drivers
for SCSI devices are rather picky about getting the right entry.

pps: and anyone who writes a driver for a SCSI device, please put
your driver in the right Unit Table slot.  It can make a difference
if you want to be compatible with other SCSI drivers that have to
do weird things.

time@crane.aa.ox.com (Tim Endres) (03/13/90)

When we wrote MacNFS at UofM CITI, we were told by Apple to actually
*extend* the Unit Table to add our drivers (there were several). This
was before the larger Unit Tables we see today, but I think the advice
is still valid. Otherwise, hitting a Unit Slot that is "reserved" is a
bad idea. It is a very difficult bug for the user to resolve.

The details of growing the Unit Table are not extensive, but for
bandwidth sake, I suggest calling tech support. The "extension"
involved actually allocating a new table, copying pointers, and
updating the low memory global which pointed to the table. All
appropriate warnings and disclaimers apply to this procedure.

kab@adpplz.plaza.adp.com (Ken Baker) (03/23/90)

In article <TIME.90Mar12182251@crane.aa.ox.com>, time@crane.aa.ox.com (Tim Endres) writes:
> When we wrote MacNFS at UofM CITI, we were told by Apple to actually
> *extend* the Unit Table to add our drivers (there were several). This
> was before the larger Unit Tables we see today, but I think the advice
> is still valid. Otherwise, hitting a Unit Slot that is "reserved" is a
> bad idea. It is a very difficult bug for the user to resolve.
> 

Does any one know about macNFS mentioned in the above article?
We are looking for a product that works in a similar way to PC-NFS
to use in our Mac/Pc/UNIX enviarnment here.

Please send me email or post the information in this newsgroup. My
short email address may not work yet as we are a new site but the
long address below will work. Thanks in advance for any help!


-- 
Ken Baker                                       ADP Dealer Services (Plaza R&D)
kab@adpplz.plaza.adp.com         . . .  tektronix!nosun!cvedc!mcspdx!adpplz!kab
Voice: (503) 294-4200 ext. 2528      . . . uunet!apple!motcsd!mcspdx!adpplz!kab