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:
Ethan Roseman 2021-07-12 07:07:34 -04:00 committed by GitHub
parent 7cb1790789
commit 6db3503055
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 75 additions and 31 deletions

View File

@ -1,5 +1,8 @@
#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", filemenu_set_selected);

View File

@ -1,5 +1,8 @@
#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
#ifdef NON_MATCHING
void pause_set_cursor_opacity(s32 val) {

View File

@ -12,10 +12,10 @@ NUPiOverlaySegment D_8007798C = {
.romStart = _163400_ROM_START,
.romEnd = _163400_ROM_END,
.ramStart = _163400_VRAM,
.textStart = _163400_VRAM,
.textEnd = _16A3E0_data__s,
.dataStart = _16A3E0_data__s,
.dataEnd = _163400_BSS_START,
.textStart = _163400_TEXT_START,
.textEnd = _163400_TEXT_END,
.dataStart = _163400_DATA_START,
.dataEnd = _163400_DATA_END,
.bssStart = _163400_BSS_START,
.bssEnd = _163400_BSS_END,
};

View File

@ -5,19 +5,16 @@
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 = {
.romStart = pause_ROM_START,
.romEnd = pause_ROM_END,
.ramStart = pause_VRAM,
.textStart = pause_VRAM,
.textEnd = gPauseMenuIconScripts,
.dataStart = gPauseMenuIconScripts,
.dataEnd = &gPauseMenuHeldButtons,
.bssStart = &gPauseMenuHeldButtons,
.bssEnd = 0x80278640
.textStart = pause_TEXT_START,
.textEnd = pause_TEXT_END,
.dataStart = pause_DATA_START,
.dataEnd = pause_DATA_END,
.bssStart = pause_BSS_START,
.bssEnd = pause_BSS_END,
};
void state_init_pause(void) {

View File

@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/ethteck/splat.git
branch = master
commit = fe30b60b75cd2660c45915e781599ccce9103246
parent = 28af7909768f4379f103ef590b33196353da84e1
commit = cc58f64954e8b7b2369b03db1152b161e6ccb78b
parent = c4e441d9ab91a2f63d7563c034772150934b48a1
method = merge
cmdver = 0.4.3

View File

@ -31,6 +31,12 @@ def to_cname(symbol: str) -> str:
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:
def __init__(self, segment: Segment, src_paths: List[Path], object_path: Path, section: str):
self.segment = segment
@ -60,29 +66,70 @@ class LinkerWriter():
self._begin_segment(segment)
seg_name = get_segment_cname(segment)
self._write_symbol(f"{seg_name}_TEXT_START", ".")
do_next = False
text_ended = False
data_started = False
data_ended = False
bss_started = False
cur_section = None
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._begin_segment(entry.segment)
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
if isinstance(start, int):
# Create new sections for non-0x10 alignment (hack)
if start % 0x10 != 0 and i != 0 or do_next:
self._end_block()
self._begin_segment(entry.segment, for_subalign=True)
self._begin_segment(entry.segment, mid_segment=True)
do_next = False
if start % 0x10 != 0 and i != 0:
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]))
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)
@ -136,7 +183,7 @@ class LinkerWriter():
self._writeln(f"{symbol} = {value};")
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
if not self.shiftable and isinstance(segment.rom_start, int):
self._writeln(f"__romPos = 0x{segment.rom_start:X};")
@ -149,12 +196,9 @@ class LinkerWriter():
vram = segment.vram_start
vram_str = f"0x{vram:X} " if isinstance(vram, int) else ""
if segment.parent:
name = to_cname(segment.parent.name + "_" + segment.name)
else:
name = to_cname(segment.name)
name = get_segment_cname(segment)
if for_subalign:
if mid_segment:
name += to_cname(segment.type)
self._write_symbol(f"{name}_ROM_START", "__romPos")
@ -166,17 +210,14 @@ class LinkerWriter():
def _end_segment(self, segment: Segment):
self._end_block()
if segment.parent:
name = to_cname(segment.parent.name + "_" + segment.name)
else:
name = to_cname(segment.name)
name = get_segment_cname(segment)
# force end if not shiftable/auto
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};")
else:
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("")