/*
    (C) 1995-96 AROS - The Amiga Replacement OS
    $Id: runprocess.s,v 1.3 1996/12/11 10:14:56 aros Exp $

    Desc: Run a process ( invoked by dos/Runcommand() )
    Lang: english

 LONG RunProcess ( struct Process         * proc,
		    struct StackSwapStruct * sss,
		    STRPTR		     argptr,
		    ULONG		     argsize,
		    LONG_FUNC		     entry,
		    struct DosLibrary	   * DOSBase )
*/

	#include "machine.i"

	.set FirstArg,	4+(2*4)	/* Return-address + registers */
	.set proc,	FirstArg
	.set sss,	proc+4
	.set argptr,	sss+4
	.set argsize,	argptr+4
	.set entry,	argsize+4

#define	DOSBase		entry+4

	.text
	.balign 16
	.globl	AROS_SLIB_ENTRY(RunProcess,Dos)
	.type	AROS_SLIB_ENTRY(RunProcess,Dos),@function
AROS_SLIB_ENTRY(RunProcess,Dos):
	movem.l	%a5-%a6,-(%sp)	/* Save some registers */

	move.l	sss(%sp),%a0		/* Fetch the arguments off the stack */
	move.l	entry(%sp),%a5		/* "     "   "         "   "   " */

	move.l	stk_Upper(%a0),%a1	/* Move upper bounds of the new stack into a1 */
	move.l	%a0,-(%a1)		/* Push sss onto the new stack */
	move.l	DOSBase(%sp),%a6	/* Get SysBase */
	move.l	dl_SysBase(%a6),%a6	/* "   " */
	move.l	%a6,-(%a1)		/* Push SysBase onto the new stack */
	move.l	%a1,stk_Pointer(%a0)	/* Store Switch Point in sss */

	jsr	StackSwap(%a6)		/* Switch stacks (a0=sss) */

	jsr	(%a5)			/* Call the specified routine */
	move.l	%d0,%a5			/* Save return value */

	move.l	(%sp)+,%a6		/* Pop SysBase */
	move.l	(%sp)+,%a0		/* Pop sss */
	jsr	StackSwap(%a6)		/* Switch stacks back */

	move.l	%a5,%d0			/* Put result in d0 where our caller expects it */

	movem.l	(%sp)+,%a5-%a6	/* Restore registers */
	rts
