Subject: Re: How does the asm interface to OF work? I need to enhance it
To: Derek Peschel <dpeschel@eskimo.com>
From: gabriel rosenkoetter <gr@eclipsed.net>
List: port-macppc
Date: 12/28/2001 11:09:54
--IrhDeMKUP4DT/M7F
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Dec 28, 2001 at 01:48:10AM -0800, Derek Peschel wrote:
> but how exactly do they do it?  i.e., which instructions do what?

Can't help with this without checking, and there's no OpenFirmware
at the folks' house.

> 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.

> 	- Load the stack as usual.  Call OF.  Read a value from the
> 	  stack.  Read a second value from the stack if the first one
> 	  was 1 or -1.  This would all be done in assembly language.

That sounds moderately painful. It also seems like it means
reinventing the openfirmware() wheel to a certain extent.

> 	- 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 !=3D0? (OF *has* a pop command, does it not?)

> 	- 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.

--=20
gabriel rosenkoetter
gr@eclipsed.net

--IrhDeMKUP4DT/M7F
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (NetBSD)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAjwsmVIACgkQ9ehacAz5CRqqXQCdHa45AHLbQqFnUxzsCy0tr3mx
aJMAniN5CU38CY2s3+PK/HUAnw02iAHN
=5eN8
-----END PGP SIGNATURE-----

--IrhDeMKUP4DT/M7F--