#define mmio32(x) (*(volatile unsigned long *)(x))
#define __disable_irq() __asm__ volatile("CPSID i":::"memory");
#define __enable_irq() __asm__ volatile("CPSIE i":::"memory");
typedef long unsigned int uint32_t;
extern void main(void);
__attribute__((section(".vectable")))
uint32_t irq_table[256 + 16];
extern unsigned long _stextload;
extern unsigned long _stext;
extern unsigned long _etext;
extern unsigned long _sdataload;
extern unsigned long _sdata;
extern unsigned long _edata;
extern unsigned long _sbss;
extern unsigned long _ebss;
extern unsigned long _heap_end;
extern unsigned long _heap_start;
extern unsigned long _flexram_bank_config;
extern unsigned long _estack;
extern unsigned long _flashimagelen;
void startup(void);
static void memory_copy(uint32_t *dest, const uint32_t *src, uint32_t *dest_end);
static void memory_clear(uint32_t *dest, uint32_t *dest_end);
__attribute__((section(".startup"), optimize("no-tree-loop-distribute-patterns"), naked))
void startup() {
mmio32(0x400AC000 + 0x44) = (uint32_t)&_flexram_bank_config;
mmio32(0x400AC000 + 0x40) = 0x00000007;
mmio32(0x400AC000 + 0x38) = 0x00AA0000;
mmio32(0xE000ED88) = mmio32(0xE000ED88) | (0xFF<<20);
__asm__ volatile("isb");
__asm__ volatile("dsb");
__asm__ volatile("mov sp, %0" : : "r" ((uint32_t)&_estack) : );
memory_copy(&_stext, &_stextload, &_etext);
memory_copy(&_sdata, &_sdataload, &_edata);
memory_clear(&_sbss, &_ebss);
irq_table[0] = (uint32_t)&_estack;
uint32_t addr = (uint32_t)&irq_table;
mmio32(0xE000ED08) = addr;
__asm__ volatile("b main");
}
__attribute__((section(".bootdata"), used))
const uint32_t BootData[3] = {
0x60000000,
(uint32_t)&_flashimagelen,
0};
__attribute__((section(".ivt"), used))
const uint32_t ImageVectorTable[8] = {
0x402000D1, (uint32_t)startup, 0, 0, (uint32_t)BootData, (uint32_t)ImageVectorTable, 0, 0 };
__attribute__((section(".flashconfig"), used))
uint32_t FlexSPI_NOR_Config[128] = {
0x42464346, 0x56010000, 0, 0x00020101,
0x00000000, 0, 0, 0x00000000,
0, 0,
0,
0,
0, 0,
0,
0,
0x00000000, 0x00030401, 0, 0,
0x00200000, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0x00000000,
0x0A1804EB, 0x26043206, 0, 0,
0x24040405, 0, 0, 0,
0, 0, 0, 0,
0x00000406, 0, 0, 0,
0, 0, 0, 0,
0x08180420, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0x081804D8, 0, 0, 0,
0x08180402, 0x00002004, 0, 0,
0, 0, 0, 0,
0x00000460, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
256, 4096, 1, 0,
0x00010000, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0 };
__attribute__((section(".startup"), used, optimize("no-tree-loop-distribute-patterns")))
static void memory_copy(uint32_t *dest, const uint32_t *src, uint32_t *dest_end)
{
if (dest == src)
return;
while (dest < dest_end)
{
*dest++ = *src++;
}
}
__attribute__((section(".startup"), used, optimize("no-tree-loop-distribute-patterns")))
static void memory_clear(uint32_t *dest, uint32_t *dest_end)
{
while (dest < dest_end)
{
*dest++ = 0;
}
}