Reputation: 179
I'm a little confused going about adding a new instruction to QEMU and want to confirm if my understanding is right. After going through the source code, I think adding an instruction to QEMU involves the following steps:
CHERI_HELPER_IMPL(*instruction*
in \target\target_arch\op_helper.c
that emulates this instruction.generate_*instruction*
in \target\target_arch\translate.c
that calls gen_helper_*instruction*
which calls the helper function.Am I missing any steps?
Upvotes: 0
Views: 1089
Reputation: 11383
The fact that you mention a "CHERI_HELPER_IMPL" macro tells me that you're not working with upstream QEMU, but with the CHERI project's fork of it. So you should talk to them about anything special that might be needed there. As I understand it their local modifications may be quite significant.
For upstream QEMU, this depends on whether the target architecture is using decodetree or not.
For decodetree-based architectures:
trans_
to handle instructions that match that pattern, passing it a pointer to a structure which contains the values of the various instruction fields defined by your pattern.trans_
functions appropriately. What you need to do depends on what the instruction behaviour is. For simple instructions, you can just emit TCG ops which do the actions the instruction must do. For more complicated work, you might want to emit TCG ops for "call a runtime helper function". The tcg/README file has some "recommended coding rules" at the bottom which include a rule of thumb for when to use a helper function.gen_helper_whatever
that your translate-time code can call to generate the TCG code to call it.For non-decodetree-based architectures:
You'll find that there's a lot of specific detail that needs to be got right in each of these steps, but that's the basic outline.
Upvotes: 2