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

70 lines
1.5 KiB
ArmAsm
Raw Normal View History

2018-03-14 20:14:02 +00:00
.macro CLEAR_GPR_REG_ITER
mov r\@, #0
.endm
.section .text.start, "ax", %progbits
2018-03-14 20:14:02 +00:00
.arm
.align 5
.global _start
.type _start, %function
2018-03-14 20:14:02 +00:00
_start:
2018-03-15 22:12:38 +00:00
/* Insert NOPs for convenience (i.e. to use Nintendo's BCTs, for example) */
.rept 16
nop
.endr
2018-03-14 20:14:02 +00:00
/* 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
2018-03-14 20:14:02 +00:00
bne _relocation_loop_end
ldr r4, =__bss_start__
sub r4, r4, r2 /* size >= 32, obviously */
2018-03-14 20:14:02 +00:00
_relocation_loop:
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-04 22:56:01 +01:00
ldr sp, =0x40010000
2018-03-14 20:14:02 +00:00
mov fp, #0
stmfd sp!, {r0, r1}
2018-03-14 20:14:02 +00:00
/* Clear .bss */
ldr r0, =__bss_start__
mov r1, #0
ldr r2, =__bss_end__
sub r2, r2, r0
bl memset
2018-05-04 22:56:01 +01:00
/* Initialize the heap */
bl __init_heap
2018-03-14 20:14:02 +00:00
/* 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}
2018-03-14 20:14:02 +00:00
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