#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <exec/memory.h>
#include <exec/libraries.h>
#include <exec/alerts.h>
#include <exec/execbase.h>
#include <exec/devices.h>
#include <exec/io.h>
#include <exec/errors.h>

#include <emul/emulinterface.h>
#include <emul/emulregs.h>
#include <ppcinline/exec.h>

#include <public/proto/quark/syscall_protos.h>


void	test(ULONG	Arg1,
             ULONG	Arg2,
             ULONG	Arg3,
             ULONG	Arg4,
             ULONG	Arg5,
             ULONG	Arg6,
             ULONG	Arg7,
             ULONG	Arg8);

#define	STACKSIZE	16384

int	main(void)
{
struct ExecBase		*SysBase=*((struct ExecBase**) 4);
struct PPCStackSwapArgs	Args;
struct StackSwapStruct	Swap;
UBYTE			*MyStack;
int			i;

  dprintf("main: StackSwap\n");

  for (i=0;i<8;i++)
  {
    Args.Args[i]	=	i;
  }

  if (MyStack=AllocVec(STACKSIZE,
                       MEMF_PUBLIC))
  {
    dprintf("main: Stack 0x%lx\n",
            MyStack);

    Swap.stk_Lower	=(void*) MyStack;
    Swap.stk_Upper	=(ULONG) &MyStack[STACKSIZE];

    /*
     * Internally the function subtract 16 for the current r1
     * because we need the savety header
     */
    Swap.stk_Pointer	=(void*) &MyStack[STACKSIZE];

    NewPPCStackSwap(&Swap,
                    &test,
                    &Args);

    FreeVec(MyStack);
  }
  else
  {
    dprintf("main: Stack allocation failed\n");
  }
  dprintf("main: done\n");
  return(0);
}


void	test(ULONG	Arg1,
             ULONG	Arg2,
             ULONG	Arg3,
             ULONG	Arg4,
             ULONG	Arg5,
             ULONG	Arg6,
             ULONG	Arg7,
             ULONG	Arg8)
{
  dprintf("test: %ld %ld %ld %ld %ld %ld %ld %ld\n",
          Arg1,
          Arg2,
          Arg3,
          Arg4,
          Arg5,
          Arg6,
          Arg7,
          Arg8);
}

