entry.s 1.07 KB
#include <regdef.h>
#include <asm.h>
#include <PR/R4300.h>

#include <PR/bcp.h>

#include "boot.h"

// XXX: t7 is reserved for use in TRACE macros, do not use.

.text
.align 2
.set    noreorder 
.globl __entry
__entry:
	# this must be done before any lw or sw
	mtc0	zero, C0_WATCHLO
	mtc0	zero, C0_WATCHHI

	# poll virage2 ctrl for ready bit
	la	t0, PHYS_TO_K1(VIRAGE2_CTRL_REG)
virage2_poll:
	lw	t1, 0(t0)
	and	t2, t1, VIRAGE_CTRL_NV_RCREADY
	beqz	t2, virage2_poll
	nop
	
patch1_return:
	# take IDE out of reset  so future TRACEs will work
	li	t0, PHYS_TO_K1(PI_IDE_CONFIG_REG)
	lw	t1, 0(t0)
	and	t1, ~PI_IDE_CONFIG_RESET
	sw	t1, 0(t0)
	
	TRACE_VAL(0x1)
	
        # copy ROM code to IRAM
        #   t0: dst
        #   t2: src
        #   t1: end
        la      t0, PHYS_TO_K1(INTERNAL_RAM_START)
        la      t2, __s_la_text
        la      t1, __e_text 
copy_rom_to_iram:
        lw      t3, 0(t2)  # the rom instruction
        sw      t3, 0(t0)  # save to iram
        addu    t0, 4      
        bltu    t0, t1, copy_rom_to_iram
        addu    t2, 4

	la	t0, __start
	jr	t0
	nop