Merge remote-tracking branch 'origin/GP-4149_James_frame_descriptor_entry_16_bit'

This commit is contained in:
Ryan Kurtz 2023-12-15 17:10:24 -05:00
commit e05c1d1600
7 changed files with 87 additions and 17 deletions

View file

@ -30,6 +30,7 @@ import ghidra.program.model.listing.*;
import ghidra.program.model.mem.*;
import ghidra.program.model.symbol.*;
import ghidra.program.model.util.CodeUnitInsertionException;
import ghidra.util.DataConverter;
import ghidra.util.Msg;
import ghidra.util.exception.InvalidInputException;
import ghidra.util.task.TaskMonitor;
@ -228,8 +229,8 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
curSize += locTypeSize;
program.getReferenceManager().addMemoryReference(addr, cieAddr, RefType.DATA,
SourceType.ANALYSIS, 0);
program.getReferenceManager()
.addMemoryReference(addr, cieAddr, RefType.DATA, SourceType.ANALYSIS, 0);
return addr.add(locTypeSize);
}
@ -267,8 +268,8 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
createAndCommentData(program, addr, encodedDt, comment, CodeUnit.EOL_COMMENT);
if (pcBeginAddr.getOffset() != 0x0) {
program.getReferenceManager().addMemoryReference(addr, pcBeginAddr, RefType.DATA,
SourceType.ANALYSIS, 0);
program.getReferenceManager()
.addMemoryReference(addr, pcBeginAddr, RefType.DATA, SourceType.ANALYSIS, 0);
}
curSize += encodedLen;
@ -293,7 +294,12 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
*/
String comment = "(FDE) PcRange";
intPcRange = (int) GccAnalysisUtils.readDWord(program, addr);
DataType dataType = getAddressSizeDataType();
byte[] range = new byte[dataType.getLength()];
GccAnalysisUtils.readBytes(program, addr, range);
DataConverter converter = DataConverter.getInstance(program.getMemory().isBigEndian());
intPcRange = (int) converter.getSignedValue(range, range.length);
if (intPcRange < 0) {
return null;
}
@ -303,7 +309,6 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
}
pcEndAddr = pcBeginAddr.add(intPcRange - 1);
DataType dataType = getAddressSizeDataType();
if (dataType.getLength() == 8) {
// While this is 64-bit system, this length may be encoded as a 32-bit value,
// arguing a length needn't use all 8 bytes. If it *is* encoded in 8 bytes, the
@ -389,8 +394,6 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
* @throws MemoryAccessException if the required memory can't be read
*/
private Address createCallFrameInstructions(Address addr) throws MemoryAccessException {
CreateArrayCmd arrayCmd = null;
// Create initial instructions array with remaining bytes.
int instructionLength = intLength - curSize;
ArrayDataType adt = new ArrayDataType(ByteDataType.dataType, instructionLength, BYTE_LEN);
@ -589,16 +592,17 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
createData(program, augmentationDataAddr, DWordDataType.dataType);
program.getReferenceManager().addMemoryReference(augmentationDataAddr,
augmentationDataExAddr, RefType.DATA, SourceType.ANALYSIS, 0);
program.getReferenceManager()
.addMemoryReference(augmentationDataAddr, augmentationDataExAddr,
RefType.DATA, SourceType.ANALYSIS, 0);
try {
String label = "eh_augmentation_" + pcBeginAddr + ".." + pcEndAddr + "_" +
augmentationDataExAddr;
program.getSymbolTable().createLabel(augmentationDataExAddr, label,
SourceType.ANALYSIS);
program.getSymbolTable()
.createLabel(augmentationDataExAddr, label, SourceType.ANALYSIS);
}
catch (InvalidInputException e) {
// ignored
@ -634,8 +638,9 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
return;
}
program.getReferenceManager().addMemoryReference(augmentationDataAddr, lsdaAddr,
RefType.DATA, SourceType.ANALYSIS, 0);
program.getReferenceManager()
.addMemoryReference(augmentationDataAddr, lsdaAddr, RefType.DATA,
SourceType.ANALYSIS, 0);
if (!program.getMemory().getAllInitializedAddressSet().contains(lsdaAddr)) {

View file

@ -3,10 +3,12 @@ Module.manifest||GHIDRA||||END|
data/languages/TI430Common.sinc||GHIDRA||||END|
data/languages/TI430X.sinc||GHIDRA||||END|
data/languages/TI_MSP430.cspec||GHIDRA||||END|
data/languages/TI_MSP430.dwarf||GHIDRA||||END|
data/languages/TI_MSP430.ldefs||GHIDRA||||END|
data/languages/TI_MSP430.pspec||GHIDRA||||END|
data/languages/TI_MSP430.slaspec||GHIDRA||||END|
data/languages/TI_MSP430X.cspec||GHIDRA||||END|
data/languages/TI_MSP430X.dwarf||GHIDRA||||END|
data/languages/TI_MSP430X.slaspec||GHIDRA||||END|
data/languages/ti_msp430.opinion||GHIDRA||||END|
data/manuals/MSP430.idx||GHIDRA||reviewed||END|

View file

@ -1,6 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--Information from "MSP430 Embedded Application Binary Interface Rev A -->
<compiler_spec>
<data_organization>
<machine_alignment value="2" />
<default_alignment value="1" />
<default_pointer_alignment value="2" />
<pointer_size value="2" />
<short_size value="2" />
<integer_size value="2" />
<wchar_size value="2" />
<long_size value="4" />
<long_long_size value="8" />
<float_size value="4" />
<double_size value="8" />
<long_double_size value="8" />
<size_alignment_map>
<entry size="1" alignment="1" />
<entry size="2" alignment="2" />
<entry size="4" alignment="2" />
<entry size="8" alignment="2" />
</size_alignment_map>
</data_organization>
<global>
<range space="RAM"/>
</global>

View file

@ -0,0 +1,9 @@
<dwarf>
<register_mappings>
<register_mapping dwarf="0" ghidra="PC"/>
<register_mapping dwarf="1" ghidra="SP" stackpointer="true"/>
<register_mapping dwarf="2" ghidra="SR"/>
<register_mapping dwarf="3" ghidra="R3" auto_count="13"/> <!-- R3..R15 -->
</register_mappings>
<call_frame_cfa value="2"/>
</dwarf>

View file

@ -12,7 +12,8 @@
id="TI_MSP430:LE:16:default">
<description>TI MSP430 16-Bit MicroController</description>
<compiler name="default" spec="TI_MSP430.cspec" id="default"/>
<external_name tool="gnu" name="msp:430X"/>
<external_name tool="gnu" name="msp:14"/>
<external_name tool="DWARF.register.mapping.file" name="TI_MSP430.dwarf"/>
<external_name tool="IDA-PRO" name="msp430"/>
</language>
<language processor="TI_MSP430X"
@ -26,6 +27,8 @@
id="TI_MSP430X:LE:32:default">
<description>TI MSP430X 20-Bit MicroController</description>
<compiler name="default" spec="TI_MSP430X.cspec" id="default"/>
<external_name tool="gnu" name="msp:14"/>
<external_name tool="IDA-PRO" name="msp430"/>
<external_name tool="DWARF.register.mapping.file" name="TI_MSP430X.dwarf"/>
</language>
</language_definitions>

View file

@ -1,6 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--From "MSP430 Embedded Application Binary Interface Rev A -->
<!-- large code model -->
<compiler_spec>
<data_organization>
<machine_alignment value="2" />
<default_alignment value="1" />
<default_pointer_alignment value="2" />
<pointer_size value="4" />
<short_size value="2" />
<integer_size value="2" />
<wchar_size value="2" />
<long_size value="4" />
<long_long_size value="8" />
<float_size value="4" />
<double_size value="8" />
<long_double_size value="8" />
<size_alignment_map>
<entry size="1" alignment="1" />
<entry size="2" alignment="2" />
<entry size="4" alignment="2" />
<entry size="8" alignment="2" />
</size_alignment_map>
</data_organization>
<global>
<range space="RAM"/>
</global>

View file

@ -0,0 +1,9 @@
<dwarf>
<register_mappings>
<register_mapping dwarf="0" ghidra="PC"/>
<register_mapping dwarf="1" ghidra="SP" stackpointer="true"/>
<register_mapping dwarf="2" ghidra="SR"/>
<register_mapping dwarf="3" ghidra="R3" auto_count="13"/> <!-- R3..R15 -->
</register_mappings>
<call_frame_cfa value="4"/>
</dwarf>