Rewrote crt0, init, and chainloading code
start.s, init.c, linker.ld and linker.specs are meant to be re-used by user applications, should they remove the defines from init.c and the .chainloader* sections from the linker script
This commit is contained in:
@@ -2,30 +2,27 @@
|
||||
mov r\@, #0
|
||||
.endm
|
||||
|
||||
.section .text.start
|
||||
.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 */
|
||||
/* Switch to system mode, mask all interrupts, clear all flags */
|
||||
msr cpsr_cxsf, #0xDF
|
||||
|
||||
/* Relocate ourselves if necessary */
|
||||
ldr r0, =__start__
|
||||
adr r1, _start
|
||||
cmp r0, r1
|
||||
ldr r2, =__start__
|
||||
adr r3, _start
|
||||
cmp r2, r3
|
||||
bne _relocation_loop_end
|
||||
|
||||
ldr r2, =__bss_start__
|
||||
sub r2, r2, r0 /* size >= 32, obviously */
|
||||
ldr r4, =__bss_start__
|
||||
sub r4, r4, r2 /* size >= 32, obviously, and we've declared 32-byte-alignment */
|
||||
_relocation_loop:
|
||||
ldmia r1!, {r3-r10}
|
||||
stmia r0!, {r3-r10}
|
||||
subs r2, #0x20
|
||||
ldmia r3!, {r5-r12}
|
||||
stmia r2!, {r5-r12}
|
||||
subs r4, #0x20
|
||||
bne _relocation_loop
|
||||
|
||||
ldr r12, =_relocation_loop_end
|
||||
@@ -33,22 +30,25 @@ _start:
|
||||
|
||||
_relocation_loop_end:
|
||||
/* Set the stack pointer */
|
||||
ldr sp, =0x40008000
|
||||
mov fp, #0
|
||||
ldr sp, =__stack_top__
|
||||
mov fp, #0
|
||||
bl __program_init
|
||||
|
||||
/* Clear .bss */
|
||||
ldr r0, =__bss_start__
|
||||
mov r1, #0
|
||||
ldr r2, =__bss_end__
|
||||
sub r2, r2, r0
|
||||
bl memset
|
||||
|
||||
/* Call global constructors */
|
||||
bl __libc_init_array
|
||||
|
||||
/* Set r0 to r12 to 0 (because why not?) & call main */
|
||||
/* Set r0 to r12 to 0 (for debugging) & call main */
|
||||
.rept 13
|
||||
CLEAR_GPR_REG_ITER
|
||||
.endr
|
||||
bl main
|
||||
b .
|
||||
ldr r0, =__program_argc
|
||||
ldr r1, =__program_argv
|
||||
ldr lr, =__program_exit
|
||||
b main
|
||||
|
||||
/* No need to include this in normal programs: */
|
||||
.section .chainloader.text.start, "ax", %progbits
|
||||
.arm
|
||||
.align 5
|
||||
.global relocate_and_chainload
|
||||
.type relocate_and_chainload, %function
|
||||
relocate_and_chainload:
|
||||
ldr sp, =__stack_top__
|
||||
b relocate_and_chainload_main
|
||||
|
||||
Reference in New Issue
Block a user