nds_test2

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