mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-29 06:29:30 +08:00
GP-1487: Adding better explanation for pcode UNIMPLEMENTED.
This commit is contained in:
+23
@@ -900,4 +900,27 @@ public class TracePcodeEmulatorTest extends AbstractGhidraHeadlessIntegrationTes
|
||||
TraceSleighUtils.evaluate("RCX", tb.trace, 1, thread, 0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,10 +122,22 @@ public class PcodeExecutor<T> {
|
||||
}
|
||||
}
|
||||
|
||||
protected void badOp(PcodeOp op) {
|
||||
switch (op.getOpcode()) {
|
||||
case PcodeOp.UNIMPLEMENTED:
|
||||
throw new LowlevelError(
|
||||
"Encountered an unimplemented instruction at " + op.getSeqnum().getTarget());
|
||||
default:
|
||||
throw new LowlevelError(
|
||||
"Unsupported p-code op at " + op.getSeqnum().getTarget() + ": " + op);
|
||||
}
|
||||
}
|
||||
|
||||
public void stepOp(PcodeOp op, PcodeFrame frame, SleighUseropLibrary<T> library) {
|
||||
OpBehavior b = OpBehaviorFactory.getOpBehavior(op.getOpcode());
|
||||
if (b == null) {
|
||||
throw new LowlevelError("Unsupported pcode op" + op);
|
||||
badOp(op);
|
||||
return;
|
||||
}
|
||||
if (b instanceof UnaryOpBehavior) {
|
||||
executeUnaryOp(op, (UnaryOpBehavior) b);
|
||||
@@ -164,7 +176,8 @@ public class PcodeExecutor<T> {
|
||||
executeReturn(op, frame);
|
||||
return;
|
||||
default:
|
||||
throw new LowlevelError("Unsupported op " + op);
|
||||
badOp(op);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
# 1010 0100 ssss tttt # user_four rs rt user_four rs rt
|
||||
# 1010 0101 nnnn nnnn # user_five n user_five n
|
||||
# 1010 0110 ssss 0000 # user_six rs user_six rs
|
||||
# 1010 1000 0000 0000 # unimpl
|
||||
#
|
||||
#### RESERVED
|
||||
# 1101 1001 xxxx xxxx # RESERVED BANK
|
||||
@@ -222,3 +223,4 @@ define pcodeop pcodeop_three;
|
||||
:user_five Rel8 is $(INSTR_PHASE) op1215=0xa & op0811=0x05 & Rel8 { lr = inst_next; call Rel8; pcodeop_three();}
|
||||
:user_six rs is $(INSTR_PHASE) op1215=0xa & op0811=0x06 & rs & op0003=0x0 { r1 = pcodeop_one(rs); call [r1];}
|
||||
|
||||
:unimpl is $(INSTR_PHASE) op1215=0xa & op0811=0x08 & op0007=0 unimpl
|
||||
|
||||
Reference in New Issue
Block a user