On Fri, Oct 22, 2010 at 6:45 PM, Mark Cave-Ayland mark.cave-ayland@siriusit.co.uk wrote:
Blue Swirl wrote:
Ah okay - so swap retl with plain ret? And can I just use %sp like the SPARC64 version?
Yes. If you add 'save' and 'restore', then %sp can be used.
Okay - perhaps I'm missing something more fundamental here. The attached patch creates a simple handler that does nothing except flush windows to the stack and then call the C function - but it still seems to corrupt the stack somehow as subsequent calls into OBP have the wrong parameters.
The only thing I can think of is that this simple example fails because of something related to the return address, but I'm not 100% sure.
'call' instruction writes the return address to %o7, clobbering previous %o7 from the OS. That's why 'save' and 'restore' are needed.
In this case, alternatively changing just 'call' to 'jmp' and deleting the rest should also work.
Also what are the rules about how much information you can push onto the stack of the previous frame, i.e. the frame pointer? My current thoughts are that I can either i) push arguments onto the %fp and not save into a new window or ii) push arguments onto the %sp after a save (in which case I need additional code to copy the i registers into the o registers before calling the C function). Does this sound correct?
I'd go for ii) or 'jmp'.