		.file	"kernel.S"

		.section .ktext,"ax"
		.align	2

		.macro kpush reg
		addiu	$sp, 4
		sw		\reg, 0($sp)
		.endm
		
		.macro kpop reg
		lw		\reg, 0($sp)
		addiu	$sp, -4
		.endm

_exc_handler:

		.set	noreorder
		
		# Set Error LED and ExcCode LEDs
		# Get Cause
		mfc0	$26, $13
		li 		$27, 0xC0000000
		srl		$26, 2
		andi	$26, 0x000F
		or 		$26, $27
		la 		$27, sys_led_port
		sw 		$26, 0($27)

		# wait for all interrupts = 0
$w4x:	mfc0	$26, $13
		nop
		srl		$26, 8
		andi	$26, 0xFF
		bnez	$26, $w4x
		nop
		
		# Get return address
		mfc0	$26, $14

		# Return
		nop
		jr	$26
		rfe
		.set	reorder
	
