/*
 * Load and switch to test image
 */

#include "common.h"
#include "irq.h"
#include "io.h"
#include "sys.h"

extern const char __dram_start[];
extern char __dram_test_start[];
abssymval(_dram_test_size)

extern no_return __start_test(void);

static inline void disable_abcmem(void)
{
    volatile uint32_t *pg = &ABCMEMMAP_PAGE(0);

    for (unsigned int addr = 0; addr < 0x10000; addr += 512)
	*pg++ = 0;
}

void __dram_text run_test_image(void)
{
    disable_abcmem();

    disable_irqs();

    romcopy_download(__dram_test_start,
		     __dram_test_start - __dram_start,
		     _dram_test_size());

    waitfor(ROMCOPY_IRQ);

    __start_test();
}
