#include <iregdef.h>
#include <idtcpu.h>
        .text
        .globl  inth
/* *************************************************************************
	Internal Handler
		This code will save all registers on the stack and then jump to the right Exception Handler
************************************************************************* */

inth:	sub	sp, sp, 128			// Make way for data on the stack

	/* *** STACK OVERVIEW ****
	*	0 	- t0
	*	4 	- t1
	*	8 	- t2
	*	12 	- t3
	*	16	- ra
	*	20	- EPC
	*	24	- CAUSE
	********************** */
	
	sw	t0, 0(sp)
	sw	t1, 4(sp)
	sw	t2, 8(sp)
	sw	t3, 12(sp)
	sw	ra, 16(sp)

	mfc0	t0, C0_EPC
	nop

	mfc0	t1, C0_CAUSE
	nop

	sw	t0, 20(sp)
	sw	t1, 24(sp)

	la	t0,  ExceptionTable		// Load our table
	and	t1, t1, 0x7c			// Get the right value that is in CAUSE by masking it
	add	t0, t0, t1			// Add the value from CAUSE to the ExceptionTable
	lw	t0, 0(t0)			// Load the adress

	jr	t0				// Jump to the Position given in the Table

	
	

