Subject: Re: How does the asm interface to OF work? I need to enhance it
To: None <port-macppc@netbsd.org>
From: Derek Peschel <dpeschel@eskimo.com>
List: port-macppc
Date: 12/28/2001 08:22:43
> > The existing OF routines all assume that the number of return values is
> > known in advance.  Unfortunately I need to call a word (FIND) which
> > either returns 0 alone, -1 and another value, or 1 and another value.
> 
> Hrm. This sucks. But is maybe not an easy problem to fix.

Yes, but if I want the @@#$%!@ keyboard detection code to work right,
it has to be fixed.

> > 	- On one call of openfirmware():  Load the stack as usual,
> > 	  with the required values plus an extra value.  Call OF.
> > 	  Read two values.  Back in C: inspect the topmost return
> > 	  value; if it's 1 or -1, call openfirmware() again to pop
> > 	  the remaining value off the OF stack.  (If the return value
> > 	  is 0, the OF stack will already be empty.)
> 
> Maybe I'm missing something, but I think you've made this sound more
> complicated than it needs to be. The OF command you're calling will
> either return 1 or two arguments, right? Doesn't OF have a "pop"
> command? Can't you run find telling openfirmware() to expect only
> one response, check the value, then run OF's pop command if the
> response was !=0? (OF *has* a pop command, does it not?)

Expecting one value instead of two should work (I have to think about
it though).  When I said "call openfirmware() again to pop..." I meant
that I'd use the C interface to call DROP, which would call openfirmware()
as a side effect.  My point was	that you go through openfirmware()
twice, rather than once as in my first idea.

The only problem with dropping the second value is that it might be useful.
It's the address of the method.  Of course if I call my function
OF_does_method_exist rather than OF_address_of_method, I don't have to
worry about returning the second value!

> > 	- Hope that the OF stack is always cleared between calls.
> 
> Hrm. Good Forth code will leave the stack clean when it's done. I
> don't think it's safe to trust that, though. You *could* store the
> value of the stack position (it's the number before the prompt in
> OF, must also exist in a register) and know when you get back to the
> same place. That sounds more than slightly shady, though.

I meant "Hope that the OF interface routines always clear the stack
between calls", not "Trust every single piece of code in the system
except mine to clear the stack." :)

-- Derek

P.S.  Please don't Cc: me, since it only creates twice as much mail.