/***************************************************************************
	XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A 
	COURTESY TO YOU.  BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
	ONE POSSIBLE   IMPLEMENTATION OF THIS FEATURE, APPLICATION OR 
	STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
	IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE 
	FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.  
	XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO 
	THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO 
	ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE 
	FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY 
	AND FITNESS FOR A PARTICULAR PURPOSE.
$Id: libprocess.c,v 1.1.2.1 2003/03/12 22:27:46 mohan Exp $
***************************************************************************/
/**************************************************************************/
/**
 * @file libprocess.c
 *
 * This contains system call wrapper functions for Process Management.
 * The system call wrapper functions are put in a library libw.a and is used
 * by application program to make system calls.
 ***************************************************************************/
#include <sys/process.h>
#include <sys/syscall.h>
#include <os_config.h>

#ifdef MICROBLAZE
#include <sys/mblaze_asm.h>
#define do_syscall(num,p1,p2,p3,p4,p5)  JMP_SYSCALL_HANDLER(num)
/*
 * The register r18 contains the system call number.
 * Branch is then made to the system call handler routine.
 */
#else
extern void *do_syscall(int syscall_num, void *param1, void *param2, void *param3, void *param4, void *param5);
#endif

/**************************************************************************/
/**
 * Same as sys_process_create() - Refer sys/process.c
 ***************************************************************************/
int process_create( unsigned int start, int prio ) 
{
	return ((int)do_syscall( _MB_Process_Create , (void *)start, (void *)prio, 0,0,0));
}

#ifdef CONFIG_PROCESS_EXIT
/**************************************************************************/
/**
 * Same as sys_exit() - Refer sys/process.c
 ***************************************************************************/
int process_exit()
{
  // tell the kernel to exit this process
  do_syscall( _MB_Process_Exit ,0,0,0,0,0);
  while(1); // loop forever, until process is removed by the kernel

}
#endif

#ifdef CONFIG_PROCESS_KILL
/**************************************************************************/
/**
 * Same as sys_process_kill() - Refer sys/process.c
 ***************************************************************************/
int process_kill( int pid )
{
  return (int) do_syscall( _MB_Process_Kill , (void *)pid, 0,0,0,0);
}
#endif

/**************************************************************************/
/**
 * Same as sys_process_status() - Refer sys/process.c
 ***************************************************************************/
int process_status( int pid, p_stat *ps )
{
  return ((int) do_syscall( _MB_Process_Status , (void *)pid, (void *)ps, 0,0,0));
}

#ifdef CONFIG_PROCESS_SLEEP
int process_sleep()
{
  return (int) do_syscall( _MB_Process_Sleep , 0,0,0,0,0);
}
#endif

#ifdef CONFIG_PROCESS_YIELD
/**************************************************************************/
/**
 * Same as sys_process_yield() - Refer sys/process.c
 ***************************************************************************/
int process_yield() 
{
  return (int) do_syscall( _MB_Process_Yield ,0,0,0,0,0);
}
#endif

int get_currentPID() 
{
  return (int) do_syscall( _MB_Process_GetPID ,0,0,0,0,0);
}

int process_getpriority()
{
  return (int) do_syscall( _MB_Process_GetPriority ,0,0,0,0,0);
}

int process_setpriority( int priority )
{
  return (int) do_syscall( _MB_Process_SetPriority , (void *)priority, 0,0,0,0);
}

