Subject: Re: Is the kernel designed to return?
To: None <port-macppc@netbsd.org>
From: Derek Peschel <dpeschel@eskimo.com>
List: port-macppc
Date: 01/12/2002 17:40:22
On Sat, Jan 12, 2002 at 02:02:37PM -0800, John Hawkinson wrote:
> Derek Peschel <dpeschel@eskimo.com> wrote on Sun, 30 Dec 2001
> at 08:23:21 -0800 in <20011230082321.B28439@eskimo.eskimo.com>:

> > But I realized that calling the
> > cpu_reboot function is not the cleanest way to do that -- I want to return
> > from a series of nested functions (ultimately reaching the boot loader,
> > which has an "OF_exit" statement following the "chain" statement that
> > transfers control to the kernel).
> 
> I don't believe this is necessary. I think you can just
> call OF_exit().

cpu_reboot is something like this:

	/* handle a halt */
	ppc_exit();

	/* handle a reboot */
	...

and ppc_exit is something like this:

	OF_exit();
	while (1) { };

So control apparently returns from OF_exit to ppc_exit.  If I take the
endless loop out of ppc_exit, control returns from there to cpu_reboot
and falls through to the reboot code.  Or something is making the
machine reboot, at any rate.

Trying to get cpu_reboot to return is fruitless since it's declared
not to.

Somone on tech-kern mentioned that the Sparc halts -- but then der Mouse
mentioned that not all Sparcs do.  And the Sparc port just relies on
OF_exit as well.  I don't think we can trust OF_exit by itself.

> > Is the kernel designed to be tortured in this way?  Otherwise I'd have
> > to do something even nastier (which I wouldn't understand anyway).
> 
> You haven't specified a torture as far as I can see.

I was referring to my "I want to return from a series of nested functions"
remark.  It would be a fundamentally different approach -- the scheduler
would have to be modified to return, control would reach the statement
in the boot loader after th chain() call, and the boot loader would exit.

By "something nastier" I meant using assembly to manipulate the stack
directly.

> > The other issue is that (AIUI) OF_exit should be called exactly
> > as many times as OF_enter is.  So I'd need to track down all the exits
> > and enters.  Is anyone using another boot loader besides ofwboot?
> 
> No, OF_enter() calls have nothing to do with OF_exit() calls.

You are correct (as I found after posting) -- enter is used to get at the
command-line interface while a client program is running; from the CLI,
"go" gets back to the client program.

-- Derek

P.S.  cpu_reboot is incorrect in another way -- unsuccessful powerdowns
are supposed to be treated as halts, according to reboot.h, but they
currently fall through to the reboot code instead.  This shouldn't be
too hard to fix.