/*
 *----------------------------------------------------------------------
 *    micro T-Kernel
 *
 *    Copyright (C) 2006-2011 by Ken Sakamura. All rights reserved.
 *    micro T-Kernel is distributed under the micro T-License.
 *----------------------------------------------------------------------
 *
 *    Version:   1.01.01
 *    Released by T-Engine Forum(http://www.t-engine.org) at 2011/07/29.
 *
 *----------------------------------------------------------------------
 */

/*
 *	cpu_insn.h (TWRK60N512)
 *	TWRK60N512-Dependent Operation
 */

/*
 *  for MB9BF618T on FRK-FM3
 * 
 *   Copyright (C) by Y.Ishioka.
 */

#ifndef _CPU_INSN_
#define _CPU_INSN_

#include <sys/sysinfo.h>
#include "cpu_status.h"
#if 0 /* Y.Ishioka */
#include "MK60N512MD100.h"
#include "core_cm4.h"
#else
#include "mb9bf618t.h"
#include "core_cm3.h"
#endif
/* ------------------------------------------------------------------------ */
/*
 *	Control register operation
 */

/*
 * Get BASEPRI
 */
IMPORT _knl_getBASEPRI(void);
Inline UINT knl_getBASEPRI(void)
	{
	UINT	basepri = _knl_getBASEPRI();
	return basepri;
	}

/* ------------------------------------------------------------------------ */
/*
 *	EIT-related
 */


/*
 *	Check Reserved SWI
 */
LOCAL BOOL IsReservedSWI(INT vecno)
	{

	BOOL reserved = FALSE;
	if ((vecno == SWI_SVC)
	||	(vecno == SWI_RETINT)
	||	(vecno == SWI_DEBUG)
	||	(vecno == SWI_DISPATCH_FROM_TKMAIN))
		{
		reserved = TRUE;
		}

	return reserved;
	}


/* Y.Ishioka */
IMPORT  void  Int_Dummy_Handler( void ) ;


/*
 * Set interrupt handler
 */
#define VTOR 0xE000ED08 /* Vector Table Offset Register */

IMPORT FP	knl_intvec[];
IMPORT void Default_Handler(void);

/* Y.Ishioka */
Inline void knl_define_inthdr( INT vecno, FP inthdr, UB intpri)
	{
	volatile UINT* vtor = (UINT*)VTOR;
	volatile UINT* hdrAddr = (UINT*)*vtor;
	int setVecNo;

	disint();

	if (vecno >= N_INTVEC && IsReservedSWI(vecno) )
		{
		enaint(0);
		return;
		}

	setVecNo = vecno;
	if (inthdr)
		{
		knl_intvec[setVecNo] = inthdr;
		}
		else
		{
		knl_intvec[setVecNo] = Int_Dummy_Handler;
		}

	enaint(0);
	return;
	}

/*
 * If it is the task-independent part, TRUE
 */
Inline BOOL knl_isTaskIndependent( void )
{
	return ( knl_taskindp > 0 )? TRUE: FALSE;
}

/*
 * Move to/Restore task independent part
 */
Inline void knl_EnterTaskIndependent( void )
{
	knl_taskindp++;
}
Inline void knl_LeaveTaskIndependent( void )
{
	knl_taskindp--;
}

/* ------------------------------------------------------------------------ */

#endif /* _CPU_INSN_ */
