/*
 * Launch the kernel on a Deskstation Tyne
 *
 * Parameters: a0 - start address of the kernel image source
 *             a1 - size of the kernel image in bytes without header
 *             a2 - size of the loaded RAM disk image
 *
 * To do: move all initialisation stuff which will only bloat the kernel
 *        after having once been executed to this file.
 */
#include <asm/asm.h>
#include <asm/cachectl.h>
#include <asm/mipsregs.h>

		.text
		.set	noreorder
		NESTED(launch, 16, sp)
		subu	sp,16

		/*
		 * Disable Interrupts
		 */
		mfc0	t0,CP0_STATUS
		ori	t0,t0,1
		xori	t0,t0,1
		mtc0	t0,CP0_STATUS

		/*
		 * Move kernel image to destination
		 */
		lw      t0,C_LABEL(kernel_base)
1:		lbu	t1,(a0)
		subu	a1,a1,1
		sb	t1,(t0)
		addiu	a0,a0,1
		bnez	a1,1b
		addiu	t0,t0,1

		/*
		 * a0 now points to the RAM disk image start address
		 */
		beq	zero,a2,2f
		lw	t0,C_LABEL(kernel_bss_end)
1:		lbu	t1,(a0)
		subu	a2,a2,1
		sb	t1,(t0)
		addiu	a0,a0,1
		bne	zero,a2,1b
		addiu	t0,t0,1

2:		move	a0,zero
		li	a1,~0
		li	a2,BCACHE
		jal	C_LABEL(cacheflush)
	        nop
		jal	C_LABEL(clear_wb)		/* flush write buffer */
		nop

		/*
		 * launch the real thing
		 *
		 */
		lw	t0,C_LABEL(kernel_entry)
		nop
		jr	t0
		nop
		END(launch)
