exceptasm.s 2.18 KB
#include "regdef.h"
#include "asm.h"
#include "exceptasm.h"
#include <R4300.h>

#define BRK_KERNELBP	1
	.set	noat
LEAF(exception)
	/*
	 * Read the cause register; we're only interested in interrupts.
	 * (We are also interested in some exceptions, like CpU...)
	 */
	.set	noreorder
	mfc0	k0,C0_CAUSE
	.set	reorder
	andi	k0,CAUSE_EXCMASK
#ifdef _SYMMON
	li	k1,EXC_BREAK
	beq	k0,k1,handle_break
#endif

	bne	k0,k1,_Panic
	/*
	 * Not an interrupt, or an interrupt without a interrupt thread:
	 * print all of the registers and spin.
	 */
EXPORT(_Panic)

	la	k0,_ExceptionFrame

	sw	AT,EF_AT(k0);
	sw	v0,EF_V0(k0);
	sw	v0,EF_V1(k0);
	sw	a0,EF_A0(k0);
	sw	a1,EF_A1(k0);
	sw	a2,EF_A2(k0);
	sw	a3,EF_A3(k0);
	sw	t0,EF_T0(k0);
	sw	t1,EF_T1(k0);
	sw	t2,EF_T2(k0);
	sw	t3,EF_T3(k0);
	sw	t4,EF_T4(k0);
	sw	t5,EF_T5(k0);
	sw	t6,EF_T6(k0);
	sw	t7,EF_T7(k0);
	sw	s0,EF_S0(k0);
	sw	s1,EF_S1(k0);
	sw	s2,EF_S2(k0);
	sw	s3,EF_S3(k0);
	sw	s4,EF_S4(k0);
	sw	s5,EF_S5(k0);
	sw	s6,EF_S6(k0);
	sw	s7,EF_S7(k0);
	sw	t8,EF_T8(k0);
	sw	t9,EF_T9(k0);
	sw	gp,EF_GP(k0);
	sw	sp,EF_SP(k0);
	sw	s8,EF_S8(k0);
	sw	ra,EF_RA(k0);

	.set	noreorder
	mfc0	k1,C0_PAGEMASK
	nop
	sw	k1,EF_PAGEMASK(k0)
	mfc0	k1,C0_WIRED
	nop
	sw	k1,EF_WIRED(k0)
	mfc0	k1,C0_ENTRYLO0
	nop
	sw	k1,EF_ENTRYLO0(k0)
	mfc0	k1,C0_ENTRYLO1
	nop
	sw	k1,EF_ENTRYLO1(k0)
	mfc0	k1,C0_CONTEXT
	nop
	sw	k1,EF_CONTEXT(k0)
	mfc0	k1,C0_BADVADDR
	nop
	sw	k1,EF_BADVADDR(k0)
	mfc0	k1,C0_ENTRYHI
	nop
	sw	k1,EF_ENTRYHI(k0)
	mfc0	k1,C0_COMPARE
	nop
	sw	k1,EF_COMPARE(k0)
	mfc0	k1,C0_SR
	nop
	sw	k1,EF_SR(k0)
	mfc0	k1,C0_CAUSE
	nop
	sw	k1,EF_CAUSE(k0)
	mfc0	k1,C0_EPC
	nop
	sw	k1,EF_EPC(k0)
	mfc0	k1,C0_CONFIG
	nop
	sw	k1,EF_CONFIG(k0)
	.set	reorder

	jal	_ExceptionPrint

1:	b	1b

BSS(_atsave, 4)
BSS(_rasave, 4)

EXPORT(handle_break)
	.set	noreorder
	.set	noat
	move	k0,AT
	sw	k0,_atsave
	# jump to breakpoint handler
	lw	AT,SPB_DEBUGADDR		# address of debug block
	nop
	beq	AT,zero,2f
	nop
	lw	AT,DB_BPOFF(AT)			# breakpoint handle
	nop
	beq	AT,zero,2f
	nop
	lw	k0,_atsave
	j	AT
	nop
2:	j	ra
	nop
	END(exception)

	.set 	at
LEAF(debug)
	sw	ra,_rasave
	break	BRK_KERNELBP
	lw	ra,_rasave
	j	ra
	END(debug)


	.set	noreorder

LEAF(_ExceptionPreamble)
	la	k0,exception
	jr	k0
	nop
	END(_ExceptionPreamble)