forked from Mr-Wiseguy/Paper-Mario-Precomp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpapermario.ld
121 lines (104 loc) · 3.75 KB
/
papermario.ld
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
OUTPUT_ARCH (mips)
#define BEGIN_SEG(name, addr) \
_##name##SegmentStart = ADDR(.name); \
_##name##SegmentRomStart = __romPos; \
.name addr : AT(__romPos)
#define END_SEG(name) \
_##name##SegmentEnd = ADDR(.name) + SIZEOF(.name); \
_##name##SegmentRomEnd = __romPos + SIZEOF(.name); \
_##name##SegmentSize = _##name##SegmentEnd - _##name##SegmentStart; \
__romPos += SIZEOF(.name);
#define BEGIN_NOLOAD(name) \
_##name##SegmentNoloadStart = ADDR(.name.noload); \
.name.noload (NOLOAD) :
#define END_NOLOAD(name) \
_##name##SegmentNoloadEnd = ADDR(.name.noload) + SIZEOF(.name.noload);
#define PATCH(segment, symbol, offset) \
.segment##symbol##offset##_patch symbol + offset : AT(_##segment##SegmentRomStart + symbol - _##segment##SegmentStart + offset)
#define CODE_PATCH(segment, symbol, offset) \
.segment##symbol##offset##_patch symbol + offset : AT(segment##_ROM_START + symbol - segment##_VRAM + offset)
#define JAL_HOOK(segment, symbol, offset, helper, name) \
.segment##symbol##offset##_patch symbol + offset : AT(segment##_ROM_START + symbol - segment##_VRAM + offset) \
{ \
name = .; \
BYTE(0x0C); \
BYTE((helper >> 18) & 0xFF); \
BYTE((helper >> 10) & 0xFF); \
BYTE((helper >> 2) & 0xFF); \
}
#define J_HOOK_NOP(segment, symbol, offset, helper, name) \
.segment##symbol##offset##_patch symbol + offset : AT(segment##_ROM_START + symbol - segment##_VRAM + offset) \
{ \
name = .; \
BYTE(0x08); \
BYTE((helper >> 18) & 0xFF); \
BYTE((helper >> 10) & 0xFF); \
BYTE((helper >> 2) & 0xFF); \
BYTE(0x00); \
BYTE(0x00); \
BYTE(0x00); \
BYTE(0x00); \
}
#define ROM_PATCH(address) \
.rom##address##_patch : AT(address)
SECTIONS
{
__romPos = 0;
BEGIN_SEG(baserom, 0)
{
BASEROM;
}
END_SEG(baserom)
baseromEnd = __romPos;
extRamStart = 0xFFFFFFFF80400000;
. = extRamStart;
BEGIN_SEG(custom, .)
{
BUILD_DIR/src/custom/init.o(.text);
BUILD_DIR/src/custom/drawing.o(.text);
BUILD_DIR/src/custom/usb.o(.text);
BUILD_DIR/src/custom/debug.o(.text);
BUILD_DIR/src/custom/patch.o(.text);
BUILD_DIR/src/custom/callback.o(.text);
BUILD_DIR/load_mods.o(.text);
MODS_TEXT
BUILD_DIR/src/custom/init.o(.*data*);
BUILD_DIR/src/custom/drawing.o(.*data*);
BUILD_DIR/src/custom/usb.o(.*data*);
BUILD_DIR/src/custom/debug.o(.*data*);
BUILD_DIR/src/custom/patch.o(.*data*);
BUILD_DIR/src/custom/callback.o(.*data*);
MODS_DATA
}
END_SEG(custom)
BEGIN_NOLOAD(custom)
{
BUILD_DIR/src/custom/init.o(.bss);
BUILD_DIR/src/custom/drawing.o(.bss);
BUILD_DIR/src/custom/usb.o(.bss);
BUILD_DIR/src/custom/debug.o(.bss);
BUILD_DIR/src/custom/callback.o(.bss);
MODS_BSS
}
END_NOLOAD(custom)
/* Overwrite the IS64 initialization with a dma of custom code into ext ram */
CODE_PATCH(_1000, is_debug_init, 0x0)
{
BUILD_DIR/src/patches/dma_code.o(.text);
}
/* Overwrite the IS64 print functions with jumps to debug_printf */
J_HOOK_NOP(_1000, printf, 0x0, debug_printf, func_80025CC0_print_hook)
/* Overwrite the IS64 print functions with jumps to debug_printf */
J_HOOK_NOP(_1000, osSyncPrintf, 0x0, debug_printf, func_80025CFC_print_hook)
/* Overwrite the IS64 print functions with jumps to debug_printf */
J_HOOK_NOP(_1000, rmonPrintf, 0x0, debug_printf, func_80025D38_print_hook)
ROM_PATCH(0x000000)
{
BUILD_DIR/src/patches/header.o(.data);
}
/* Discard everything not specifically mentioned above. */
/DISCARD/ :
{
*(*);
}
}