
.syntax unified
.cpu cortex-m0plus
.thumb

.section .boot2, "ax"
.word 0x4b32b500
.word 0x60582021
.word 0x21026898
.word 0x60984388
.word 0x611860d8
.word 0x4b2e6158
.word 0x60992100
.word 0x61592102
.word 0x22f02101
.word 0x492b5099
.word 0x21016019
.word 0x20356099
.word 0xf844f000
.word 0x42902202
.word 0x2106d014
.word 0xf0006619
.word 0x6e19f834
.word 0x66192101
.word 0x66182000
.word 0xf000661a
.word 0x6e19f82c
.word 0x6e196e19
.word 0xf0002005
.word 0x2101f82f
.word 0xd1f94208
.word 0x60992100
.word 0x6019491b
.word 0x60592100
.word 0x481b491a
.word 0x21016001
.word 0x21eb6099
.word 0x21a06619
.word 0xf0006619
.word 0x2100f812
.word 0x49166099
.word 0x60014814
.word 0x60992101
.word 0x2800bc01
.word 0x4700d000
.word 0x49134812
.word 0xc8036008
.word 0x8808f380
.word 0xb5034708
.word 0x20046a99
.word 0xd0fb4201
.word 0x42012001
.word 0xbd03d1f8
.word 0x6618b502
.word 0xf7ff6618
.word 0x6e18fff2
.word 0xbd026e18
.word 0x40020000
.word 0x18000000
.word 0x00070000
.word 0x005f0300
.word 0x00002221
.word 0x180000f4
.word 0xa0002022
.word 0x10000100
.word 0xe000ed08
.word 0x00000000
.word 0x00000000
.word 0x00000000
.word 0x7a4eb274


.section .vectors, "ax"
.align 2

.global __vectors
__vectors:
.word __StackTop
.word _reset_handler
.word isr_nmi
.word isr_hardfault
.word isr_invalid @ Reserved, should never fire
.word isr_invalid @ Reserved, should never fire
.word isr_invalid @ Reserved, should never fire
.word isr_invalid @ Reserved, should never fire
.word isr_invalid @ Reserved, should never fire
.word isr_invalid @ Reserved, should never fire
.word isr_invalid @ Reserved, should never fire
.word isr_svcall
.word isr_invalid @ Reserved, should never fire
.word isr_invalid @ Reserved, should never fire
.word isr_pendsv
.word isr_systick
.word isr_irq0
.word isr_irq1
.word isr_irq2
.word isr_irq3
.word isr_irq4
.word isr_irq5
.word isr_irq6
.word isr_irq7
.word isr_irq8
.word isr_irq9
.word isr_irq10
.word isr_irq11
.word isr_irq12
.word isr_irq13
.word isr_irq14
.word isr_irq15
.word isr_irq16
.word isr_irq17
.word isr_irq18
.word isr_irq19
.word isr_irq20
.word isr_irq21
.word isr_irq22
.word isr_irq23
.word isr_irq24
.word isr_irq25
.word isr_irq26
.word isr_irq27
.word isr_irq28
.word isr_irq29
.word isr_irq30
.word isr_irq31


.macro decl_isr_bkpt name
.weak \name
.type \name,%function
.thumb_func
\name:
    bkpt #0
.endm

decl_isr_bkpt isr_invalid
decl_isr_bkpt isr_nmi
decl_isr_bkpt isr_hardfault
decl_isr_bkpt isr_svcall
decl_isr_bkpt isr_pendsv
decl_isr_bkpt isr_systick

.macro decl_isr name
.weak \name
.type \name,%function
.thumb_func
\name:
.endm

decl_isr isr_irq0
decl_isr isr_irq1
decl_isr isr_irq2
decl_isr isr_irq3
decl_isr isr_irq4
decl_isr isr_irq5
decl_isr isr_irq6
decl_isr isr_irq7
decl_isr isr_irq8
decl_isr isr_irq9
decl_isr isr_irq10
decl_isr isr_irq11
decl_isr isr_irq12
decl_isr isr_irq13
decl_isr isr_irq14
decl_isr isr_irq15
decl_isr isr_irq16
decl_isr isr_irq17
decl_isr isr_irq18
decl_isr isr_irq19
decl_isr isr_irq20
decl_isr isr_irq21
decl_isr isr_irq22
decl_isr isr_irq23
decl_isr isr_irq24
decl_isr isr_irq25
decl_isr isr_irq26
decl_isr isr_irq27
decl_isr isr_irq28
decl_isr isr_irq29
decl_isr isr_irq30
decl_isr isr_irq31


.global __unhandled_user_irq
.thumb_func
__unhandled_user_irq:
    bl __get_current_exception
    subs r0, #16
.global unhandled_user_irq_num_in_r0
unhandled_user_irq_num_in_r0:
    bkpt #0


.section .binary_info_header, "a"
binary_info_header:
@.word BINARY_INFO_MARKER_START
.word	0x7188ebf2
.word __binary_info_start
.word __binary_info_end
.word data_cpy_table 
@.word BINARY_INFO_MARKER_END
.word	0xe71aa390


.section .reset, "ax"


.thumb_func
.global _entry_point
_entry_point:
    movs r0, #0
    ldr r1, =0xe000ed08
    str r0, [r1]
    ldmia r0!, {r1, r2}
    msr msp, r1
    bx r2



.thumb_func
_reset_handler:
    	ldr	r0, =0xd0000000
      	ldr	r0, [r0, #0]
     	cmp	r0, #0
      	bne	hold_non_core0_in_bootrom

    adr r4, data_cpy_table

1:
    ldmia r4!, {r1-r3}
    cmp r1, #0
    beq 2f
    bl data_cpy
    b 1b
2:

    ldr r1, =__bss_start__
    ldr r2, =__bss_end__
    movs r0, #0
    b bss_fill_test
bss_fill_loop:
    stm r1!, {r0}
bss_fill_test:
    cmp r1, r2
    bne bss_fill_loop

platform_entry:
    ldr r0,=main
    blx r0
    b loop
loop:
    b loop

.thumb_func
hold_non_core0_in_bootrom:
      	ldr	r0, =0x00005657
 	bl	rom_func_lookup
      	bx	r0

.global __get_current_exception
.thumb_func
__get_current_exception:
    mrs  r0, ipsr
    uxtb r0, r0
    bx   lr

.thumb_func
rom_func_lookup:
      	movs	r3, #20
      	push	{r4, lr}
      	movs	r1, r0
      	ldrh	r0, [r3, #0]
      	adds	r3, #4
      	ldrh	r3, [r3, #0]
      	blx	r3
      	pop	{r4, pc}


data_cpy_loop:
    ldm r1!, {r0}
    stm r2!, {r0}
data_cpy:
    cmp r2, r3
    blo data_cpy_loop
    bx lr

.align 2
data_cpy_table:
.word __etext
.word __data_start__
.word __data_end__

.word __scratch_x_source__
.word __scratch_x_start__
.word __scratch_x_end__

.word __scratch_y_source__
.word __scratch_y_start__
.word __scratch_y_end__

.word 0

.align 4
.ltorg

.thumb_func
.globl multicore_launch_core1
.align 2
multicore_launch_core1:
	push	{r4, r5, lr}
	sub	sp, #28
      	str	r0, [sp, #20]
	ldr	r1, =0x20040800+0x7fc
      	str	r1, [sp, #16]
      	ldr	r2, =0xe000ed08
      	ldr	r2, [r2]
      	str	r2, [sp, #12]
	movs	r1, #1
	str	r1, [sp, #8]
	movs	r1, #0
      	str	r1, [sp, #4]
      	str	r1, [sp, #0]
      	movs	r5, #0
L2:
      	mov	r4, sp
      	lsls	r2, r5, #2
      	ldr	r4, [r4, r2]
	cmp	r4, #0
	bne	L3
	bl	multicore_fifo_drain
	sev
L3:
	mov	r0, r4
	bl	multicore_fifo_push_blocking
	bl	multicore_fifo_pop_blocking
	cmp	r0, r4
	beq	L4
	movs	r5, #0
L4:
      	adds	r5, #1
      	cmp	r5, #5
      	bls	L2
      	add	sp, #28
     	pop	{r4, r5, pc}


.thumb_func
.align	2
multicore_fifo_drain:
	push	{r0, r1, r2, lr}
	ldr	r0, =0xd0000000
	movs	r1, #1
3:
	ldr	r2, [r0, #0x50]	@ FIFO_ST
	ands	r2, r1
	beq	2f
1:
	ldr	r2, [r0, #0x58] @ dummy read
	b	3b
2:
	pop	{r0, r1, r2, pc}


.globl multicore_fifo_push_blocking
.thumb_func
.align	2
multicore_fifo_push_blocking:
	push	{r1, r2, r3, lr}
	ldr	r2, =0xd0000000
      	movs	r1, #2
MF1:
      	ldr	r3, [r2, #0x50] @ FIFO_ST
      	tst	r1, r3          @ wait until FIFO is not full
      	beq	MF1
      	str	r0, [r2, #0x54] @ FIFO_WR (send)
      	sev
      	pop	{r1, r2, r3, pc}

.globl multicore_fifo_pop_blocking
.thumb_func
.align	2
multicore_fifo_pop_blocking:
	push	{r1, r2, r3, lr}
	ldr	r2, =0xd0000050 @ FIFO_ST
      	ldr	r3, [r2]
      	lsls	r3, r3, #31     @ is FIFO valid?
      	bmi.n	MF2             @ if valid, return FIFO value
      	movs	r1, #1
MF3:
      	wfe
      	ldr	r3, [r2]
      	tst	r1, r3          @ wait until FIFO un-empty
      	beq	MF3
MF2:
	ldr	r3, =0xd0000058 @ FIFO_RD
      	ldr	r0, [r3]        @ receive
      	pop	{r1, r2, r3, pc}
