Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix REL section loading #81

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/java/gamecubeloader/rel/RELHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public boolean IsValid(BinaryReader reader) {
}

public int Size() {
switch ((int) this.moduleId) {
switch ((int) this.moduleVersion) {
case 0:
case 1:
return 0x40;
Expand All @@ -161,4 +161,8 @@ public int Size() {
return 0x4C;
}
}

public int FullSize() {
return this.Size() + (int) this.sectionCount * 8;
}
}
42 changes: 33 additions & 9 deletions src/main/java/gamecubeloader/rel/RELProgramBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,17 @@ else if (fileName.endsWith(".rel") || fileName.endsWith(".szs") || fileName.ends
var isText = (section.address & RELProgramBuilder.EXECUTABLE_SECTION) != 0;
var blockName = String.format("%s_%s%d", relInfo.name, isText ? ".text" : ".data", isText ? textCount : dataCount);

MemoryBlockUtils.createInitializedBlock(this.program, false, blockName, this.addressSpace.getAddress(currentOutputAddress),
relInfo.reader.getByteProvider().getInputStream(section.address & ~1), section.size, "", null, true, true, isText, null, this.monitor);
// Update the address of the section with its virtual memory address.
var offs = section.address & ~1;
section.address = relBaseAddress + offs;

MemoryBlockUtils.createInitializedBlock(this.program, false, blockName, this.addressSpace.getAddress(section.address),
relInfo.reader.getByteProvider().getInputStream(offs), section.size, "", null, true, true, isText, null, this.monitor);
vabold marked this conversation as resolved.
Show resolved Hide resolved

if (isText) textCount++;
else dataCount++;

// Update the address of the section with it's virtual memory address.
section.address = currentOutputAddress;

currentOutputAddress += section.size;
currentOutputAddress = section.address + section.size;

// Ensure output address is aligned to 4 bytes
if ((currentOutputAddress & 3) != 0) {
Expand All @@ -268,7 +269,30 @@ else if (relInfo.header.bssSectionId == 0) {

// Add bss section.
if (relInfo.header.bssSize != 0 && relInfo.header.bssSectionId != 0) {
if (relInfo.header.moduleVersion < 2 || relInfo.header.bssSectionAlignment == 0) {
if (this.specifyModuleMemAddrs) {
// TODO: Check against addresses already containing memory sections.
var setValidAddress = false;
while (!setValidAddress) {
var selectedAddress = OptionDialog.showInputSingleLineDialog(null, "Specify BSS Address", "Specify the BSS memory address for Module " +
relInfo.name, Long.toHexString(currentOutputAddress));

if (selectedAddress == null) {
break;
}

try {
var specifiedAddr = Long.parseUnsignedLong(selectedAddress, 16) & 0xFFFFFFFF;
if (specifiedAddr >= 0x80000000L && (specifiedAddr + relInfo.header.Size()) < 0x81800000L) {
currentOutputAddress = specifiedAddr;
setValidAddress = true;
}
}
catch (NumberFormatException e) {
continue;
}
}
}
else if (relInfo.header.moduleVersion < 2 || relInfo.header.bssSectionAlignment == 0) {
currentOutputAddress = align(currentOutputAddress, 0x20);
}
else {
Expand Down Expand Up @@ -311,7 +335,7 @@ else if (relInfo.header.bssSectionId == 0) {
name = name.substring(0, name.lastIndexOf("."));
}

mapLoadedResult = SymbolLoader.TryLoadAssociatedMapFile(name, directory, this.program, this.monitor, relBaseAddress, (int)relInfo.header.sectionAlignment,
mapLoadedResult = SymbolLoader.TryLoadAssociatedMapFile(name, directory, this.program, this.monitor, relBaseAddress + relInfo.header.FullSize(), (int)relInfo.header.sectionAlignment,
relInfo.header.bssSectionId != 0 ? relInfo.header.sections[relInfo.header.bssSectionId].address : 0);

if (mapLoadedResult.loaded != false) {
Expand All @@ -330,7 +354,7 @@ else if (relInfo.header.bssSectionId == 0) {

if (selectedFile != null) {
var reader = new FileReader(selectedFile);
var loader = new SymbolLoader(this.program, monitor, reader, relBaseAddress, 0,
var loader = new SymbolLoader(this.program, monitor, reader, relBaseAddress + relInfo.header.FullSize(), 0,
relInfo.header.bssSectionId != 0 ? relInfo.header.sections[relInfo.header.bssSectionId].address : 0,
this.binaryName, true);
this.symbolInfoList.add(loader.ApplySymbols());
Expand Down
Loading