/* boot.S
 *
 * Contains diagnostics code entry point and minimal code
 * to detect Wallaby Bootloader version and to load rest of
 * the diagnostics image from the SD card.
 *
 * Makes calls to init.c. Compiled code in boot.S and init.c
 * may not exceed 512 bytes (must fit in first block read from
 * SD card).
 */

#define _C_FUNC(x_) /**/x_/**/
#define ENTRY(name) .globl name; \
                    name:
                    
ENTRY(_start)
    /* Detect Wallaby version */
    bl      _C_FUNC( detect_version )
    cmp     r0, #0
    beq     skippatch
    
    /* Free up stack space */
    mov     r0, #0x40000
    orr     r0, r0, #0x1c
    add     sp, sp, r0
    
    /* Diagnostics main code */
    bl      _C_FUNC( diag_main )
    
    /* Return from diagnostics code */
    ldmfd   sp!, {r4-r11,pc}
    
skippatch:
    /* Free up stack space */
    mov     r0, #0x40000
    orr     r0, r0, #0x1c
    add     sp, sp, r0
    
    /* Return from diagnostics code */
    ldmfd   sp!, {r4-r11,pc}
    
