/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */
#include <arm.h>
#include <asm.h>
#include <hw.h>

        .text
        .code 32
        .align 0
        .global _start

_start:
        b     iosResetHandler
        sub     pc, pc, #8  /* Undefined */
        sub     pc, pc, #8  /* SWI */
        sub     pc, pc, #8  /* Prefetch Abort */
        sub     pc, pc, #8  /* Data Abort */
        sub     pc, pc, #8  /* Reserved */
        sub     pc, pc, #8  /* IRQ */
        sub     pc, pc, #8  /* FIQ */

iosResetHandler:
         /* Zero the bss */
        ldr     r0, =__bss_start
        ldr     r1, =__bss_end
        ldr     r2, =0
        ldr     r3, =4
        bl      word_set
        
        /* Enable 96K SRAM */
#define ACRSPARE1_REG (ACR_PROT_REGS_BASE+ACRSPARE1_OFFSET)
        ldr     r0, = ACRSPARE1_REG
        ldr     r1, [r0]
        orr     r1, r1, #ACRSPARE1_ENABLE_96K_MASK
        str     r1, [r0]

        /* Set sp to point to top of stack */
        ldr r2, =_initStackSize
        ldr r2, [r2]
        ldr sp, =_initStack
        add sp, sp, r2

        /* Jump to minimon0 */
        mov     lr, pc                         
        ldr     pc, =minimon0                  @ Now that stacks are setup
inf:
        b       inf                         @ we should never get here

word_set:
        cmp     r0, r1
        bcs     1f
        str     r2, [r0], r3
        b       word_set
1:
        bx      lr



        .end
