QEMU: Call a Custom Function from TCG

One of features that makes QEMU so flexible is an ability to call to a function in the middle of executing translated target code phase. QEMU calls it a helper function. include/exec/def-helper.h [Note: changed to a set of helper headers on May 28. change log] is where QEMU defines macros for creating helper functions for us. Basically, they are just ordinary functions with a wrapper.

Do you remember that target code is translated into TCG intermediate code, then it is translated into host code? A helper function is blended during translation from target code to TCG code. Therefore, you can expected to see helper functions appearing in translate.c file. Helper functions are there to aid target code translation. Some target architecture instructions are hard to be described by pure TCG code. Helper functions provide an access to high-level functionalities and libraries in a running host.

Continue reading