Interface PcodeEmulationCallbacks<T>
- Type Parameters:
T- the type of values in the emulator
- All Known Subinterfaces:
TraceEmulationIntegration.Writer
- All Known Implementing Classes:
ComposedPcodeEmulationCallbacks,PcodeEmulationCallbacks.NoPcodeEmulationCallbacks,TraceEmulationIntegration.TraceWriter
Note that some emulator extensions (notably the JIT-accelerated emulator) may disable and/or slightly change the specification of these callbacks. Read an emulator's documentation carefully. That said, an extension should strive to adhere to this specification as closely as possible.
See PcodeEmulator for advice regarding extending the emulator versus integrating with an
emulator. Use of these callbacks is favored over extending an emulator when possible, as this
favors composition of such integrations.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumA singleton implementation of the callbacks that does nothing.static final recordA wrapper that can forward callbacks from state pieces to callbacks for the emulator, for a given thread. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidafterBranch(PcodeThread<T> thread, PcodeOp op, Address target) The emulator has just branched to an address.default voidafterExecuteInject(PcodeThread<T> thread, Address address) The emulator has just finished executing an injected p-code program.default voidafterExecuteInstruction(PcodeThread<T> thread, Instruction instruction) The emulator has finished executing an instruction.default voidafterLoad(PcodeThread<T> thread, PcodeOp op, AddressSpace space, T offset, int size, T value) The emulator has just loaded a value from its execution state.default voidafterStepOp(PcodeThread<T> thread, PcodeOp op, PcodeFrame frame) The emulator has just executed a p-code op.default voidafterStore(PcodeThread<T> thread, PcodeOp op, AddressSpace space, T offset, int size, T value) The emulator has just stored a value into its execution state.default voidbeforeDecodeInstruction(PcodeThread<T> thread, Address counter, RegisterValue context) The emulator, having found no injects, is preparing to decode an instruction.default voidbeforeExecuteInject(PcodeThread<T> thread, Address address, PcodeProgram program) The emulator is preparing to execute an injected program.default voidbeforeExecuteInstruction(PcodeThread<T> thread, Instruction instruction, PcodeProgram program) The emulator is preparing to execute a decoded instruction.default voidbeforeLoad(PcodeThread<T> thread, PcodeOp op, AddressSpace space, T offset, int size) The emulator is preparing to load a value from its execution state.default voidbeforeStepOp(PcodeThread<T> thread, PcodeOp op, PcodeFrame frame) The emulator is preparing to execute a p-code op.default voidbeforeStore(PcodeThread<T> thread, PcodeOp op, AddressSpace space, T offset, int size, T value) The emulator is preparing to store a value into its execution state.default <A,U> void dataWritten(PcodeThread<T> thread, PcodeExecutorStatePiece<A, U> piece, Address address, int length, U value) Data was written into the given state piece (concrete addressing).default <A,U> void dataWritten(PcodeThread<T> thread, PcodeExecutorStatePiece<A, U> piece, AddressSpace space, A offset, int length, U value) Data was written into the given state piece (abstract addressing).default <A,U> void delegateDataWritten(PcodeThread<T> thread, PcodeExecutorStatePiece<A, U> piece, Address address, int length, U value) Typically used from withindataWritten(PcodeThread, PcodeExecutorStatePiece, Address, int, Object)to forward the call to the callback for abstract addressingdataWritten(PcodeThread, PcodeExecutorStatePiece, AddressSpace, Object, int, Object).default <A,U> void delegateDataWritten(PcodeThread<T> thread, PcodeExecutorStatePiece<A, U> piece, AddressSpace space, A offset, int length, U value) Typically used from withindataWritten(PcodeThread, PcodeExecutorStatePiece, AddressSpace, Object, int, Object)to forward the call to the callback for concrete addressingdataWritten(PcodeThread, PcodeExecutorStatePiece, Address, int, Object).default <A,U> AddressSetView delegateReadUninitialized(PcodeThread<T> thread, PcodeExecutorStatePiece<A, U> piece, AddressSetView set) Typically used from withinreadUninitialized(PcodeThread, PcodeExecutorStatePiece, AddressSetView)to forward to the callback for abstract addressingreadUninitialized(PcodeThread, PcodeExecutorStatePiece, AddressSpace, Object, int).default <A,U> int delegateReadUninitialized(PcodeThread<T> thread, PcodeExecutorStatePiece<A, U> piece, AddressSpace space, A offset, int length) Typically used from withinreadUninitialized(PcodeThread, PcodeExecutorStatePiece, AddressSpace, Object, int)to forward to the callback for concrete addressingreadUninitialized(PcodeThread, PcodeExecutorStatePiece, AddressSetView).default voidemulatorCreated(PcodeMachine<T> machine) The emulator has been created, but not yet finished construction.default PcodeProgramgetInject(PcodeThread<T> thread, Address address) The emulator is preparing to decode an instruction, but is checking for injected overrides first.default booleanhandleMissingUserop(PcodeThread<T> thread, PcodeOp op, PcodeFrame frame, String opName, PcodeUseropLibrary<T> library) The emulator has encountered a userop for which it has no definition.static <T> PcodeEmulationCallbacks<T> none()Obtain callbacks that do nothing.default <A,U> AddressSetView readUninitialized(PcodeThread<T> thread, PcodeExecutorStatePiece<A, U> piece, AddressSetView set) The emulator is preparing to read from uninitialized portions of the given state piece (concrete addressing).default <A,U> int readUninitialized(PcodeThread<T> thread, PcodeExecutorStatePiece<A, U> piece, AddressSpace space, A offset, int length) The emulator is preparing to read from uninitialized portions of the given state piece (abstract addressing).default voidsharedStateCreated(PcodeMachine<T> machine) The emulator's shared state has been created.default voidthreadCreated(PcodeThread<T> thread) A new thread has just been created.default PcodeStateCallbackswrapFor(PcodeThread<T> thread) Obtain a callback wrapper suitable for passing into an emulator's execution states
-
Method Details
-
none
Obtain callbacks that do nothing.- Type Parameters:
T- the domain- Returns:
PcodeEmulationCallbacks.NoPcodeEmulationCallbacks.INSTANCE
-
emulatorCreated
The emulator has been created, but not yet finished construction.WARNING: At this point, the emulator has not been fully constructed. The most the callback ought to do is save a pointer to the machine. Attempting to access the machine or invoke any of its methods will likely result in a
NullPointerException. Use thesharedStateCreated(PcodeMachine)callback to access the machine after it has been constructed- Parameters:
machine- the emulator or abstract machine.
-
threadCreated
A new thread has just been created.The thread is fully constructed. This callback may access it.
- Parameters:
thread- the new thread
-
getInject
The emulator is preparing to decode an instruction, but is checking for injected overrides first.- Parameters:
thread- the threadaddress- the thread's program counter- Returns:
- null, or a p-code program to override the instruction
- See Also:
-
beforeExecuteInject
The emulator is preparing to execute an injected program.- Parameters:
thread- the threadaddress- the thread's program counterprogram- the injected p-code program- See Also:
-
afterExecuteInject
The emulator has just finished executing an injected p-code program.If the program executed a branch, then
addresswill be the target address. Note that any sane inject ought to execute a branch, even to effect fall-through, otherwise the program counter cannot advance.- Parameters:
thread- the threadaddress- the thread's program counter
-
beforeDecodeInstruction
The emulator, having found no injects, is preparing to decode an instruction.- Parameters:
thread- the threadcounter- the thread's program countercontext- the decode contextreg value
-
beforeExecuteInstruction
default void beforeExecuteInstruction(PcodeThread<T> thread, Instruction instruction, PcodeProgram program) The emulator is preparing to execute a decoded instruction.- Parameters:
thread- the threadinstruction- the decoded instructionprogram- the instruction's p-code program
-
afterExecuteInstruction
The emulator has finished executing an instruction.- Parameters:
thread- the threadinstruction- the just-executed instruction
-
beforeStepOp
The emulator is preparing to execute a p-code op.- Parameters:
thread- the threadop- the opframe- the frame for the current p-code program
-
afterStepOp
The emulator has just executed a p-code op.- Parameters:
thread- the threadop- the opframe- the frame for the current p-code program
-
beforeLoad
The emulator is preparing to load a value from its execution state.- Parameters:
thread- the threadop- thePcodeOp.LOADopspace- the address space of the operandoffset- the offset of the operandsize- the size of the operand
-
afterLoad
default void afterLoad(PcodeThread<T> thread, PcodeOp op, AddressSpace space, T offset, int size, T value) The emulator has just loaded a value from its execution state.- Parameters:
thread- the threadop- thePcodeOp.LOADopspace- the address space of the operandoffset- the offset of the operandsize- the size of the operandvalue- the value loaded
-
beforeStore
default void beforeStore(PcodeThread<T> thread, PcodeOp op, AddressSpace space, T offset, int size, T value) The emulator is preparing to store a value into its execution state.- Parameters:
thread- the threadop- thePcodeOp.STOREopspace- the address space of the operandoffset- the offset of the operandsize- the size of the operandvalue- the value to store
-
afterStore
default void afterStore(PcodeThread<T> thread, PcodeOp op, AddressSpace space, T offset, int size, T value) The emulator has just stored a value into its execution state.- Parameters:
thread- the threadop- thePcodeOp.STOREopspace- the address space of the operandoffset- the offset of the operandsize- the size of the operandvalue- the value stored
-
afterBranch
The emulator has just branched to an address.- Parameters:
thread- the threadop- the branching optarget- the new program counter
-
handleMissingUserop
default boolean handleMissingUserop(PcodeThread<T> thread, PcodeOp op, PcodeFrame frame, String opName, PcodeUseropLibrary<T> library) The emulator has encountered a userop for which it has no definition.Emulation has not yet been interrupted at this point. If a callback returns true, indicating the fault has been handled, then the emulator will proceed. If not, then emulation for this thread will be interrupted
- Parameters:
thread- the threadop- thePcodeOp.CALLOTHERopframe- the frame for the current p-code programopName- the name of the userop being calledlibrary- the thread's userop library- Returns:
- true if handled, false if not
-
dataWritten
default <A,U> void dataWritten(PcodeThread<T> thread, PcodeExecutorStatePiece<A, U> piece, AddressSpace space, A offset, int length, U value) Data was written into the given state piece (abstract addressing).NOTE: In contrast to the operation-driven callbacks, e.g.,
beforeStore(PcodeThread, PcodeOp, AddressSpace, Object, int, Object), thethreadparameter here may be null. It is not necessarily the thread executing the op, but the thread associated to the state being accessed. In particular, when this is the shared state,threadwill be null. When this is the local state,threadwill be the thread of execution. If this behavior poses a serious limitation, then we may consider changing this to always be the thread of execution.- Type Parameters:
A- the piece's address domainU- the piece's value domain- Parameters:
thread- the thread associated to the piecepiece- the state piecespace- the address space of the operandoffset- the offset of the operandlength- the size of the operandvalue- the value written
-
delegateDataWritten
default <A,U> void delegateDataWritten(PcodeThread<T> thread, PcodeExecutorStatePiece<A, U> piece, AddressSpace space, A offset, int length, U value) Typically used from withindataWritten(PcodeThread, PcodeExecutorStatePiece, AddressSpace, Object, int, Object)to forward the call to the callback for concrete addressingdataWritten(PcodeThread, PcodeExecutorStatePiece, Address, int, Object).- Type Parameters:
A- the piece's address domainU- the piece's value domain- Parameters:
thread- the thread associated to the piece. SeedataWritten(PcodeThread, PcodeExecutorStatePiece, AddressSpace, Object, int, Object)piece- the state piecespace- the address space of the operandoffset- the offset of the operandlength- the size of the operandvalue- the value written
-
dataWritten
default <A,U> void dataWritten(PcodeThread<T> thread, PcodeExecutorStatePiece<A, U> piece, Address address, int length, U value) Data was written into the given state piece (concrete addressing).- Type Parameters:
A- the piece's address domainU- the piece's value domain- Parameters:
thread- the thread associated to the piece. SeedataWritten(PcodeThread, PcodeExecutorStatePiece, AddressSpace, Object, int, Object)piece- the state pieceaddress- the address of the operandlength- the size of the operandvalue- the value written
-
delegateDataWritten
default <A,U> void delegateDataWritten(PcodeThread<T> thread, PcodeExecutorStatePiece<A, U> piece, Address address, int length, U value) Typically used from withindataWritten(PcodeThread, PcodeExecutorStatePiece, Address, int, Object)to forward the call to the callback for abstract addressingdataWritten(PcodeThread, PcodeExecutorStatePiece, AddressSpace, Object, int, Object).- Type Parameters:
A- the piece's address domainU- the piece's value domain- Parameters:
thread- the thread associated to the piece. SeedataWritten(PcodeThread, PcodeExecutorStatePiece, AddressSpace, Object, int, Object)piece- the state pieceaddress- the address of the operandlength- the size of the operandvalue- the value written
-
readUninitialized
default <A,U> int readUninitialized(PcodeThread<T> thread, PcodeExecutorStatePiece<A, U> piece, AddressSpace space, A offset, int length) The emulator is preparing to read from uninitialized portions of the given state piece (abstract addressing).This callback provides an opportunity for something to initialize the required portion lazily. In most cases, this should either return 0 indicating the requested portion remains uninitialized, or the full
lengthindicating the full requested portion is now initialized. If, for some reason, the requested portion could only be partially initialized, this can return a smaller length. Partial initializations are only recognized from the starting offset. Other parts could be initialized; however, there is no mechanism for communicating that result to the emulator.- Type Parameters:
A- the piece's address domainU- the piece's value domain- Parameters:
thread- the thread associated to the piece. SeedataWritten(PcodeThread, PcodeExecutorStatePiece, AddressSpace, Object, int, Object)piece- the state piecespace- the address space of the operandoffset- the offset of the operandlength- the size of the operand- Returns:
- the length of the operand just initialized, typically 0 or
length
-
delegateReadUninitialized
default <A,U> int delegateReadUninitialized(PcodeThread<T> thread, PcodeExecutorStatePiece<A, U> piece, AddressSpace space, A offset, int length) Typically used from withinreadUninitialized(PcodeThread, PcodeExecutorStatePiece, AddressSpace, Object, int)to forward to the callback for concrete addressingreadUninitialized(PcodeThread, PcodeExecutorStatePiece, AddressSetView).- Type Parameters:
A- the piece's address domainU- the piece's value domain- Parameters:
thread- the thread associated to the piece. SeedataWritten(PcodeThread, PcodeExecutorStatePiece, AddressSpace, Object, int, Object)piece- the state piecespace- the address space of the operandoffset- the offset of the operandlength- the size of the operand- Returns:
- the length of the operand just initialized, typically 0 or
length
-
readUninitialized
default <A,U> AddressSetView readUninitialized(PcodeThread<T> thread, PcodeExecutorStatePiece<A, U> piece, AddressSetView set) The emulator is preparing to read from uninitialized portions of the given state piece (concrete addressing).This callback provides an opportunity for something to initialize the required portion lazily. This method must return the address set that remains uninitialized. If no part of the required portion was initialized, this should return
setidentically, so that the caller can quickly recognize that nothing has changed. Otherwise, this should copyset, remove those parts it was able to initialize, and return the copy. DO NOT modify the givenset.- Type Parameters:
A- the piece's address domainU- the piece's value domain- Parameters:
thread- the thread associated to the piece. SeedataWritten(PcodeThread, PcodeExecutorStatePiece, AddressSpace, Object, int, Object)piece- the state pieceset- the uninitialized portion required- Returns:
- the addresses in
setthat remain uninitialized
-
delegateReadUninitialized
default <A,U> AddressSetView delegateReadUninitialized(PcodeThread<T> thread, PcodeExecutorStatePiece<A, U> piece, AddressSetView set) Typically used from withinreadUninitialized(PcodeThread, PcodeExecutorStatePiece, AddressSetView)to forward to the callback for abstract addressingreadUninitialized(PcodeThread, PcodeExecutorStatePiece, AddressSpace, Object, int).- Type Parameters:
A- the piece's address domainU- the piece's value domain- Parameters:
thread- the thread associated to the piece. SeedataWritten(PcodeThread, PcodeExecutorStatePiece, AddressSpace, Object, int, Object)piece- the state pieceset- the uninitialized portion required- Returns:
- the addresses in
setthat remain uninitialized
-
wrapFor
Obtain a callback wrapper suitable for passing into an emulator's execution statesThis will forward the calls from the state's pieces to this set of emulator callbacks, passing the given thread
- Parameters:
thread- the thread to include in forwarded callbacks- Returns:
- the wrapper
-