Search code examples
qemukvm

How to access executing instruction binary code (e.g., opcode) from C helper functions in QEMU


I would like to modify the QEMU emulator's behaviour when it executes some assembly instructions of a target architecture (e.g., RISC-V) running ontop of a host (e.g., x86).

My question is, is it possible, to access the information related to the instruction being executed, from the C helper?

There some infos that can be accessed from the context variable pointer, but I wasn't able to access the instruction binary code for example. Any ideas?


Solution

  • My question is, is it possible, to access the information related to the instruction being executed, from the C helper?

    Yes. One way to do it is to pass this information to helper from a translator function. Another is to use cpu_ld*_code (e.g. cpu_ldub_code) in the helper to fetch instruction from memory.