.syntax unified
.cpu cortex-m4

.section .text
.thumb_func
_startup:
    /* zero .bss section */
    ldr r0, =_bss_start
    ldr r1, =_bss_end
    movs r2, #0
1:  cmp r0, r1
    itt lt
    strlt r2, [r0], #4
    blt 1b
2:
    bl main
1:  b 1b

.section .text
.global _init
/* cold boot from ROM */
_init:
    ldr sp, =_stack_top
    ldr r0, =_vector_table
    ldr r1, =0xE000ED08
    str r0, [r1]

    b _startup

.section .vectors
.global _vector_table
_vector_table:
    /* Core Cortex-M4 Vectors */
    .word _stack_top               /* 0: Initial Stack Pointer */
    .word Reset_Handler            /* 1: Reset */
    .word NMI_Handler              /* 2: NMI */
    .word HardFault_Handler        /* 3: Hard Fault */
    .word MemManage_Handler        /* 4: Memory Management Fault */
    .word BusFault_Handler         /* 5: Bus Fault */
    .word UsageFault_Handler       /* 6: Usage Fault */
    .word SecureFault_Handler      /* 7: Secure Fault */
    .word 0                        /* 8: Reserved */
    .word 0                        /* 9: Reserved */
    .word 0                        /* 10: Reserved */
    .word SVC_Handler              /* 11: SVCall */
    .word DebugMon_Handler         /* 12: Debug Monitor */
    .word 0                        /* 13: Reserved */
    .word PendSV_Handler           /* 14: PendSV */
    .word SysTick_Handler          /* 15: SysTick */
    /* RTL8710BX Specific Interrupts */
    .word PWR_Wakeup_Handler       /* 16: Power Wakeup */
    .word WDG_Handler              /* 17: Watchdog */
    .word TIM0_Handler             /* 18: Timer 0 */
    .word TIM1_Handler             /* 19: Timer 1 */
    .word TIM2_Handler             /* 20: Timer 2 */
    .word TIM3_Handler             /* 21: Timer 3 */
    .word SPI0_Handler             /* 22: SPI0 */
    .word GPIO_Handler             /* 23: GPIO */
    .word UART0_Handler            /* 24: UART0 */
    .word FLASH_Handler            /* 25: Flash */
    .word UART1_Handler            /* 26: UART1 */
    .word TIM4_Handler             /* 27: Timer 4 */
    .word SDIO_Handler             /* 28: SDIO */
    .word I2S0_PCM0_Handler        /* 29: I2S0/PCM0 */
    .word TIM5_Handler             /* 30: Timer 5 */
    .word WLAN_DMA_Handler         /* 31: WLAN DMA */
    .word WLAN_Protocol_Handler    /* 32: WLAN Protocol */
    .word Crypto_Handler           /* 33: Cryptography */
    .word SPI1_Handler             /* 34: SPI1 */
    .word Periph_Handler           /* 35: Peripheral */
    .word DMA0_Channel0_Handler    /* 36: DMA0 Channel 0 */
    .word DMA0_Channel1_Handler    /* 37: DMA0 Channel 1 */
    .word DMA0_Channel2_Handler    /* 38: DMA0 Channel 2 */
    .word DMA0_Channel3_Handler    /* 39: DMA0 Channel 3 */
    .word DMA0_Channel4_Handler    /* 40: DMA0 Channel 4 */
    .word DMA0_Channel5_Handler    /* 41: DMA0 Channel 5 */
    .word I2C0_Handler             /* 42: I2C0 */
    .word I2C1_Handler             /* 43: I2C1 */
    .word UART_Log_Handler         /* 44: Log UART */
    .word ADC_Handler              /* 45: ADC */
    .word RDP_Handler              /* 46: CPU RDP */
    .word RTC_Handler              /* 47: RTC */
    .word DMA1_Channel0_Handler    /* 48: DMA1 Channel 0 */
    .word DMA1_Channel1_Handler    /* 49: DMA1 Channel 1 */
    .word DMA1_Channel2_Handler    /* 50: DMA1 Channel 2 */
    .word DMA1_Channel3_Handler    /* 51: DMA1 Channel 3 */
    .word DMA1_Channel4_Handler    /* 52: DMA1 Channel 4 */
    .word DMA1_Channel5_Handler    /* 53: DMA1 Channel 5 */
    .word USB_Handler              /* 54: USB */
    .word RXI300_Handler           /* 55: RXI300 */
    .word USB_SIE_Handler          /* 56: USB SIE */

/* If you don't override a specific handler, it will just spin forever. */
.section .text
.thumb_func
Default_Handler:
    b Default_Handler

/* weak alias all interrupts */
.weak NMI_Handler
.thumb_set NMI_Handler,Default_Handler

.weak HardFault_Handler
.thumb_set HardFault_Handler,Default_Handler

.weak MemManage_Handler
.thumb_set MemManage_Handler,Default_Handler

.weak BusFault_Handler
.thumb_set BusFault_Handler,Default_Handler

.weak UsageFault_Handler
.thumb_set UsageFault_Handler,Default_Handler

.weak SecureFault_Handler
.thumb_set SecureFault_Handler,Default_Handler

.weak SVC_Handler
.thumb_set SVC_Handler,Default_Handler

.weak DebugMon_Handler
.thumb_set DebugMon_Handler,Default_Handler

.weak PendSV_Handler
.thumb_set PendSV_Handler,Default_Handler

.weak SysTick_Handler
.thumb_set SysTick_Handler,Default_Handler

/* RTL8710BX specific handlers */
.weak PWR_Wakeup_Handler
.thumb_set PWR_Wakeup_Handler,Default_Handler

.weak WDG_Handler
.thumb_set WDG_Handler,Default_Handler

.weak TIM0_Handler
.thumb_set TIM0_Handler,Default_Handler

.weak TIM1_Handler
.thumb_set TIM1_Handler,Default_Handler

.weak TIM2_Handler
.thumb_set TIM2_Handler,Default_Handler

.weak TIM3_Handler
.thumb_set TIM3_Handler,Default_Handler

.weak SPI0_Handler
.thumb_set SPI0_Handler,Default_Handler

.weak GPIO_Handler
.thumb_set GPIO_Handler,Default_Handler

.weak UART0_Handler
.thumb_set UART0_Handler,Default_Handler

.weak FLASH_Handler
.thumb_set FLASH_Handler,Default_Handler

.weak UART1_Handler
.thumb_set UART1_Handler,Default_Handler

.weak TIM4_Handler
.thumb_set TIM4_Handler,Default_Handler

.weak SDIO_Handler
.thumb_set SDIO_Handler,Default_Handler

.weak I2S0_PCM0_Handler
.thumb_set I2S0_PCM0_Handler,Default_Handler

.weak TIM5_Handler
.thumb_set TIM5_Handler,Default_Handler

.weak WLAN_DMA_Handler
.thumb_set WLAN_DMA_Handler,Default_Handler

.weak WLAN_Protocol_Handler
.thumb_set WLAN_Protocol_Handler,Default_Handler

.weak Crypto_Handler
.thumb_set Crypto_Handler,Default_Handler

.weak SPI1_Handler
.thumb_set SPI1_Handler,Default_Handler

.weak Periph_Handler
.thumb_set Periph_Handler,Default_Handler

.weak DMA0_Channel0_Handler
.thumb_set DMA0_Channel0_Handler,Default_Handler

.weak DMA0_Channel1_Handler
.thumb_set DMA0_Channel1_Handler,Default_Handler

.weak DMA0_Channel2_Handler
.thumb_set DMA0_Channel2_Handler,Default_Handler

.weak DMA0_Channel3_Handler
.thumb_set DMA0_Channel3_Handler,Default_Handler

.weak DMA0_Channel4_Handler
.thumb_set DMA0_Channel4_Handler,Default_Handler

.weak DMA0_Channel5_Handler
.thumb_set DMA0_Channel5_Handler,Default_Handler

.weak I2C0_Handler
.thumb_set I2C0_Handler,Default_Handler

.weak I2C1_Handler
.thumb_set I2C1_Handler,Default_Handler

.weak UART_Log_Handler
.thumb_set UART_Log_Handler,Default_Handler

.weak ADC_Handler
.thumb_set ADC_Handler,Default_Handler

.weak RDP_Handler
.thumb_set RDP_Handler,Default_Handler

.weak RTC_Handler
.thumb_set RTC_Handler,Default_Handler

.weak DMA1_Channel0_Handler
.thumb_set DMA1_Channel0_Handler,Default_Handler

.weak DMA1_Channel1_Handler
.thumb_set DMA1_Channel1_Handler,Default_Handler

.weak DMA1_Channel2_Handler
.thumb_set DMA1_Channel2_Handler,Default_Handler

.weak DMA1_Channel3_Handler
.thumb_set DMA1_Channel3_Handler,Default_Handler

.weak DMA1_Channel4_Handler
.thumb_set DMA1_Channel4_Handler,Default_Handler

.weak DMA1_Channel5_Handler
.thumb_set DMA1_Channel5_Handler,Default_Handler

.weak USB_Handler
.thumb_set USB_Handler,Default_Handler

.weak RXI300_Handler
.thumb_set RXI300_Handler,Default_Handler

.weak USB_SIE_Handler
.thumb_set USB_SIE_Handler,Default_Handler

/* Reset_Handler will be global */
.global Reset_Handler

.section .text
.thumb_func
Reset_Handler:
    b _startup

.end
