lsw: JPN fix
[savezelda.git] / lsw / exploit2.s
1 # Copyright 2008-2009  Segher Boessenkool  <segher@kernel.crashing.org>
2 # Copyright      2011  roto <roto@mozy.org>
3 # Copyright      2011  Bernhard Urban <lewurm@gmail.com>
4 # This code is licensed to you under the terms of the GNU GPL, version 2;
5 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
6
7         bptr = 0x91178ea0
8         save = 0x91177f40
9         main = 0x90000020
10
11         audio_stop_usa = 0x8038ce9c
12         video_stop_usa = 0x8039971c
13
14         audio_stop_jpn = 0x803a0d4c
15         video_stop_jpn = 0x803ad748
16
17         audio_stop_eur = 0x8038cfec
18         video_stop_eur = 0x80399708
19
20         audio_stop_data = 0x9421fff0 # stwu 1,-16(1)
21         video_stop_data = 0x9421ffe0 # stwu 1,-32(1)
22
23         # Set up a stack frame.
24         lis 1,0x8080 ; li 0,0 ; stwu 0,-64(1)
25
26         # Stop audio.
27         lis 10,audio_stop_data@h ; ori 10,10,audio_stop_data@l
28         lis 3,audio_stop_usa@h ; ori 3,3,audio_stop_usa@l; lwz 5,0(3)
29         cmpw 5,10 ; beq execa
30         lis 3,audio_stop_jpn@h ; ori 3,3,audio_stop_jpn@l; lwz 5,0(3)
31         cmpw 5,10 ; beq execa
32         lis 3,audio_stop_eur@h ; ori 3,3,audio_stop_eur@l
33 execa:
34         mtctr 3 ; bctrl
35
36         # Stop video.
37         lis 10,video_stop_data@h ; ori 10,10,video_stop_data@l
38         lis 3,video_stop_usa@h ; ori 3,3,video_stop_usa@l; lwz 5,0(3)
39         cmpw 5,10 ; beq execv
40         lis 3,video_stop_jpn@h ; ori 3,3,video_stop_jpn@l; lwz 5,0(3)
41         cmpw 5,10 ; beq execv
42         lis 3,video_stop_eur@h ; ori 3,3,video_stop_eur@l
43 execv:
44         mtctr 3 ; bctrl
45
46         # Move code into place; a generous 32kB, starting at 64kB in
47         # the save file.
48         lis 3,main@h ; ori 3,3,main@l ; addi 5,3,-4
49         lis 4,save@h ; ori 4,4,save@l ; addi 4,4,-4
50
51         addis 4,4,1 ; addi 4,4,exploitlen # offset for exploit.bin
52
53         li 0,0x2000 ; mtctr 0
54 loop1:
55         lwzu 0,4(4) ; stwu 0,4(5) ; bdnz loop1
56
57         # Sync caches on it.
58         li 0,0x0400 ; mtctr 0 ; mr 5,3
59 loop2:
60         dcbst 0,5 ; sync ; icbi 0,5 ; addi 5,5,0x20 ; bdnz loop2
61         sync ; isync
62
63         # Go for it!
64         mtctr 3 ; bctr