mirror of
https://github.com/pmret/papermario.git
synced 2024-11-18 08:52:40 +01:00
Linker section labels (#306)
* properly use section start/end labels for overlay structs * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "cc58f64954" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "cc58f64954" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596"
This commit is contained in:
parent
7cb1790789
commit
6db3503055
@ -1,5 +1,8 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
// TODO this is the bss for the whole segment - break it up
|
||||||
|
static char bss[0xA0];
|
||||||
|
|
||||||
INCLUDE_ASM(s32, "163400", mainmenu_draw_rect);
|
INCLUDE_ASM(s32, "163400", mainmenu_draw_rect);
|
||||||
|
|
||||||
INCLUDE_ASM(s32, "163400", filemenu_set_selected);
|
INCLUDE_ASM(s32, "163400", filemenu_set_selected);
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
// TODO this is the bss for the whole segment - break it up
|
||||||
|
static char bss[0x8580];
|
||||||
|
|
||||||
// Need data segment and vars declared above
|
// Need data segment and vars declared above
|
||||||
#ifdef NON_MATCHING
|
#ifdef NON_MATCHING
|
||||||
void pause_set_cursor_opacity(s32 val) {
|
void pause_set_cursor_opacity(s32 val) {
|
||||||
|
@ -12,10 +12,10 @@ NUPiOverlaySegment D_8007798C = {
|
|||||||
.romStart = _163400_ROM_START,
|
.romStart = _163400_ROM_START,
|
||||||
.romEnd = _163400_ROM_END,
|
.romEnd = _163400_ROM_END,
|
||||||
.ramStart = _163400_VRAM,
|
.ramStart = _163400_VRAM,
|
||||||
.textStart = _163400_VRAM,
|
.textStart = _163400_TEXT_START,
|
||||||
.textEnd = _16A3E0_data__s,
|
.textEnd = _163400_TEXT_END,
|
||||||
.dataStart = _16A3E0_data__s,
|
.dataStart = _163400_DATA_START,
|
||||||
.dataEnd = _163400_BSS_START,
|
.dataEnd = _163400_DATA_END,
|
||||||
.bssStart = _163400_BSS_START,
|
.bssStart = _163400_BSS_START,
|
||||||
.bssEnd = _163400_BSS_END,
|
.bssEnd = _163400_BSS_END,
|
||||||
};
|
};
|
||||||
|
@ -5,19 +5,16 @@
|
|||||||
|
|
||||||
s32 D_80077950[] = { 0x8038F800, 0x803B5000, &D_803DA800 };
|
s32 D_80077950[] = { 0x8038F800, 0x803B5000, &D_803DA800 };
|
||||||
|
|
||||||
// TODO the gPauseMenuIconScripts should be DATA_START
|
|
||||||
// TODO the gPauseMenuHeldButtons should be BSS_START
|
|
||||||
// TODO 80278640 is BSS_END
|
|
||||||
NUPiOverlaySegment D_8007795C = {
|
NUPiOverlaySegment D_8007795C = {
|
||||||
.romStart = pause_ROM_START,
|
.romStart = pause_ROM_START,
|
||||||
.romEnd = pause_ROM_END,
|
.romEnd = pause_ROM_END,
|
||||||
.ramStart = pause_VRAM,
|
.ramStart = pause_VRAM,
|
||||||
.textStart = pause_VRAM,
|
.textStart = pause_TEXT_START,
|
||||||
.textEnd = gPauseMenuIconScripts,
|
.textEnd = pause_TEXT_END,
|
||||||
.dataStart = gPauseMenuIconScripts,
|
.dataStart = pause_DATA_START,
|
||||||
.dataEnd = &gPauseMenuHeldButtons,
|
.dataEnd = pause_DATA_END,
|
||||||
.bssStart = &gPauseMenuHeldButtons,
|
.bssStart = pause_BSS_START,
|
||||||
.bssEnd = 0x80278640
|
.bssEnd = pause_BSS_END,
|
||||||
};
|
};
|
||||||
|
|
||||||
void state_init_pause(void) {
|
void state_init_pause(void) {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
[subrepo]
|
[subrepo]
|
||||||
remote = https://github.com/ethteck/splat.git
|
remote = https://github.com/ethteck/splat.git
|
||||||
branch = master
|
branch = master
|
||||||
commit = fe30b60b75cd2660c45915e781599ccce9103246
|
commit = cc58f64954e8b7b2369b03db1152b161e6ccb78b
|
||||||
parent = 28af7909768f4379f103ef590b33196353da84e1
|
parent = c4e441d9ab91a2f63d7563c034772150934b48a1
|
||||||
method = merge
|
method = merge
|
||||||
cmdver = 0.4.3
|
cmdver = 0.4.3
|
||||||
|
@ -31,6 +31,12 @@ def to_cname(symbol: str) -> str:
|
|||||||
|
|
||||||
return symbol
|
return symbol
|
||||||
|
|
||||||
|
def get_segment_cname(segment: Segment) -> str:
|
||||||
|
if segment.parent:
|
||||||
|
return to_cname(segment.parent.name + "_" + segment.name)
|
||||||
|
else:
|
||||||
|
return to_cname(segment.name)
|
||||||
|
|
||||||
class LinkerEntry:
|
class LinkerEntry:
|
||||||
def __init__(self, segment: Segment, src_paths: List[Path], object_path: Path, section: str):
|
def __init__(self, segment: Segment, src_paths: List[Path], object_path: Path, section: str):
|
||||||
self.segment = segment
|
self.segment = segment
|
||||||
@ -60,29 +66,70 @@ class LinkerWriter():
|
|||||||
|
|
||||||
self._begin_segment(segment)
|
self._begin_segment(segment)
|
||||||
|
|
||||||
|
seg_name = get_segment_cname(segment)
|
||||||
|
|
||||||
|
self._write_symbol(f"{seg_name}_TEXT_START", ".")
|
||||||
|
|
||||||
do_next = False
|
do_next = False
|
||||||
|
text_ended = False
|
||||||
|
data_started = False
|
||||||
|
data_ended = False
|
||||||
|
bss_started = False
|
||||||
|
cur_section = None
|
||||||
|
|
||||||
for i, entry in enumerate(entries):
|
for i, entry in enumerate(entries):
|
||||||
if entry.section == "linker": # TODO: isinstance is preferable
|
cur_section = entry.section
|
||||||
|
|
||||||
|
if cur_section == "linker": # TODO: isinstance is preferable
|
||||||
self._end_block()
|
self._end_block()
|
||||||
self._begin_segment(entry.segment)
|
self._begin_segment(entry.segment)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# text/data/bss START/END labels
|
||||||
|
if not data_started and ("data" in cur_section or "rodata" in cur_section):
|
||||||
|
if not text_ended:
|
||||||
|
text_ended = True
|
||||||
|
self._write_symbol(f"{seg_name}_TEXT_END", ".")
|
||||||
|
|
||||||
|
data_started = True
|
||||||
|
self._write_symbol(f"{seg_name}_DATA_START", ".")
|
||||||
|
elif data_started and not data_ended and "data" not in cur_section and "rodata" not in cur_section:
|
||||||
|
data_ended = True
|
||||||
|
self._write_symbol(f"{seg_name}_DATA_END", ".")
|
||||||
|
|
||||||
|
if not bss_started and i < (len(entries) - 1) and "bss" in entries[i + 1].section:
|
||||||
|
bss_started = True
|
||||||
|
self._write_symbol(f"{seg_name}_BSS_START", ".")
|
||||||
|
elif not bss_started and "bss" in cur_section:
|
||||||
|
bss_started = True
|
||||||
|
self._write_symbol(f"{seg_name}_BSS_START", ".")
|
||||||
|
|
||||||
start = entry.segment.rom_start
|
start = entry.segment.rom_start
|
||||||
if isinstance(start, int):
|
if isinstance(start, int):
|
||||||
# Create new sections for non-0x10 alignment (hack)
|
# Create new sections for non-0x10 alignment (hack)
|
||||||
if start % 0x10 != 0 and i != 0 or do_next:
|
if start % 0x10 != 0 and i != 0 or do_next:
|
||||||
self._end_block()
|
self._end_block()
|
||||||
self._begin_segment(entry.segment, for_subalign=True)
|
self._begin_segment(entry.segment, mid_segment=True)
|
||||||
do_next = False
|
do_next = False
|
||||||
|
|
||||||
if start % 0x10 != 0 and i != 0:
|
if start % 0x10 != 0 and i != 0:
|
||||||
do_next = True
|
do_next = True
|
||||||
|
|
||||||
if entry.object_path and entry.section == ".data":
|
if entry.object_path and cur_section == ".data":
|
||||||
path_cname = re.sub(r"[^0-9a-zA-Z_]", "_", str(entry.segment.dir / entry.segment.name) + ".".join(entry.object_path.suffixes[:-1]))
|
path_cname = re.sub(r"[^0-9a-zA-Z_]", "_", str(entry.segment.dir / entry.segment.name) + ".".join(entry.object_path.suffixes[:-1]))
|
||||||
self._write_symbol(path_cname, ".")
|
self._write_symbol(path_cname, ".")
|
||||||
|
|
||||||
self._writeln(f"{entry.object_path}({entry.section});")
|
self._writeln(f"{entry.object_path}({cur_section});")
|
||||||
|
|
||||||
|
if not text_ended:
|
||||||
|
self._write_symbol(f"{seg_name}_TEXT_END", ".")
|
||||||
|
if not data_started:
|
||||||
|
self._write_symbol(f"{seg_name}_DATA_START", ".")
|
||||||
|
if not data_ended:
|
||||||
|
self._write_symbol(f"{seg_name}_DATA_END", ".")
|
||||||
|
if not bss_started:
|
||||||
|
self._write_symbol(f"{seg_name}_BSS_START", ".")
|
||||||
|
self._write_symbol(f"{seg_name}_BSS_END", ".")
|
||||||
|
|
||||||
self._end_segment(segment)
|
self._end_segment(segment)
|
||||||
|
|
||||||
@ -136,7 +183,7 @@ class LinkerWriter():
|
|||||||
self._writeln(f"{symbol} = {value};")
|
self._writeln(f"{symbol} = {value};")
|
||||||
self.symbols.append(symbol)
|
self.symbols.append(symbol)
|
||||||
|
|
||||||
def _begin_segment(self, segment: Segment, for_subalign=False):
|
def _begin_segment(self, segment: Segment, mid_segment=False):
|
||||||
# force location if not shiftable/auto
|
# force location if not shiftable/auto
|
||||||
if not self.shiftable and isinstance(segment.rom_start, int):
|
if not self.shiftable and isinstance(segment.rom_start, int):
|
||||||
self._writeln(f"__romPos = 0x{segment.rom_start:X};")
|
self._writeln(f"__romPos = 0x{segment.rom_start:X};")
|
||||||
@ -149,12 +196,9 @@ class LinkerWriter():
|
|||||||
vram = segment.vram_start
|
vram = segment.vram_start
|
||||||
vram_str = f"0x{vram:X} " if isinstance(vram, int) else ""
|
vram_str = f"0x{vram:X} " if isinstance(vram, int) else ""
|
||||||
|
|
||||||
if segment.parent:
|
name = get_segment_cname(segment)
|
||||||
name = to_cname(segment.parent.name + "_" + segment.name)
|
|
||||||
else:
|
|
||||||
name = to_cname(segment.name)
|
|
||||||
|
|
||||||
if for_subalign:
|
if mid_segment:
|
||||||
name += to_cname(segment.type)
|
name += to_cname(segment.type)
|
||||||
|
|
||||||
self._write_symbol(f"{name}_ROM_START", "__romPos")
|
self._write_symbol(f"{name}_ROM_START", "__romPos")
|
||||||
@ -166,17 +210,14 @@ class LinkerWriter():
|
|||||||
def _end_segment(self, segment: Segment):
|
def _end_segment(self, segment: Segment):
|
||||||
self._end_block()
|
self._end_block()
|
||||||
|
|
||||||
if segment.parent:
|
name = get_segment_cname(segment)
|
||||||
name = to_cname(segment.parent.name + "_" + segment.name)
|
|
||||||
else:
|
|
||||||
name = to_cname(segment.name)
|
|
||||||
|
|
||||||
# force end if not shiftable/auto
|
# force end if not shiftable/auto
|
||||||
if not self.shiftable and isinstance(segment.rom_start, int) and isinstance(segment.rom_end, int):
|
if not self.shiftable and isinstance(segment.rom_start, int) and isinstance(segment.rom_end, int):
|
||||||
self._write_symbol(f"{to_cname(name)}_ROM_END", segment.rom_end)
|
self._write_symbol(f"{name}_ROM_END", segment.rom_end)
|
||||||
self._writeln(f"__romPos = 0x{segment.rom_end:X};")
|
self._writeln(f"__romPos = 0x{segment.rom_end:X};")
|
||||||
else:
|
else:
|
||||||
self._writeln(f"__romPos += SIZEOF(.{name});")
|
self._writeln(f"__romPos += SIZEOF(.{name});")
|
||||||
self._write_symbol(f"{to_cname(name)}_ROM_END", "__romPos")
|
self._write_symbol(f"{name}_ROM_END", "__romPos")
|
||||||
|
|
||||||
self._writeln("")
|
self._writeln("")
|
||||||
|
Loading…
Reference in New Issue
Block a user