;------------------------------------------------------------------------------
; Recovered startup assembly from STM32_FlashLoader.axf
;
; Original DWARF unit:
;   stm32f10x_vector.s
;   ARM/Thumb Macro Assembler, RVCT3.0 [Build 441]
;
; This loader is not a normal flash-resident STM32 vector table. The AXF entry is
; 0x20000000 in SRAM. Reset_Handler sets SP to 0x20002F20 and calls Main().
;------------------------------------------------------------------------------

                PRESERVE8
                THUMB

Stack_Size      EQU     0x00000200
Heap_Size       EQU     0x00000200

                AREA    HEAP, NOINIT, READWRITE, ALIGN=3
                EXPORT  __heap_base
                EXPORT  __heap_limit
__heap_base
Heap_Mem        SPACE   Heap_Size
__heap_limit

                AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
                EXPORT  __initial_sp
__initial_sp

                AREA    ER_RO, CODE, READONLY, ALIGN=2
                ENTRY

                IMPORT  Main
                IMPORT  __libspace_start

                EXPORT  Reset_Handler
                EXPORT  __user_initial_stackheap

; 0x20000000
Reset_Handler
                ; AXF bytes: DF F8 24 D0
                ; Loads SP from literal at +0x28. In the original image this
                ; literal is 0x20002F20, the address of __libspace_start.
                LDR.W   SP, =__libspace_start
                BL      Main
                NOP
                ALIGN

; 0x2000000C
endprogram
                BKPT    0
                BKPT    0

; 0x20000010
exception_handler
                BKPT    0
                BKPT    0

; 0x20000014
loop0
                NOP
                B       loop0

; 0x20000018
loop1
                NOP
                B       loop1

; 0x2000001C
; ARM two-region memory model hook.
; Returns:
;   R0 = heap base  = 0x20002F80 (__heap_base)
;   R1 = stack base = 0x20003380 (__initial_sp)
;   R2 = heap limit = 0x20003180 (__heap_limit)
;   R3 = stack limit/base = 0x20003180 (Stack_Mem)
__user_initial_stackheap
                LDR     R0, =__heap_base
                LDR     R1, =__initial_sp
                LDR     R2, =__heap_limit
                LDR     R3, =Stack_Mem
                BX      LR

                END
