Need comment on a Qemu source code line
-
26-10-2019 - |
Question
There is a definition for Translation Block in Qemu Source Code(cpu-exec.c)
Line 127 says
static TranslationBlock *tb_find_slow(target_ulong pc, target_ulong cs_base, uint64_t flags)
what does it mean?
Solution
That's not a definition for a translation block, that's a function called tb_find_slow()
which returns a pointer to a translation block. The translation block structure is defined in exec-all.h
.
As to what they are, this page has a succinct description:
QEMU translates native instructions into ‘micro operations’ and builds them up as ‘translation blocks’. When execution occurs, one of the first things that happen is that a lookup is made to find a translation block that has already been created.
In other words, it's sort of a just-in-time compiler.
There's a tb_find_fast()
function which uses a hash based on a bit of CPU state (program counter, code selector and flags) which should be unique for each translation block. If that hash doesn't work (the resultant translation block has a different PC/CS/flags), then it reverts to the slow method, which is a sequential scan of the translation block list.