/*///////////////////////////////////////////////////////////////////////////
//
// 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.
// 
// Date   : 2002, November.
// Author : Raj Nagarajan (rajn@xilinx.com)
// Company: Xilinx
// Group  : Emerging Software Technologies
//
// $Id :$
//
/////////////////////////////////////////////////////////////////////////////*/

/*
 * timer_intr.S - Timer interrupt handler
 */
 
#include <sys/mblaze_asm.h>

	.globl _interrupt_handler
	.text
	.align 2
	.extern process_scheduler	 
	.extern kernel_sp		 
	.extern scontext		 
	.extern intr_type		 
	.ent timer_intr_handler

/*
 * - Save the context of the current process.
 * - Switch to the kernel context.
 * - Call the process scheduler, which stores the context of the next process
 * - Restore the context of the next process and return based on interrupt
 *   type to the process.
 */
 
_interrupt_handler:
	SAVE_ALL			/* Save the process context */
	//lwi r1,r0, kernel_sp		/* Switch to kernel context */
	//addi r18,r0,0x01		 
	//swi r18,r0, intr_type 
	brlid r15,process_scheduler	/* Branch to process_scheduler */
	nop
	
	RESTORE_ALL			/* Restore the process context */
	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
	//rtsd r15, 8
	//mts rmsr,r12
	
	.end timer_intr_handler
