/*///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2002 Xilinx, Inc.  All rights reserved.
//
// Xilinx, Inc.
// 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: soft_intr.S,v 1.1.2.1 2003/03/12 22:22:45 mohan Exp $
//
//////////////////////////////////////////////////////////////////////////////*/

/***************************************************************************/
/**
 * @file soft_intr.S 
 *
 * System call handler routine.
 ***************************************************************************/
#include <os_config.h>

	.globl _soft_interrupt_handler
	.globl _exception_handler
	.text
	.align 2
	.ent system_call_handler

/**
 * System call handler.
 * - Disable the interrupt.
 * - Refer the system call table and based on the system call number,branch 
 *   to the system call routine. Register r18 is used to indicate system call
 * number
 */
_exception_handler:	
_soft_interrupt_handler:
	addi r1, r1, -40
	swi r15, r1, 36
	swi r31, r1, 32
	
	mfs r31, rmsr 			/* Disable the Interupts */
	andi r31,r31, 0xfffffffd		 
	mts rmsr, r31 

	add r18,r18,r18
	add r18,r18,r18		 
	lwi r18, r18, syscall_table	/* Branch to the system call */
	brald  r15, r18		 
	nop

restore_all:
	mfs r12, rmsr
	//lwi r18,r0, intr_disabled 
	//bnei r18, 8

		ori r12,r12,2
	//lwi r18,r0, intr_type		/* Jump to the process location */
	//addi r18, r18, -1 
	//bnei r18, 12
	//	rtsd r14, 0
	//	mts rmsr,r12
	
	lwi r15, r1, 36
	lwi r31, r1, 32
	addi r1, r1, 40
	rtsd r15, 8
	mts rmsr,r12

	/*
	 * System call table - System call number defined in syscall.h
	 * If the module is not included in the system, then the location
	 * in the table is replaced by 0.
	 */
	.data
	.align 2
syscall_table:		/* System call table */ 
	.int 0 
	.int sys_process_create		/* Process handling functions */
	#ifdef CONFIG_PROCESS_EXIT
		.int sys_exit
	#else
		.int 0
	#endif
	#ifdef CONFIG_PROCESS_KILL
		.int sys_process_kill
	#else
		.int 0
	#endif
	.int sys_process_status
	#ifdef CONFIG_PROCESS_SLEEP
		.int sys_process_sleep
	#else
		.int 0
	#endif
	#ifdef CONFIG_PROCESS_YIELD
		.int sys_process_yield
	#else
		.int 0
	#endif

	.int sys_get_currentPID
	.int sys_process_getpriority
	.int sys_process_setpriority

	#ifdef CONFIG_THREAD_SUPPORT
	.int sys_thread_create		/* Thread handling functions */
	.int sys_thread_exit
	#else
		.int 0
		.int 0
	#endif

	#ifdef CONFIG_SEMA
	.int sys_sema_init		/* Semaphore handling functions */
	.int sys_sema_wait
	.int sys_sema_trywait
	.int sys_sema_post
	.int sys_sema_destroy
	#else
		.int 0
		.int 0
		.int 0
		.int 0
		.int 0
	#endif

	#ifdef CONFIG_MSGQ
	.int sys_msgget			/* Message Queue functions */
	.int sys_msgctl
	.int sys_msgsend
	.int sys_msgrecv
	#else
		.int 0
		.int 0
		.int 0
		.int 0
	#endif

	#ifdef CONFIG_SHM
	.int sys_shmget			/* Shared Memory Functions */
	.int sys_shmctl
	.int sys_shmat
	.int sys_shmdt
	#else
		.int 0
		.int 0
		.int 0
		.int 0
	#endif

	#ifdef CONFIG_MALLOC
	.int bufmalloc
	.int buffree
	#else
		.int 0
		.int 0
	#endif

	.int gettime			/* Timer related calls */
	.int settime
	.int sleep
	
	#ifdef CONFIG_MET
	.int xilsock_socket		/* xilnet related calls */
	.int xilsock_bind
	.int xilsock_listen
	.int xilsock_accept
	.int xilsock_recv
	.int xilsock_send
	.int xilsock_recv
	.int xilsock_sendto
	.int xilsock_close
	#else
		.int 0
		.int 0
		.int 0
		.int 0
		.int 0
		.int 0
		.int 0
		.int 0
		.int 0
	#endif

	.end system_call_handler
