2018-03-14 20:14:02 +00:00
|
|
|
.macro CLEAR_GPR_REG_ITER
|
|
|
|
mov r\@, #0
|
|
|
|
.endm
|
|
|
|
|
2018-05-06 23:02:23 +00:00
|
|
|
.section .text.start, "ax", %progbits
|
2018-03-14 20:14:02 +00:00
|
|
|
.arm
|
|
|
|
.align 5
|
|
|
|
.global _start
|
2018-05-06 23:02:23 +00:00
|
|
|
.type _start, %function
|
2018-03-14 20:14:02 +00:00
|
|
|
_start:
|
2018-05-07 21:32:45 +00:00
|
|
|
/* Switch to system mode, mask all interrupts, clear all flags */
|
2018-03-14 20:14:02 +00:00
|
|
|
msr cpsr_cxsf, #0xDF
|
|
|
|
|
|
|
|
/* Relocate ourselves if necessary */
|
2018-04-08 11:06:04 +00:00
|
|
|
ldr r2, =__start__
|
|
|
|
adr r3, _start
|
|
|
|
cmp r2, r3
|
2018-03-14 20:14:02 +00:00
|
|
|
bne _relocation_loop_end
|
|
|
|
|
2018-04-08 11:06:04 +00:00
|
|
|
ldr r4, =__bss_start__
|
2018-05-07 21:32:45 +00:00
|
|
|
sub r4, r4, r2 /* size >= 32, obviously, and we've declared 32-byte-alignment */
|
2018-03-14 20:14:02 +00:00
|
|
|
_relocation_loop:
|
2018-04-08 11:06:04 +00:00
|
|
|
ldmia r3!, {r5-r12}
|
|
|
|
stmia r2!, {r5-r12}
|
|
|
|
subs r4, #0x20
|
2018-03-14 20:14:02 +00:00
|
|
|
bne _relocation_loop
|
|
|
|
|
|
|
|
ldr r12, =_relocation_loop_end
|
|
|
|
bx r12
|
|
|
|
|
|
|
|
_relocation_loop_end:
|
|
|
|
/* Set the stack pointer */
|
2018-05-07 21:32:45 +00:00
|
|
|
ldr sp, =__stack_top__
|
|
|
|
mov fp, #0
|
|
|
|
bl __program_init
|
2018-03-14 20:14:02 +00:00
|
|
|
|
2018-05-07 21:32:45 +00:00
|
|
|
/* Set r0 to r12 to 0 (for debugging) & call main */
|
2018-03-14 20:14:02 +00:00
|
|
|
.rept 13
|
|
|
|
CLEAR_GPR_REG_ITER
|
|
|
|
.endr
|
2018-05-07 21:32:45 +00:00
|
|
|
ldr r0, =__program_argc
|
|
|
|
ldr r1, =__program_argv
|
|
|
|
ldr lr, =__program_exit
|
2018-05-08 12:44:28 +00:00
|
|
|
ldr r0, [r0]
|
|
|
|
ldr r1, [r1]
|
2018-05-07 21:32:45 +00:00
|
|
|
b main
|
2018-05-06 23:02:23 +00:00
|
|
|
|
2018-05-07 21:32:45 +00:00
|
|
|
/* No need to include this in normal programs: */
|
2018-05-06 23:02:23 +00:00
|
|
|
.section .chainloader.text.start, "ax", %progbits
|
|
|
|
.arm
|
|
|
|
.align 5
|
|
|
|
.global relocate_and_chainload
|
|
|
|
.type relocate_and_chainload, %function
|
|
|
|
relocate_and_chainload:
|
2018-05-07 21:32:45 +00:00
|
|
|
ldr sp, =__stack_top__
|
2018-05-06 23:02:23 +00:00
|
|
|
b relocate_and_chainload_main
|