77import ghidra .program .model .address .Address ;
88import ghidra .program .model .data .*;
99import ghidra .program .model .listing .Data ;
10+ import ghidra .program .model .listing .Listing ;
1011import ghidra .program .model .listing .Program ;
1112import ghidra .program .model .mem .Memory ;
1213import ghidra .program .model .mem .MemoryBlock ;
@@ -40,6 +41,39 @@ private Structure getDvpExtOverlay() {
4041 return struct ;
4142 }
4243
44+ /**
45+ * Apply QWord data type to the memory block for compact display.
46+ * VU instructions are 16 bytes (2 qwords), so marking as qwords provides better visualization.
47+ */
48+ private void applyQWordDataType (Program program , MemoryBlock block , TaskMonitor monitor ) {
49+ int txId = program .startTransaction ("Apply QWord data type to " + block .getName ());
50+ try {
51+ Listing listing = program .getListing ();
52+ Address addr = block .getStart ();
53+ Address end = block .getEnd ();
54+ DataType qword = QWordDataType .dataType ;
55+
56+ // First, clear all existing code units (undefined data) in the block
57+ listing .clearCodeUnits (addr , end , false );
58+
59+ // Now apply qword data type across the entire block
60+ while (addr .compareTo (end ) <= 0 ) {
61+ monitor .checkCancelled ();
62+ try {
63+ listing .createData (addr , qword );
64+ addr = addr .add (8 ); // QWord is 8 bytes
65+ } catch (Exception e ) {
66+ // If we can't create data here (e.g., not enough bytes remaining), stop
67+ break ;
68+ }
69+ }
70+ program .endTransaction (txId , true );
71+ } catch (Exception e ) {
72+ program .endTransaction (txId , false );
73+ elf .getLog ().appendException (e );
74+ }
75+ }
76+
4377 @ Override
4478 public void parse (TaskMonitor monitor ) throws Exception {
4579 Memory mem = elf .getProgram ().getMemory ();
@@ -50,11 +84,11 @@ public void parse(TaskMonitor monitor) throws Exception {
5084 // only 1 function
5185 ElfSectionHeader section = elfHeader .getSection (".vutext" );
5286 if (section != null ) {
53- parseVuSection (elf , section );
87+ parseVuSection (elf , section , monitor );
5488 }
5589 section = elfHeader .getSection (".vudata" );
5690 if (section != null ) {
57- parseVuSection (elf , section );
91+ parseVuSection (elf , section , monitor );
5892 }
5993 return ;
6094 }
@@ -128,14 +162,17 @@ public void parse(TaskMonitor monitor) throws Exception {
128162 // }
129163 block .setRead (true );
130164 block .setWrite (section .isWritable ());
165+
166+ // Apply QWord data type for compact display
167+ applyQWordDataType (elf .getProgram (), block , monitor );
131168 }
132169 catch (Exception e ) {
133170 elf .getLog ().appendException (e );
134171 }
135172 }
136173 }
137174
138- private void parseVuSection (ElfLoadHelper elfLoadHelper , ElfSectionHeader section ) {
175+ private void parseVuSection (ElfLoadHelper elfLoadHelper , ElfSectionHeader section , TaskMonitor monitor ) {
139176 Program program = elfLoadHelper .getProgram ();
140177 Memory mem = program .getMemory ();
141178 long base = section .isExecutable () ? VU1_TEXT_ADDRESS : VU1_DATA_ADDRESS ;
@@ -161,6 +198,9 @@ private void parseVuSection(ElfLoadHelper elfLoadHelper, ElfSectionHeader sectio
161198 // EmotionEngineLoader.setMicroMode(program, block);
162199 // elfLoadHelper.createOneByteFunction(null, block.getStart(), true);
163200 // }
201+
202+ // Apply QWord data type for compact display
203+ applyQWordDataType (program , block , monitor );
164204 } catch (Exception e ) {
165205 elfLoadHelper .getLog ().appendException (e );
166206 }
0 commit comments