1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-25 11:46:05 +00:00
Atmosphere/fusee/fusee-secondary/src/start.s

69 lines
1.5 KiB
ArmAsm

.macro CLEAR_GPR_REG_ITER
mov r\@, #0
.endm
.section .text.start, "ax", %progbits
.arm
.align 5
.global _start
.type _start, %function
_start:
/* Insert NOPs for convenience (i.e. to use Nintendo's BCTs, for example) */
.rept 16
nop
.endr
/* Switch to supervisor mode, mask all interrupts, clear all flags */
msr cpsr_cxsf, #0xDF
/* Relocate ourselves if necessary */
ldr r2, =__start__
adr r3, _start
cmp r2, r3
bne _relocation_loop_end
ldr r4, =__bss_start__
sub r4, r4, r2 /* size >= 32, obviously */
_relocation_loop:
ldmia r3!, {r5-r12}
stmia r2!, {r5-r12}
subs r4, #0x20
bne _relocation_loop
ldr r12, =_relocation_loop_end
bx r12
_relocation_loop_end:
/* Set the stack pointer */
ldr sp, =0x40010000
mov fp, #0
stmfd sp!, {r0, r1}
/* Clear .bss */
ldr r0, =__bss_start__
mov r1, #0
ldr r2, =__bss_end__
sub r2, r2, r0
bl memset
/* Initialize the heap */
bl __init_heap
/* Call global constructors */
bl __libc_init_array
/* Set r0 to r12 to 0 (because why not?) & call main */
.rept 13
CLEAR_GPR_REG_ITER
.endr
ldmfd sp!, {r0, r1}
bl main
b .
.section .chainloader.text.start, "ax", %progbits
.arm
.align 5
.global relocate_and_chainload
.type relocate_and_chainload, %function
relocate_and_chainload:
ldr sp, =0x40010000
b relocate_and_chainload_main