Skip to content

Commit f8b479c

Browse files
committed
dvp: Mark VU sections as qwords so they show up more compact
1 parent 0b199d1 commit f8b479c

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/main/java/ghidra/emotionengine/dvp/DvpOverlayTable.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,28 @@ private Structure getDvpExtOverlay() {
4242
}
4343

4444
/**
45-
* Apply QWord data type to the memory block for compact display.
45+
* Apply QWord data type to a specific address range for compact display.
4646
* VU instructions are 16 bytes (2 qwords), so marking as qwords provides better visualization.
4747
*/
48-
private void applyQWordDataType(Program program, MemoryBlock block, TaskMonitor monitor) {
49-
int txId = program.startTransaction("Apply QWord data type to " + block.getName());
48+
private void applyQWordDataType(Program program, Address startAddr, long size, TaskMonitor monitor) {
49+
int txId = program.startTransaction("Apply QWord data type");
5050
try {
5151
Listing listing = program.getListing();
52-
Address addr = block.getStart();
53-
Address end = block.getEnd();
52+
Address addr = startAddr;
53+
Address end = startAddr.add(size - 1);
5454
DataType qword = QWordDataType.dataType;
5555

56+
// First, clear all existing code units (undefined data) in the range
57+
listing.clearCodeUnits(addr, end, false);
58+
59+
// Now apply qword data type across the range
5660
while (addr.compareTo(end) <= 0) {
5761
monitor.checkCancelled();
5862
try {
59-
// Only create data if there isn't already data at this location
60-
if (listing.getDataAt(addr) == null) {
61-
listing.createData(addr, qword);
62-
}
63+
listing.createData(addr, qword);
6364
addr = addr.add(8); // QWord is 8 bytes
6465
} catch (Exception e) {
65-
// If we can't create data here (e.g., not enough bytes), skip
66+
// If we can't create data here (e.g., not enough bytes remaining), stop
6667
break;
6768
}
6869
}
@@ -151,8 +152,12 @@ public void parse(TaskMonitor monitor) throws Exception {
151152

152153
scalar = (Scalar) comp.getComponent(1).getValue();
153154
Address mappedAddress = elf.getDefaultAddress(scalar.getValue());
155+
long sectionSize = section.getLogicalSize();
156+
157+
applyQWordDataType(elf.getProgram(), mappedAddress, sectionSize, monitor);
158+
154159
block = mem.createByteMappedBlock(
155-
blockName, addr, mappedAddress, (int) section.getLogicalSize(), true);
160+
blockName, addr, mappedAddress, (int) sectionSize, true);
156161
// TODO: Restore VU instructions in Sleigh files so we can enable this
157162
// if (section.isExecutable()) {
158163
// EmotionEngineLoader.setMicroMode(elf.getProgram(), block);
@@ -161,9 +166,6 @@ public void parse(TaskMonitor monitor) throws Exception {
161166
// }
162167
block.setRead(true);
163168
block.setWrite(section.isWritable());
164-
165-
// Apply QWord data type for compact display
166-
applyQWordDataType(elf.getProgram(), block, monitor);
167169
}
168170
catch (Exception e) {
169171
elf.getLog().appendException(e);
@@ -180,8 +182,13 @@ private void parseVuSection(ElfLoadHelper elfLoadHelper, ElfSectionHeader sectio
180182
String sectionName = section.getNameAsString();
181183
MemoryBlock origBlock = mem.getBlock(sectionAddress);
182184
try {
185+
long blockSize = origBlock.getSize();
186+
187+
// Apply QWord data type to source address BEFORE creating byte-mapped block
188+
applyQWordDataType(program, sectionAddress, blockSize, monitor);
189+
183190
MemoryBlock block = mem.createByteMappedBlock(
184-
sectionName + "_overlay", addr, sectionAddress, (int) origBlock.getSize(), true);
191+
sectionName + "_overlay", addr, sectionAddress, (int) blockSize, true);
185192
byte[] bytes = new byte[(int) section.getLogicalSize()];
186193
MemoryBufferImpl buf = new MemoryBufferImpl(mem, sectionAddress);
187194
buf.getBytes(bytes, 0);
@@ -197,9 +204,6 @@ private void parseVuSection(ElfLoadHelper elfLoadHelper, ElfSectionHeader sectio
197204
// EmotionEngineLoader.setMicroMode(program, block);
198205
// elfLoadHelper.createOneByteFunction(null, block.getStart(), true);
199206
// }
200-
201-
// Apply QWord data type for compact display
202-
applyQWordDataType(program, block, monitor);
203207
} catch (Exception e) {
204208
elfLoadHelper.getLog().appendException(e);
205209
}

0 commit comments

Comments
 (0)