/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1991 by John E. Lloyd.				    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

#if !defined(SGI_CFG) && !defined(VXWORKS_CFG) 

#include <errno.h>
#include "../h/errorCodes.h"
#if !defined(SIMONLY_CFG) && !defined(LINUX_CFG)
#include "../sys/rciext/rciioctl.h"
#endif

extern int errno;

int _rciFd;

/* ----- Error Messages. Defined externally to save space ----- */

static char *badIoctlMsg	= "%s -- %s ioctl failed, errno %d\n";

extern int rciSignalRefCount;
extern int rciSimOnly;

rciTaskExec (fxn, arg)
int (*fxn)();
int arg;
{
#ifndef LINUX_CFG
/* IRIX: send a signal to the RCI control task to run a task 'on demand' */

	char *fxnName = "rciTaskExec()";

	if (rciSimOnly)
	 { if (rciSignalRefCount > 0)
	    { blockRciSignals();
	    }
	   (*fxn)(arg);
	   if (rciSignalRefCount > 0)
	    { unblockRciSignals();
	    }
	 }
	else
	 { 
#if !defined(SIMONLY_CFG)
	   struct RCI_fxn_arg exec;

	   exec.function = fxn;
	   exec.argument = arg;
	   if (ioctl (_rciFd, RCIIOC_EXECUTE, &exec) < 0)
	    { errorMsg (EInternal, badIoctlMsg, fxnName, "EXECUTE", errno);
	      return (-1);
	    }
#endif
	 }
	return(1);
#endif
}

rciKrnlExec (fxn, arg0, arg1, arg2, arg3)
int (*fxn)();
int arg0, arg1, arg2, arg3;
{
/* IRIX: don't need this; this shouldn't be used by IRIX version */
#ifndef LINUX_CFG
	char *fxnName = "rciKrnlExec()";
	int rval;

	if (rciSimOnly)
	 { if (rciSignalRefCount > 0)
	    { blockRciSignals();
	    }
	   rval = (*fxn)(arg0, arg1, arg2, arg3);
	   if (rciSignalRefCount > 0)
	    { unblockRciSignals();
	    }
	 }
	else
	 { 
#if !defined(SIMONLY_CFG)
	   struct RCI_fxn_arg4 exec;

	   exec.fxn = fxn;
	   exec.arg[0] = arg0;
	   exec.arg[1] = arg1;
	   exec.arg[2] = arg2;
	   exec.arg[3] = arg3;
	   if (ioctl (_rciFd, RCIIOC_KRNLEXEC, &exec) < 0)
	    { rciAbort (EInternal, badIoctlMsg, fxnName, "CMKRNL", errno);
	      return (-1);
	    }
	   rval = exec.rval;
#endif
	 }
	return(rval);
#endif
}

rciKutExec (fxn, arg0, arg1, arg2, arg3)
int (*fxn)();
int arg0, arg1, arg2, arg3;
{
/* IRIX: don't need this; it's only used in atomicOps.c */
#ifndef LINUX_CFG
	char *fxnName = "rciKutExec()";
	int rval;

	if (rciSimOnly)
	 { if (rciSignalRefCount > 0)
	    { blockRciSignals();
	    }
	   rval = (*fxn)(arg0, arg1, arg2, arg3);
	   if (rciSignalRefCount > 0)
	    { unblockRciSignals();
	    }
	 }
	else
	 { 
#if !defined(SIMONLY_CFG)
	   struct RCI_fxn_arg4 exec;

	   exec.fxn = fxn;
	   exec.arg[0] = arg0;
	   exec.arg[1] = arg1;
	   exec.arg[2] = arg2;
	   exec.arg[3] = arg3;
	   if (ioctl (_rciFd, RCIIOC_KUTEXEC, &exec) < 0)
	    { rciAbort (EInternal, badIoctlMsg, fxnName, "CMKRNL", errno);
	      return (-1);
	    }
	   rval = exec.rval;
#endif
	 }
	return(rval);
#endif
}

#endif /* !defined(SGI_CFG) && !defined(VXWORKS_CFG) */

