mirror of
https://github.com/rvtr/GodMode9i.git
synced 2025-06-18 10:55:31 -04:00
145 lines
4.4 KiB
ArmAsm
145 lines
4.4 KiB
ArmAsm
/*-----------------------------------------------------------------
|
|
|
|
Copyright (C) 2005 Michael "Chishm" Chisholm
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License
|
|
as published by the Free Software Foundation; either version 2
|
|
of the License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
If you use this code, please give due credit and email me about your
|
|
project at chishm@hotmail.com
|
|
------------------------------------------------------------------*/
|
|
|
|
@---------------------------------------------------------------------------------
|
|
.section ".init"
|
|
.global _start
|
|
.global storedFileCluster
|
|
.global initDisc
|
|
.global wantToPatchDLDI
|
|
.global argStart
|
|
.global argSize
|
|
.global dsiSD
|
|
@---------------------------------------------------------------------------------
|
|
.align 4
|
|
.arm
|
|
@---------------------------------------------------------------------------------
|
|
_start:
|
|
@---------------------------------------------------------------------------------
|
|
b startUp
|
|
|
|
storedFileCluster:
|
|
.word 0x0FFFFFFF @ default BOOT.NDS
|
|
initDisc:
|
|
.word 0x00000001 @ init the disc by default
|
|
wantToPatchDLDI:
|
|
.word 0x00000001 @ by default patch the DLDI section of the loaded NDS
|
|
@ Used for passing arguments to the loaded app
|
|
argStart:
|
|
.word _end - _start
|
|
argSize:
|
|
.word 0x00000000
|
|
dldiOffset:
|
|
.word _dldi_start - _start
|
|
dsiSD:
|
|
.word 0
|
|
|
|
startUp:
|
|
mov r0, #0x04000000
|
|
mov r1, #0
|
|
str r1, [r0,#0x208] @ REG_IME
|
|
str r1, [r0,#0x210] @ REG_IE
|
|
str r1, [r0,#0x218] @ REG_AUXIE
|
|
|
|
mov r0, #0x12 @ Switch to IRQ Mode
|
|
msr cpsr, r0
|
|
ldr sp, =__sp_irq @ Set IRQ stack
|
|
|
|
mov r0, #0x13 @ Switch to SVC Mode
|
|
msr cpsr, r0
|
|
ldr sp, =__sp_svc @ Set SVC stack
|
|
|
|
mov r0, #0x1F @ Switch to System Mode
|
|
msr cpsr, r0
|
|
ldr sp, =__sp_usr @ Set user stack
|
|
|
|
ldr r0, =__bss_start @ Clear BSS section to 0x00
|
|
ldr r1, =__bss_end
|
|
sub r1, r1, r0
|
|
bl ClearMem
|
|
|
|
mov r0, #0 @ int argc
|
|
mov r1, #0 @ char *argv[]
|
|
ldr r3, =main
|
|
bl _blx_r3_stub @ jump to user code
|
|
|
|
@ If the user ever returns, restart
|
|
b _start
|
|
|
|
@---------------------------------------------------------------------------------
|
|
_blx_r3_stub:
|
|
@---------------------------------------------------------------------------------
|
|
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
|
|
|
|
@---------------------------------------------------------------------------------
|
|
@ Copy memory if length != 0
|
|
@ r1 = Source Address
|
|
@ r2 = Dest Address
|
|
@ r4 = Dest Address + Length
|
|
@---------------------------------------------------------------------------------
|
|
CopyMemCheck:
|
|
@---------------------------------------------------------------------------------
|
|
sub r3, r4, r2 @ Is there any data to copy?
|
|
@---------------------------------------------------------------------------------
|
|
@ Copy memory
|
|
@ r1 = Source Address
|
|
@ r2 = Dest Address
|
|
@ r3 = Length
|
|
@---------------------------------------------------------------------------------
|
|
CopyMem:
|
|
@---------------------------------------------------------------------------------
|
|
mov r0, #3 @ These commands are used in cases where
|
|
add r3, r3, r0 @ the length is not a multiple of 4,
|
|
bics r3, r3, r0 @ even though it should be.
|
|
bxeq lr @ Length is zero, so exit
|
|
CIDLoop:
|
|
ldmia r1!, {r0}
|
|
stmia r2!, {r0}
|
|
subs r3, r3, #4
|
|
bne CIDLoop
|
|
bx lr
|
|
|
|
@---------------------------------------------------------------------------------
|
|
.align
|
|
.pool
|
|
.end
|
|
@---------------------------------------------------------------------------------
|