/*
*	External functions defined by the library
*/

	.globl		BZ_IrqEntry			// IRQ handler entry point

/*
*	External functions defined by you
*/

	.globl		FatalError			// A fatal error occured
	.globl		SystemEntry			// C routine to boot the system

/*
*	Exception vector table in FLASH.
*	This table is in its own section, which must be
*	placed at 0 by the linker. We don't have to align,
*	because we *know* that it is aligned (being at 0).
*	Apart from reset and normal interrupt, we consider everything,
*	including FIQ as fatal error.
*/

	.section	.vectors,"ax",%progbits
	.code		32					// Indicate that it's ARM code
	b		reset					// Reset
	b		FatalError				// Undefined instruction (UND)
	b		FatalError				// Supervisor call (SVI)
	b		FatalError				// Instruction prefetch abort (ABT)
	b		FatalError				// Data access abort (ABT)
	.word	0						// Unused by the ARM7TDMI core
	b		BZ_IrqEntry				// Interrupt (IRQ)
	b		FatalError				// Fast interrupt (FIQ)

/*
*	Reset code. It could go into the code segment or can
*	reside in the .vectors segment. We choose the latter.
*	Since in case of a fatal error we can't really do much,
*	we do not use a separate stack, we simply use the interrupt
*	stack.
*/

reset:
	ldr		r0,irq_stk				// Get the address of the stack
	msr		cpsr,#0xd7				// Set ABT mode
	mov		sp,r0					// Set the ABT stack
	msr		cpsr,#0xdb				// Set UND mode
	mov		sp,r0					// Set the UND stack
	msr		cpsr,#0xd3				// Set SVI mode
	mov		sp,r0					// Set the SVI stack
	msr		cpsr,#0xd1				// Set FIQ mode
	mov		sp,r0					// Set the FIQ stack
	msr		cpsr,#0xd2				// Set IRQ mode
	mov		sp,r0					// Set the IRQ stack
	ldr		r0,sysinit				// Get boot code address
	bx		r0						// Start it (in IRQ mode)

/*
*	Addresses of various objects
*/

irq_stk:	.word	istack
sysinit:	.word	SystemEntry

/*
*	Stack for everything except system mode.
*
*	Note that we put the stacks into their own segment, not into the
*	bss. That's because we will clear the bss to 0 and it would be
*	most unhealthy to zero the stack we're currently running on...
*/

	.section	.stack,"aw",%nobits
	.align	3						// Align to 8-byte boundary
	.space	512						// 1/2 KB interrupt stack
istack:								// Defined *after* the stackspace!

	.end

