1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#
# To use this installer properly, the program text must be compiled to
# load at a higher address such as 0x80012000.
#
# Then call the function early in your program:
#
# void install_monitor(void);
#
# ...
#
# int main(int argc, const char *argv[])
# {
# ResetGraph(0);
#
# EnterCriticalSection();
# install_monitor();
# ExitCriticalSection();
# ...
#
.set noreorder
.section .text
.global _install_monitor
.type _install_monitor, @function
_install_monitor: # = Patch installer routine
addiu $sp, -4
sw $ra, 0($sp)
la $a0, debug_payload
la $a1, debug_payload_end
la $a2, debug_payload
subu $a1, $a2
jal .Lcopymem
lui $a2, 0xA001
lui $a0, 0x8001
jalr $a0
nop
lw $ra, 0($sp)
addiu $sp, 4
jr $ra
nop
.Lcopymem: # installer's copy routine
addiu $a1, -4
lw $v0, 0($a0)
addiu $a0, 4
sw $v0, 0($a2)
bgtz $a1, .Lcopymem
addiu $a2, 4
jr $ra
nop
.section .data
debug_payload:
.incbin "patch.bin"
debug_payload_end:
|