Subject: 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 01:48:10
I believe the openfirmware() routine in locore.S does this:

	- set up the OF stack

	    - set up the stack pointer and memory mapping registers
	    - put the arguments on the stack)

	- call OF

	- undo the setting up of the OF stack

	    - take the return values off the stasck
	    - restore the stack pointer and memory mapping registers

but how exactly do they do it?  i.e., which instructions do what?

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.
So these are my ideas, from most polished to least:

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

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

	- Hope that the OF stack is always cleared between calls.

Obviously I want to do this right, so I would prefer the first idea.

Thanks,

-- Derek