Re: A89: rom call return values


[Prev][Next][Index][Thread]

Re: A89: rom call return values




On Thu, Dec 02, 1999 at 17:49:09 -0500, Robin Kirkman wrote:
> 
> Johan wrote:
> > structs are returned in a bizarre way that you don't want to deal with.
> > (I can explain if anyone cares to know...)
> 
> Yes, please do explain...
> I am writing a tios function call wrapper for regular gcc, and i haven't
> got it to return values yet, just do the calls.
> --robin


Ok, you've been warned  ;)


struct S {
  ...;
};

struct S rets_struct(...) {
  ...;
}

void gets_struct(...) {
  struct S foo;
  ...;
  foo=rets_struct(...);
  ...;
}


A struct is returned by letting the callee write it to the top of the
caller's local variable area.

When rets_struct() is called, a6 points *immediately after* where
rets_struct() should write the returned struct.

Note that this will clobber local variables if there's no memory reserved in
the stack frame for the struct-being-returned.

When rets_struct() returns and gets_struct() gets in charge again, it should
copy the returned struct to its final position (to 'foo' in my example above).



Stack when rets_struct() is running, assuming both functions use real stack
frames:

- - - - - - - - - - - - - - -
gets_struct():
	| arg n	 |
	|   :  	 |
	| arg 1	 |
   +-->	| old a6 |
   |	| STRUCT | <- returned struct will be written here by rets_struct()
   |	|  foo   |
   +----|  ...   |---+
   	|  ...   |   |
- - - - - - - - -|- -|- - - -
rets_struct():	     |
	| arg m  |   |
	|   :    |   |
	| arg 1  |   |
a6 ->	| old a6 | >-+
	| local  |
	|   :	 |
     	| local  |
     	|  ...   |
sp -> 	|  ...   |
- - - - - - - - - - - - - - -


(Does my explaination make any sense?)
//Johan


Follow-Ups: References: