Escolar Documentos
Profissional Documentos
Cultura Documentos
Table of Contents
Introduction
I got to know Qemu since a dynamic taint analysis project, which I've been involving for
almost one year. This short introduction to Qemu is going to become a summary of what I
learn about Qemu.
Qemu is a huge project, the contents I'm going to touch here only accounts for a tiny portion
of it. (I hope it's the core portion though) Since I only understand a small piece of Qemu and
I can only introduce based on what I learned, thus there is no particular order between
contents. Basically, it can be considered as blog articles instead of a complete reference of
Qemu.
Introduction
Binary Translation
To understand what the translation means, let's take a look a small example. The piece of
code shown below executes in the guest os:
#inlcude <stdio.h>
int main(void){
printf("hello qemu\n");
return 0;
}
Code 1.3: Portion of IRs that Qemu Translates from Code 1.2
Code 1.3 shows a portion of IRs (from 0x80483e4 to 0x80483e7 ) that are translated from
the instructions shown in Code 1.2.
Afterwards, Qemu further translates these IRs into host instructions as shown below:
OUT: [size=326]
0xaa9ab870: mov -0x4(%ebp),%ebx
0xaa9ab873: test %ebx,%ebx
0xaa9ab875: jne 0xaa9ab946
0xaa9ab87b: mov 0x10(%ebp),%ebx
0xaa9ab87e: sub $0x4,%ebx
0xaa9ab881: mov 0x14(%ebp),%esi
0xaa9ab884: mov %ebx,%eax
0xaa9ab886: mov %ebx,%edx
...
Code 1.4: Portion of Host Instructions Translated from IRs showed in Code 1.3
Eventually, the instructions showed in Code 1.4 will be executed in the host machine. That
finishes the whole translation process from guest instructions to host instructions, which is
called binary translation some time.
What is movi_i32?
movi_i32 is one of Qemu intermediate representations (IRs), defined in file tcg/tcg-opc.h:
DEF(movi_i32, 1, 0, 1, 0)
movi_i32 has one constant input temporary, and one output temporary. The semantic is to
move the constant input temporary to the output.
The big picture is to assign the input constant to the output. Details are explained below.
1.
2.
3. Via the index - args[0] , Qemu can accesses the content of the output temporary ( &s>temps[args[0]] ), which temps[] is an array to store all temporaries of IRs that are
The semantic of this function is to issue an host instruction that assigning the value
val to the register ( ots->reg ), which is corresponding to the semantic of the IR.
A concrete example
Consider an assembly instruction running in the guest machine of Qemu.
IN:
0x000fe070: mov $0xe5852,%edx
The output temporary is a global temporary edx (specified by the name member)
The val_type is 2, indicating it is a TEMP_VAL_MEM , which indicates its current value was
stored in memory of the host.
defined in tcg.h
#define TEMP_VAL_DEAD 0
#define TEMP_VAL_REG 1
#define TEMP_VAL_MEM 2
#define TEMP_VAL_CONST 3
10
...
ots->val_type = TEMP_VAL_CONST;
ots->val = val;
...
Conclusion
For this particular case, Qemu did not issue any host instruction, it only did a constant
propagation.
(All codes presented should be found in stable-1.0, and assumes both guest and host
machine are in x86 platform.)
11