forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 2
/
3dsx_custom_crt0.s
75 lines (66 loc) · 2.28 KB
/
3dsx_custom_crt0.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@---------------------------------------------------------------------------------
@ 3DS processor selection
@---------------------------------------------------------------------------------
.cpu mpcore
@---------------------------------------------------------------------------------
@---------------------------------------------------------------------------------
.section ".crt0"
.global _start, __service_ptr, __apt_appid, __heap_size_hbl, __linear_heap_size_hbl, __system_arglist, __system_runflags
@---------------------------------------------------------------------------------
.align 2
.arm
@---------------------------------------------------------------------------------
_start:
@---------------------------------------------------------------------------------
b startup
.ascii "_prm"
__service_ptr:
.word 0 @ Pointer to service handle override list -- if non-NULL it is assumed that we have been launched from a homebrew launcher
__apt_appid:
.word 0x300 @ Program APPID
__heap_size_hbl:
.word 24*1024*1024 @ Default heap size (24 MiB)
__linear_heap_size_hbl:
.word 32*1024*1024 @ Default linear heap size (32 MiB)
__system_arglist:
.word 0 @ Pointer to argument list (argc (u32) followed by that many NULL terminated strings)
__system_runflags:
.word 0 @ Flags to signal runtime restrictions to ctrulib
startup:
@ Save return address
mov r4, lr
bics sp, sp, #7
@ Clear the BSS section
ldr r0, =__bss_start__
ldr r1, =__bss_end__
sub r1, r1, r0
bl ClearMem
@ System initialization
mov r0, r4
bl initSystem
@ Set up argc/argv arguments for main()
ldr r0, =__system_argc
ldr r1, =__system_argv
ldr r0, [r0]
ldr r1, [r1]
@ Jump to user code
ldr r3, =main
ldr lr, =__ctru_exit
bx r3
@---------------------------------------------------------------------------------
@ Clear memory to 0x00 if length != 0
@ r0 = Start Address
@ r1 = Length
@---------------------------------------------------------------------------------
ClearMem:
@---------------------------------------------------------------------------------
mov r2, #3 @ Round down to nearest word boundary
add r1, r1, r2 @ Shouldn't be needed
bics r1, r1, r2 @ Clear 2 LSB (and set Z)
bxeq lr @ Quit if copy size is 0
mov r2, #0
ClrLoop:
stmia r0!, {r2}
subs r1, r1, #4
bne ClrLoop
bx lr