GT-2880 set thumb on mem; fix exception handling under thumb

This commit is contained in:
ghizard
2019-06-05 14:21:01 -04:00
parent 64c5f7bd24
commit 7f3dc05d70
2 changed files with 17 additions and 7 deletions
@@ -473,14 +473,21 @@ public class PeLoader extends AbstractPeDebugLoader {
private void setProcessorContext(FileHeader fileHeader, Program program, TaskMonitor monitor, private void setProcessorContext(FileHeader fileHeader, Program program, TaskMonitor monitor,
MessageLog log) { MessageLog log) {
String machineName = fileHeader.getMachineName(); try {
if ("450".equals(machineName) || "452".equals(machineName)) { String machineName = fileHeader.getMachineName();
Register tmodeReg = program.getProgramContext().getRegister("TMode"); if ("450".equals(machineName) || "452".equals(machineName)) {
if (tmodeReg == null) { Register tmodeReg = program.getProgramContext().getRegister("TMode");
return; if (tmodeReg == null) {
return;
}
RegisterValue thumbMode = new RegisterValue(tmodeReg, BigInteger.ONE);
AddressSpace space = program.getAddressFactory().getDefaultAddressSpace();
program.getProgramContext().setRegisterValue(space.getMinAddress(),
space.getMaxAddress(), thumbMode);
} }
RegisterValue thumbMode = new RegisterValue(tmodeReg, BigInteger.ONE); }
program.getProgramContext().setDefaultDisassemblyContext(thumbMode); catch (ContextChangeException e) {
throw new AssertException("instructions should not exist");
} }
} }
@@ -17,6 +17,7 @@ package ghidra.app.cmd.data;
import ghidra.app.cmd.disassemble.DisassembleCommand; import ghidra.app.cmd.disassemble.DisassembleCommand;
import ghidra.app.cmd.function.CreateFunctionCmd; import ghidra.app.cmd.function.CreateFunctionCmd;
import ghidra.app.util.PseudoDisassembler;
import ghidra.app.util.datatype.microsoft.DataApplyOptions; import ghidra.app.util.datatype.microsoft.DataApplyOptions;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressOutOfBoundsException; import ghidra.program.model.address.AddressOutOfBoundsException;
@@ -323,6 +324,8 @@ public class EHDataTypeUtilities {
public static boolean createFunctionIfNeeded(Program program, Address functionAddress) { public static boolean createFunctionIfNeeded(Program program, Address functionAddress) {
// If there isn't an instruction at the function address yet, then disassemble there. // If there isn't an instruction at the function address yet, then disassemble there.
Listing listing = program.getListing(); Listing listing = program.getListing();
functionAddress =
PseudoDisassembler.getNormalizedDisassemblyAddress(program, functionAddress);
Instruction inst = listing.getInstructionAt(functionAddress); Instruction inst = listing.getInstructionAt(functionAddress);
if (inst == null) { if (inst == null) {
DisassembleCommand cmd = new DisassembleCommand(functionAddress, null, true); DisassembleCommand cmd = new DisassembleCommand(functionAddress, null, true);