Subject: machdep.c and its boot() routine and doshutdownhooks()
To: None <tech-kern@NetBSD.ORG>
From: Perry E. Metzger <>
List: tech-kern
Date: 11/13/1995 10:31:48
First, a little motivation: I discovered an odd bug, which was that
the floppy motor never shuts off on port-i386 if your halt the machine
while the motor is on. I decided to dig into what caused this, and for
the first time I discovered a facility I'd never known about,
specifically a little routine called doshutdownhooks(). It appears
that doshutdownhooks() is supposed to call a list of shutdown hooks to
do things exactly like, for instance, turning off the floppy drive

I've noticed, however, that the call, which appears to have to be made
from machdep.c's "boot()" routine (responsible for final shutdown --
strange that its called "boot"), is only actually included in the
alpha and i386 ports versions of machdep.c. It also appears, by the
way, that doshutdownhooks() is only called properly in the alpha port
-- on the i386 it gets called AFTER the machine is officially in a
halted state, which really isn't the right time for it AT ALL.

I also noticed that for the most part, boot() seems to be intended to
do exactly the same thing from port to port other than whether a halt
instruction or tight loop waiting for console input gets called. The
specific code differs greatly from port to port, but it almost all
seems to be the same stuff, over and over.

So, my three questions are...

1) Is the shutdown hook facility something recent? If so, who is the
   author of it? What is the reason for the mysterious variable
   shutdownhooks_done in doshutdownhooks that isn't set anywhere in
   the kernel?
2) Shouldn't doshutdownhooks() be in boot() in every port, and not
   just in two of them?
3) Should boot() be made machine and port independent, with the only
   port specificity being a call to a routine that would either call a
   machine independent "please hit any key to reboot" and loop call,
   or a machine halt instruction?