Skip to content

Ghidra is a software reverse engineering (SRE) framework

Merge remote-tracking branch 'origin/GP-1540_Dan_emulateHarvard--SQUASHED' into Ghidra_10.1

ghidra10f0b63f6ad44
diff --cc Ghidra/Debug/Framework-TraceModeling/src/test/java/ghidra/pcode/exec/trace/TracePcodeEmulatorTest.java
index 3e43785a74,cca372c262..364a4e3186
--- a/Ghidra/Debug/Framework-TraceModeling/src/test/java/ghidra/pcode/exec/trace/TracePcodeEmulatorTest.java
+++ b/Ghidra/Debug/Framework-TraceModeling/src/test/java/ghidra/pcode/exec/trace/TracePcodeEmulatorTest.java
@@@ -984,26 -989,38 +989,61 @@@ public class TracePcodeEmulatorTest ext
}
}
+ /**
+ * Test that unimplemented instructions (as opposed to instructions with no semantics) result in
+ * an interrupt.
+ */
+ @Test(expected = PcodeExecutionException.class)
+ public void testUNIMPL() throws Throwable {
+ try (ToyDBTraceBuilder tb = new ToyDBTraceBuilder("Test", "Toy:BE:64:default")) {
+ assertEquals(Register.NO_CONTEXT, tb.language.getContextBaseRegister());
+
+ TraceThread thread = initTrace(tb,
+ List.of(
+ "pc = 0x00400000;",
+ "sp = 0x00110000;"),
+ List.of(
+ "unimpl"));
+
+ TracePcodeEmulator emu = new TracePcodeEmulator(tb.trace, 0);
+ PcodeThread<byte[]> emuThread = emu.newThread(thread.getPath());
+ emuThread.overrideContextWithDefault();
+ emuThread.stepInstruction();
+ }
+ }
++
+ @Test
+ public void testMov_w_mW1_W0() throws Throwable {
+ try (ToyDBTraceBuilder tb = new ToyDBTraceBuilder("Test", "dsPIC33F:LE:24:default")) {
+ Address textStart = tb.language.getDefaultSpace().getAddress(0x000100, true);
+ // TODO: Where is the stack typically on this arch?
+ Address stackStart = tb.language.getDefaultDataSpace().getAddress(0, true);
+ TraceThread thread = initTrace(tb,
+ new AddressRangeImpl(textStart, 0x200),
+ new AddressRangeImpl(stackStart, 1),
+ List.of(
+ "PC = 0x000100;",
+ "W1 = 0x0800;",
+ "*[ram]:2 0x000800:3 = 0x1234;"),
+ List.of(
+ "mov.w [W1], W0"));
+
+ TracePcodeEmulator emu = new TracePcodeEmulator(tb.trace, 0);
+ PcodeThread<byte[]> emuThread = emu.newThread(thread.getPath());
+ //emuThread.overrideContextWithDefault(); // default context is null?
+ emuThread.stepInstruction();
+
+ try (UndoableTransaction tid = tb.startTransaction()) {
+ emu.writeDown(tb.trace, 1, 1, false);
+ }
+
+ assertEquals(BigInteger.valueOf(0x000102),
+ TraceSleighUtils.evaluate("PC", tb.trace, 1, thread, 0));
+ assertEquals(BigInteger.valueOf(0x1234),
+ TraceSleighUtils.evaluate("W0", tb.trace, 1, thread, 0));
+ assertEquals(BigInteger.valueOf(0x0800),
+ TraceSleighUtils.evaluate("W1", tb.trace, 1, thread, 0));
+ }
+ }
+
}