summaryrefslogtreecommitdiff
path: root/rtl/nds/cprt07.as
diff options
context:
space:
mode:
authorLegolas <Legolas@3ad0048d-3df7-0310-abae-a5850022a9f2>2019-06-10 06:39:46 +0000
committerLegolas <Legolas@3ad0048d-3df7-0310-abae-a5850022a9f2>2019-06-10 06:39:46 +0000
commit3295947f02c70496670318c72853957ba482466d (patch)
treed832100fd19a9b679e3b7faa648d1449ccac7bc2 /rtl/nds/cprt07.as
parent524afa41e0b81e17012cc1a521b5a26d1183e57f (diff)
downloadfpc-3295947f02c70496670318c72853957ba482466d.tar.gz
* Nintendo DS port updated to libnds ver.1.7.3
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@42202 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'rtl/nds/cprt07.as')
-rw-r--r--rtl/nds/cprt07.as97
1 files changed, 93 insertions, 4 deletions
diff --git a/rtl/nds/cprt07.as b/rtl/nds/cprt07.as
index 8d495d1f25..46894f93f3 100644
--- a/rtl/nds/cprt07.as
+++ b/rtl/nds/cprt07.as
@@ -1,5 +1,11 @@
+/*--------------------------------------------------------------------------------
+ This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/.
+--------------------------------------------------------------------------------*/
+
@---------------------------------------------------------------------------------
- .section ".init"
+ .section ".crt0","ax"
.global _start
@---------------------------------------------------------------------------------
.align 4
@@ -23,11 +29,53 @@ _start:
msr cpsr, r0
ldr sp, =__sp_usr @ Set user stack
+#ifndef VRAM
+ adr r1, __sync_start @ Perform ARM7<->ARM9 sync code
+ ldr r2, =__arm7_start__
+ mov r3, #(__sync_end-__sync_start)
+ mov r8, r2
+ bl CopyMem
+ mov r3, r8
+ bl _blx_r3_stub
+
+@---------------------------------------------------------------------------------
+@ Copy arm7 binary from LMA to VMA (EWRAM to IWRAM)
+@---------------------------------------------------------------------------------
+ adr r0, arm7lma @ Calculate ARM7 LMA
+ ldr r1, [r0]
+ add r1, r1, r0
+ ldr r2, =__arm7_start__
+ ldr r4, =__arm7_end__
+ bl CopyMemCheck
+
+#else
+ bl __sync_start
+#endif
+
ldr r0, =__bss_start__ @ Clear BSS section to 0x00
ldr r1, =__bss_end__
sub r1, r1, r0
bl ClearMem
+ cmp r10, #1
+ bne NotTWL
+ ldr r1, =__dsimode @ set DSi mode flag
+ strb r10, [r1]
+
+#ifndef VRAM
+ ldr r1, =0x02ffe1d8 @ Get ARM7i LMA from header
+ ldr r1, [r1]
+ ldr r2, =__arm7i_start__
+ ldr r4, =__arm7i_end__
+ bl CopyMemCheck
+
+ ldr r0, =__twl_bss_start__ @ Clear TWL BSS section to 0x00
+ ldr r1, =__twl_bss_end__
+ sub r1, r1, r0
+ bl ClearMem
+#endif
+
+NotTWL:
ldr r3, =__libc_init_array @ global constructors
bl _blx_r3_stub
@@ -35,13 +83,51 @@ _start:
mov r1, #0 @ char *argv[]
ldr r3, =main
ldr lr,=__libnds_exit
+ mov r12, #0x4000000 @ tell arm9 we are ready
+ mov r9, #0
+ str r9, [r12, #0x180]
+_blx_r3_stub:
bx r3
+#ifndef VRAM
+arm7lma:
+ .word __arm7_lma__ - .
+#endif
+ .pool
+
@---------------------------------------------------------------------------------
- _blx_r3_stub:
+@ ARM7<->ARM9 synchronization code
@---------------------------------------------------------------------------------
- bx r3
-
+
+__sync_start:
+ push {lr}
+ mov r12, #0x4000000
+ mov r9, #0x0
+ bl IPCSync
+ mov r9, #(0x9<<8)
+ str r9, [r12, #0x180]
+ mov r9, #0xA
+ bl IPCSync
+ mov r9, #(0xB<<8)
+ str r9, [r12, #0x180]
+ mov r9, #0xC
+ bl IPCSync
+ mov r9, #(0xD<<8)
+ str r9, [r12, #0x180]
+IPCRecvFlag:
+ ldr r10, [r12, #0x180]
+ and r10, r10, #0xF
+ cmp r10, #0xC
+ beq IPCRecvFlag
+ pop {pc}
+IPCSync:
+ ldr r10, [r12, #0x180]
+ and r10, r10, #0xF
+ cmp r10, r9
+ bne IPCSync
+ bx lr
+__sync_end:
+
@---------------------------------------------------------------------------------
@ Clear memory to 0x00 if length != 0
@ r0 = Start Address
@@ -69,6 +155,9 @@ ClrLoop:
@---------------------------------------------------------------------------------
CopyMemCheck:
@---------------------------------------------------------------------------------
+ cmp r1, r2
+ bxeq lr
+
sub r3, r4, r2 @ Is there any data to copy?
@---------------------------------------------------------------------------------
@ Copy memory