We solved it!

A good friend (Alan Wilkie) and I have managed to successfully create a stack, use it
and then restore back to the original stack. I want to share the source with you all
given the apparent shortage of information on this topic.

Firstly we define an inline function with the following prototype that will take care
of setting the stack pointer:

*****
inline asm VoidPtr SetA7(VoidPtr inNewA7);
*****

which has the following body:

*****
asm VoidPtr Teenee::SetA7(VoidPtr inNewA7)
{
 move.l sp, a0
 move.l (sp), sp
}
*****

Then we allocate a stack in our source somewhere (we're using C++ and Teenee):
*****
 int theNewStackSize = 2.5 * 1024;
 CharPtr theNewStackP = static_cast<CharPtr>(::MemPtrNew(theNewStackSize));
 ThrowErrIfZero_(theNewStackP, dmErrMemError);

 mSpareStackSentry = MemPtrFreeSentry(theNewStackP);
 mSpareStackTopP = theNewStackP + (theNewStackSize - sizeof(long));

*****

To use the stack and then restore it:

*****
 register CharPtr theAppStackP = static_cast<CharPtr>(SetA7(mSpareStackTopP));

 register Err theErr = 0;

 <Do Something Here and be sure to use register vars>

 SetA7(theAppStackP);
 ThrowIfErr_(theErr);
*****

The routine that houses the above MUST be surrounded by #pragma stack_cleanup on and
#pragma stack_cleanup reset respectively.

'hope you find it useful.

Regards,
--
Christopher Hunt
Class Action Pty. Ltd.

Are you a time zone traveler that owns a Palm(tm) connected organizer?
Check out http://www.classactionpl.com/TimeTraveler/index.htm

Reply via email to