nds_test2

view src/startup/arm7entry.s @ 0:abcaf667f2bd

initial commit (3d + 2d)
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 28 Jan 2018 20:05:26 +0200
parents
children
line source
1 @ vi:set filetype=armasm:
2 .section ".crt0","ax"
3 .global _start
4 .align 4
5 .arm
6 _start:
7 mov r0, #0x04000000 @ IME = 0;
8 mov r1, #0
9 str r1, [r0, #0x208]
11 mov r0, #0x12 @ Switch to IRQ Mode
12 msr cpsr, r0
13 ldr sp, =__sp_irq @ Set IRQ stack
15 mov r0, #0x13 @ Switch to SVC Mode
16 msr cpsr, r0
17 ldr sp, =__sp_svc @ Set SVC stack
19 mov r0, #0x1F @ Switch to System Mode
20 msr cpsr, r0
21 ldr sp, =__sp_usr @ Set user stack
23 #ifndef VRAM
24 adr r1, __sync_start @ Perform ARM7<->ARM9 sync code
25 ldr r2, =__arm7_start__
26 mov r3, #(__sync_end-__sync_start)
27 mov r8, r2
28 bl CopyMem
29 mov r3, r8
30 bl _blx_r3_stub
32 @ Copy arm7 binary from LMA to VMA (EWRAM to IWRAM)
33 adr r0, arm7lma @ Calculate ARM7 LMA
34 ldr r1, [r0]
35 add r1, r1, r0
36 ldr r2, =__arm7_start__
37 ldr r4, =__arm7_end__
38 bl CopyMemCheck
40 #else
41 bl __sync_start
42 #endif
44 ldr r0, =__bss_start__ @ Clear BSS section to 0x00
45 ldr r1, =__bss_end__
46 sub r1, r1, r0
47 bl ClearMem
49 #ifndef VRAM
50 cmp r10, #1
51 bne NotTWL
52 ldr r1, =__dsimode @ set DSi mode flag
53 strb r10, [r1]
55 ldr r1, =0x02ffe1d8 @ Get ARM7i LMA from header
56 ldr r1, [r1]
57 ldr r2, =__arm7i_start__
58 ldr r4, =__arm7i_end__
59 bl CopyMemCheck
61 ldr r0, =__twl_bss_start__ @ Clear TWL BSS section to 0x00
62 ldr r1, =__twl_bss_end__
63 sub r1, r1, r0
64 bl ClearMem
65 #endif
67 NotTWL:
68 mov r0, #0 @ int argc
69 mov r1, #0 @ char *argv[]
70 ldr r3, =main
71 mov r12, #0x4000000 @ tell arm9 we are ready
72 mov r9, #0
73 str r9, [r12, #0x180]
74 _blx_r3_stub:
75 bx r3
76 infloop:
77 b infloop
79 #ifndef VRAM
80 arm7lma:
81 .word __arm7_lma__ - .
82 #endif
83 .pool
85 @---------------------------------------------------------------------------------
86 @ ARM7<->ARM9 synchronization code
87 @---------------------------------------------------------------------------------
89 __sync_start:
90 push {lr}
91 mov r12, #0x4000000
92 mov r9, #0x0
93 bl IPCSync
94 mov r9, #(0x9<<8)
95 str r9, [r12, #0x180]
96 mov r9, #0xA
97 bl IPCSync
98 mov r9, #(0xB<<8)
99 str r9, [r12, #0x180]
100 mov r9, #0xC
101 bl IPCSync
102 mov r9, #(0xD<<8)
103 str r9, [r12, #0x180]
104 IPCRecvFlag:
105 ldr r10, [r12, #0x180]
106 and r10, r10, #0xF
107 cmp r10, #0xC
108 beq IPCRecvFlag
109 pop {pc}
110 IPCSync:
111 ldr r10, [r12, #0x180]
112 and r10, r10, #0xF
113 cmp r10, r9
114 bne IPCSync
115 bx lr
116 __sync_end:
118 @---------------------------------------------------------------------------------
119 @ Clear memory to 0x00 if length != 0
120 @ r0 = Start Address
121 @ r1 = Length
122 @---------------------------------------------------------------------------------
123 ClearMem:
124 @---------------------------------------------------------------------------------
125 mov r2, #3 @ Round down to nearest word boundary
126 add r1, r1, r2 @ Shouldn't be needed
127 bics r1, r1, r2 @ Clear 2 LSB (and set Z)
128 bxeq lr @ Quit if copy size is 0
130 mov r2, #0
131 ClrLoop:
132 stmia r0!, {r2}
133 subs r1, r1, #4
134 bne ClrLoop
135 bx lr
137 @---------------------------------------------------------------------------------
138 @ Copy memory if length != 0
139 @ r1 = Source Address
140 @ r2 = Dest Address
141 @ r4 = Dest Address + Length
142 @---------------------------------------------------------------------------------
143 CopyMemCheck:
144 @---------------------------------------------------------------------------------
145 cmp r1, r2
146 bxeq lr
148 sub r3, r4, r2 @ Is there any data to copy?
149 @---------------------------------------------------------------------------------
150 @ Copy memory
151 @ r1 = Source Address
152 @ r2 = Dest Address
153 @ r3 = Length
154 @---------------------------------------------------------------------------------
155 CopyMem:
156 @---------------------------------------------------------------------------------
157 mov r0, #3 @ These commands are used in cases where
158 add r3, r3, r0 @ the length is not a multiple of 4,
159 bics r3, r3, r0 @ even though it should be.
160 bxeq lr @ Length is zero, so exit
161 CIDLoop:
162 ldmia r1!, {r0}
163 stmia r2!, {r0}
164 subs r3, r3, #4
165 bne CIDLoop
166 bx lr
168 @---------------------------------------------------------------------------------
169 .align
170 .pool
172 .global __dsimode
173 __dsimode: .word
174 .end
175 @---------------------------------------------------------------------------------