/*
 * This program does load an Elf Binary and runs it as a PPC Task.
 * It doesn`t return until the Task completes.
 *
 */

#include <exec/types.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <PowerUP/pragmas/ppc_pragmas.h>
#include <PowerUP/clib/ppc_protos.h>
#include "PPCLoad_VERSION.h"

UBYTE vers[] = VERSTAG;

extern struct ExecBase	*SysBase;
BPTR	stdout;

void	main(ULONG argc,char *argv[])
{
struct Library	*PPCLibBase;
ULONG		Result;
APTR		MyObject;

  stdout	=	Output();

  if (argc != 2L)
  {
    Printf("Usage: ElfFile\n");
  }
  else
  {
    if (PPCLibBase=OpenLibrary("ppc.library",0))
    {
      if (MyObject=PPCLoadObject(argv[1]))
      {
        Result=PPCRunObject(MyObject,NULL);
        Printf("Result:0x%lx\n",Result);
        PPCUnLoadObject(MyObject);
      }
      else
      {
        Printf("Can't load %s\n",argv[1]);
      }
      CloseLibrary(PPCLibBase);
    }
    else
    {
      Printf("Can't open ppc.library\n");
    }
  }
}
